Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semver check for dev and beta version #5757

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions flytepropeller/pkg/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ package config
import (
"context"
"fmt"
"regexp"
"time"

"github.com/Masterminds/semver"
Expand Down Expand Up @@ -133,6 +134,9 @@ var (
MaxSizeInMBForOffloading: 1000, // 1 GB is the default size before failing fast.
},
}

// This regex is used to sanitize semver versions passed to IsSupportedSDK checks for literal offloading feature.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind including an example of what this matches against with the dev sdk versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this. Will add in follow up PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here #5758

sanitizeProtoRegex = regexp.MustCompile(`v?(\d+\.\d+\.\d+)`)
)

// Config that uses the flytestdlib Config module to generate commandline and load config files. This configuration is
Expand Down Expand Up @@ -188,19 +192,25 @@ type LiteralOffloadingConfig struct {

// IsSupportedSDKVersion returns true if the provided SDK and version are supported by the literal offloading config.
func (l LiteralOffloadingConfig) IsSupportedSDKVersion(sdk string, versionString string) bool {
regexMatches := sanitizeProtoRegex.FindStringSubmatch(versionString)
if len(regexMatches) > 1 {
logger.Infof(context.TODO(), "original: %s, semVer: %s", versionString, regexMatches[1])
pmahindrakar-oss marked this conversation as resolved.
Show resolved Hide resolved
} else {
logger.Warnf(context.TODO(), "no match found for: %s", versionString)
return false
}
version, err := semver.NewVersion(regexMatches[1])
if err != nil {
logger.Warnf(context.TODO(), "Failed to parse version %s", versionString)
return false
}
if leastSupportedVersion, ok := l.SupportedSDKVersions[sdk]; ok {
c, err := semver.NewConstraint(fmt.Sprintf(">= %s", leastSupportedVersion))
if err != nil {
// This should never happen
logger.Warnf(context.TODO(), "Failed to parse version constraint %s", leastSupportedVersion)
return false
}
version, err := semver.NewVersion(versionString)
if err != nil {
// This should never happen
logger.Warnf(context.TODO(), "Failed to parse version %s", versionString)
return false
}
return c.Check(version)
}
return false
Expand Down
17 changes: 17 additions & 0 deletions flytepropeller/pkg/controller/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@ func TestIsSupportedSDKVersion(t *testing.T) {
}
assert.False(t, config.IsSupportedSDKVersion("flytekit", "0.16.0"))
})

t.Run("supported dev version", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "1.13.4",
},
}
assert.True(t, config.IsSupportedSDKVersion("flytekit", "1.13.4.dev12+g990b450ea.d20240917"))
})
t.Run("supported beta version", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "1.13.4",
},
}
assert.True(t, config.IsSupportedSDKVersion("flytekit", "v1.13.6b0"))
})
}
Loading