Skip to content

Commit

Permalink
fix: compatibility matrix version validation (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgbernalp committed Jun 7, 2024
1 parent 02690af commit facefdc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/controllers/uiplugin/compatibility_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func lookupImageAndFeatures(pluginType uiv1alpha1.UIPluginType, clusterVersion s

for _, entry := range compatibilityMatrix {
if entry.PluginType == pluginType {
if entry.MaxClusterVersion == "" && semver.Compare(clusterVersion, entry.MinClusterVersion) >= 0 {
return entry, nil
}
canonicalMinClusterVersion := fmt.Sprintf("%s-0", semver.Canonical(entry.MinClusterVersion))

if semver.Compare(clusterVersion, entry.MinClusterVersion) >= 0 && semver.Compare(clusterVersion, entry.MaxClusterVersion) <= 0 {
if entry.MaxClusterVersion == "" && semver.Compare(clusterVersion, canonicalMinClusterVersion) >= 0 {
return entry, nil
} else if semver.Compare(clusterVersion, canonicalMinClusterVersion) >= 0 && semver.Compare(clusterVersion, entry.MaxClusterVersion) <= 0 {
return entry, nil
}
}
Expand Down
35 changes: 31 additions & 4 deletions pkg/controllers/uiplugin/compatibility_matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

func TestLookupImageAndFeatures(t *testing.T) {
tt := []struct {
pluginType uiv1alpha1.UIPluginType
clusterVersion string
expectedKey string
expectedErr error
pluginType uiv1alpha1.UIPluginType
clusterVersion string
expectedKey string
expectedErr error
expectedFeatures []string
}{
{
pluginType: uiv1alpha1.TypeDashboards,
Expand All @@ -34,6 +35,16 @@ func TestLookupImageAndFeatures(t *testing.T) {
expectedKey: "ui-dashboards",
expectedErr: nil,
},
{
pluginType: uiv1alpha1.TypeLogging,
clusterVersion: "4.13",
expectedKey: "ui-logging",
expectedErr: nil,
expectedFeatures: []string{
"dev-console",
"alerts",
},
},
{
pluginType: uiv1alpha1.TypeLogging,
clusterVersion: "4.11",
Expand Down Expand Up @@ -84,13 +95,29 @@ func TestLookupImageAndFeatures(t *testing.T) {
expectedKey: "",
expectedErr: fmt.Errorf("no compatible image found for plugin type non-existent-plugin and cluster version v4.24.0-0.nightly-2024-03-11-200348"),
},
{
pluginType: uiv1alpha1.TypeDistributedTracing,
clusterVersion: "4.16.0-rc.3",
expectedKey: "ui-distributed-tracing",
expectedErr: nil,
},
{
pluginType: uiv1alpha1.TypeTroubleshootingPanel,
clusterVersion: "v4.16.0-0.nightly-2024-06-06-064349",
expectedKey: "ui-troubleshooting-panel",
expectedErr: nil,
},
}

for _, tc := range tt {
info, err := lookupImageAndFeatures(tc.pluginType, tc.clusterVersion)

assert.Equal(t, tc.expectedKey, info.ImageKey)

if tc.expectedFeatures != nil {
assert.DeepEqual(t, tc.expectedFeatures, info.Features)
}

if tc.expectedErr != nil {
assert.Error(t, err, tc.expectedErr.Error())
} else {
Expand Down

0 comments on commit facefdc

Please sign in to comment.