From facefdcb72f8cfc16843663e1a25a702d7170c56 Mon Sep 17 00:00:00 2001 From: Gabriel Bernal Date: Fri, 7 Jun 2024 12:12:19 +0200 Subject: [PATCH] fix: compatibility matrix version validation (#501) --- .../uiplugin/compatibility_matrix.go | 8 ++--- .../uiplugin/compatibility_matrix_test.go | 35 ++++++++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/pkg/controllers/uiplugin/compatibility_matrix.go b/pkg/controllers/uiplugin/compatibility_matrix.go index 7dbbcbf8..1b8070cd 100644 --- a/pkg/controllers/uiplugin/compatibility_matrix.go +++ b/pkg/controllers/uiplugin/compatibility_matrix.go @@ -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 } } diff --git a/pkg/controllers/uiplugin/compatibility_matrix_test.go b/pkg/controllers/uiplugin/compatibility_matrix_test.go index 26de8830..bc615aab 100644 --- a/pkg/controllers/uiplugin/compatibility_matrix_test.go +++ b/pkg/controllers/uiplugin/compatibility_matrix_test.go @@ -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, @@ -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", @@ -84,6 +95,18 @@ 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 { @@ -91,6 +114,10 @@ func TestLookupImageAndFeatures(t *testing.T) { 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 {