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 all commits
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
26 changes: 18 additions & 8 deletions flytepropeller/pkg/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import (
"context"
"fmt"
"regexp"
"time"

"github.com/Masterminds/semver"
Expand Down Expand Up @@ -133,6 +134,9 @@
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 @@ -187,18 +191,24 @@
}

// 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 {
func (l LiteralOffloadingConfig) IsSupportedSDKVersion(ctx context.Context, sdk string, versionString string) bool {
regexMatches := sanitizeProtoRegex.FindStringSubmatch(versionString)
if len(regexMatches) > 1 {
logger.Infof(ctx, "original: %s, semVer: %s", versionString, regexMatches[1])
} else {
logger.Warnf(ctx, "no match found for: %s", versionString)
return false
}
version, err := semver.NewVersion(regexMatches[1])
if err != nil {
logger.Warnf(ctx, "Failed to parse version %s", versionString)
return false

Check warning on line 205 in flytepropeller/pkg/controller/config/config.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/config/config.go#L204-L205

Added lines #L204 - L205 were not covered by tests
}
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)
logger.Warnf(ctx, "Failed to parse version constraint %s", leastSupportedVersion)
return false
}
return c.Check(version)
Expand Down
158 changes: 115 additions & 43 deletions flytepropeller/pkg/controller/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,126 @@
package config

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsSupportedSDKVersion(t *testing.T) {
t.Run("supported version", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
}
assert.True(t, config.IsSupportedSDKVersion("flytekit", "0.16.0"))
})

t.Run("unsupported version", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
}
assert.False(t, config.IsSupportedSDKVersion("flytekit", "0.15.0"))
})

t.Run("unsupported SDK", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
}
assert.False(t, config.IsSupportedSDKVersion("unknown", "0.16.0"))
})

t.Run("invalid version", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
}
assert.False(t, config.IsSupportedSDKVersion("flytekit", "invalid"))
})
ctx := context.Background()
tests := []struct {
name string
config LiteralOffloadingConfig
sdk string
version string
expectedResult bool
}{
{
name: "supported version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
},
sdk: "flytekit",
version: "0.16.0",
expectedResult: true,
},
{
name: "unsupported version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
},
sdk: "flytekit",
version: "0.15.0",
expectedResult: false,
},
{
name: "unsupported SDK",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
},
sdk: "unknown",
version: "0.16.0",
expectedResult: false,
},
{
name: "invalid version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "0.16.0",
},
},
sdk: "flytekit",
version: "invalid",
expectedResult: false,
},
{
name: "invalid constraint",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "invalid",
},
},
sdk: "flytekit",
version: "0.16.0",
expectedResult: false,
},
{
name: "supported dev version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "1.13.4",
},
},
sdk: "flytekit",
version: "1.13.4.dev12+g990b450ea.d20240917",
expectedResult: true,
},
{
name: "supported beta version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "1.13.4",
},
},
sdk: "flytekit",
version: "v1.13.6b0",
expectedResult: true,
},
{
name: "unsupported dev version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "1.13.4",
},
},
sdk: "flytekit",
version: "1.13.3.dev12+g990b450ea.d20240917",
expectedResult: false,
},
{
name: "unsupported beta version",
config: LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "1.13.4",
},
},
sdk: "flytekit",
version: "v1.13.3b0",
expectedResult: false,
},
}

t.Run("invalid constraint", func(t *testing.T) {
config := LiteralOffloadingConfig{
SupportedSDKVersions: map[string]string{
"flytekit": "invalid",
},
}
assert.False(t, config.IsSupportedSDKVersion("flytekit", "0.16.0"))
})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.config.IsSupportedSDKVersion(ctx, tt.sdk, tt.version)
assert.Equal(t, tt.expectedResult, result)
})
}
}
2 changes: 1 addition & 1 deletion flytepropeller/pkg/controller/nodes/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func CheckOffloadingCompat(ctx context.Context, nCtx interfaces.NodeExecutionCon
return &phaseInfo
}
runtimeData := taskNode.CoreTask().GetMetadata().GetRuntime()
if !literalOffloadingConfig.IsSupportedSDKVersion(runtimeData.GetType().String(), runtimeData.GetVersion()) {
if !literalOffloadingConfig.IsSupportedSDKVersion(ctx, runtimeData.GetType().String(), runtimeData.GetVersion()) {
if !literalOffloadingConfig.Enabled {
errMsg := fmt.Sprintf("task [%s] is trying to consume offloaded literals but feature is not enabled", taskID)
logger.Errorf(ctx, errMsg)
Expand Down
Loading