Skip to content

Commit

Permalink
Add semver check for dev and beta version
Browse files Browse the repository at this point in the history
Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss committed Sep 18, 2024
1 parent 312910d commit 65552a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
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.
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])
} 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"))
})
}

0 comments on commit 65552a3

Please sign in to comment.