diff --git a/flytepropeller/pkg/controller/config/config.go b/flytepropeller/pkg/controller/config/config.go index 2d61c94970..28e844cd7d 100644 --- a/flytepropeller/pkg/controller/config/config.go +++ b/flytepropeller/pkg/controller/config/config.go @@ -36,6 +36,7 @@ package config import ( "context" "fmt" + "regexp" "time" "github.com/Masterminds/semver" @@ -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. + sanitizeProtoRegex = regexp.MustCompile(`v?(\d+\.\d+\.\d+)`) ) // Config that uses the flytestdlib Config module to generate commandline and load config files. This configuration is @@ -188,6 +192,18 @@ 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]) + } 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 { @@ -195,12 +211,6 @@ func (l LiteralOffloadingConfig) IsSupportedSDKVersion(sdk string, versionString 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 diff --git a/flytepropeller/pkg/controller/config/config_test.go b/flytepropeller/pkg/controller/config/config_test.go index afc9ed2fea..60f8d70f88 100644 --- a/flytepropeller/pkg/controller/config/config_test.go +++ b/flytepropeller/pkg/controller/config/config_test.go @@ -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")) + }) }