From 5ab896d4d713da821da2d6e394dc947b0fe5dbc1 Mon Sep 17 00:00:00 2001 From: Vu Dinh Date: Fri, 11 Jan 2019 19:28:15 -0500 Subject: [PATCH] fix(olm): Provide correct format of kube version in CSV The format of kube version in CSV should be Major.Minor.Patch. For example, 1.1.1 is correct. Signed-off-by: Vu Dinh --- deploy/chart/values.yaml | 2 +- pkg/controller/operators/olm/operator_test.go | 12 ++++ pkg/controller/operators/olm/requirements.go | 6 +- .../operators/olm/requirements_test.go | 65 ++++++++++++++++--- test/e2e/csv_e2e_test.go | 24 +++---- test/e2e/subscription_e2e_test.go | 2 + 6 files changed, 87 insertions(+), 24 deletions(-) diff --git a/deploy/chart/values.yaml b/deploy/chart/values.yaml index 68a2b0a8c2..89ee35c03a 100644 --- a/deploy/chart/values.yaml +++ b/deploy/chart/values.yaml @@ -2,7 +2,7 @@ rbacApiVersion: rbac.authorization.k8s.io namespace: operator-lifecycle-manager catalog_namespace: operator-lifecycle-manager operator_namespace: operators -minKubeVersion: 1.11 +minKubeVersion: 1.11.0 imagestream: false debug: false olm: diff --git a/pkg/controller/operators/olm/operator_test.go b/pkg/controller/operators/olm/operator_test.go index f4491be1bc..7215fd5c20 100644 --- a/pkg/controller/operators/olm/operator_test.go +++ b/pkg/controller/operators/olm/operator_test.go @@ -1849,6 +1849,7 @@ func TestTransitionCSV(t *testing.T) { csvs: []runtime.Object{ withConditionReason(csvWithAnnotations(csv("csv1", namespace, + "0.0.0", "", installStrategy("a1", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v1")}, @@ -1878,6 +1879,7 @@ func TestTransitionCSV(t *testing.T) { csvs: []runtime.Object{ withConditionReason(csvWithAnnotations(csv("csv1", namespace, + "0.0.0", "", installStrategy("a1", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v1")}, @@ -1944,6 +1946,7 @@ func TestTransitionCSV(t *testing.T) { csvs: []runtime.Object{ withConditionReason(csvWithAnnotations(csv("csv1", namespace, + "0.0.0", "", installStrategy("a1", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v1")}, @@ -1975,6 +1978,7 @@ func TestTransitionCSV(t *testing.T) { csvs: []runtime.Object{ withConditionReason(csvWithAnnotations(csv("csv1", namespace, + "0.0.0", "", installStrategy("a1", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v1")}, @@ -2477,6 +2481,14 @@ func TestSyncOperatorGroups(t *testing.T) { operatorCSVFinal.Status.LastUpdateTime = timeNow() operatorCSVFinal.Status.LastTransitionTime = timeNow() operatorCSVFinal.Status.RequirementStatus = []v1alpha1.RequirementStatus{ + { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + Message: "CSV minKubeVersion (0.0.0) less than server version (v0.0.0-master+$Format:%h$)", + }, { Group: "apiextensions.k8s.io", Version: "v1beta1", diff --git a/pkg/controller/operators/olm/requirements.go b/pkg/controller/operators/olm/requirements.go index 936ce8555e..307d27f8af 100644 --- a/pkg/controller/operators/olm/requirements.go +++ b/pkg/controller/operators/olm/requirements.go @@ -41,7 +41,7 @@ func (a *Operator) minKubeVersionStatus(name string, minKubeVersion string) (met return } - serverVersion, err := semver.NewVersion(strings.TrimPrefix(serverVersionInfo.String(), "v")) + serverVersion, err := semver.NewVersion(strings.Split(strings.TrimPrefix(serverVersionInfo.String(), "v"), "-")[0]) if err != nil { status.Status = v1alpha1.RequirementStatusReasonPresentNotSatisfied status.Message = "Server version parsing error" @@ -59,9 +59,9 @@ func (a *Operator) minKubeVersionStatus(name string, minKubeVersion string) (met return } - if csvVersionInfo.Compare(*serverVersion) < 0 { + if csvVersionInfo.Compare(*serverVersion) > 0 { status.Status = v1alpha1.RequirementStatusReasonPresentNotSatisfied - status.Message = "CSV version requirement not met" + status.Message = fmt.Sprintf("CSV version requirement not met: minKubeVersion (%s) > server version (%s)", minKubeVersion, serverVersion.String()) met = false statuses = append(statuses, status) return diff --git a/pkg/controller/operators/olm/requirements_test.go b/pkg/controller/operators/olm/requirements_test.go index e397926428..69866cf39b 100644 --- a/pkg/controller/operators/olm/requirements_test.go +++ b/pkg/controller/operators/olm/requirements_test.go @@ -38,7 +38,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "BadInstallStrategy", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", v1alpha1.NamedInstallStrategy{"deployment", json.RawMessage{}}, nil, @@ -55,7 +55,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "AllPermissionsMet", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy( "csv1-dep", @@ -179,6 +179,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { }, }, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, @@ -186,7 +193,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "OnePermissionNotMet", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy( "csv1-dep", @@ -310,6 +317,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { }, }, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, @@ -317,7 +331,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "AllRequirementsMet", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy( "csv1-dep", @@ -428,6 +442,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { Name: "c2group", Status: v1alpha1.RequirementStatusReasonPresent, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, @@ -435,7 +456,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "RequirementNotMet/NonServedCRDVersion", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy("csv1-dep", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v2")}, @@ -455,6 +476,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { Name: "c1group", Status: v1alpha1.RequirementStatusReasonNotPresent, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, @@ -462,7 +490,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "RequirementNotMet/NotEstablishedCRDVersion", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy("csv1-dep", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "version-not-found")}, @@ -482,6 +510,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { Name: "c1group", Status: v1alpha1.RequirementStatusReasonNotAvailable, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, @@ -489,7 +524,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "RequirementNotMet/NamesConflictedCRD", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy("csv1-dep", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v2")}, @@ -515,6 +550,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { Name: "c1group", Status: v1alpha1.RequirementStatusReasonNotAvailable, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, @@ -522,7 +564,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) { description: "RequirementNotMet/CRDResourceInactive", csv: csv("csv1", namespace, - "0.0", + "0.0.0", "", installStrategy("csv1-dep", nil, nil), []*v1beta1.CustomResourceDefinition{crd("c1", "v2")}, @@ -548,6 +590,13 @@ func TestRequirementAndPermissionStatus(t *testing.T) { Name: "c1group", Status: v1alpha1.RequirementStatusReasonNotAvailable, }, + {"operators.coreos.com", "v1alpha1", "ClusterServiceVersion", "csv1"}: { + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv1", + Status: v1alpha1.RequirementStatusReasonPresent, + }, }, expectedError: nil, }, diff --git a/test/e2e/csv_e2e_test.go b/test/e2e/csv_e2e_test.go index 4461f0c194..908192ab99 100644 --- a/test/e2e/csv_e2e_test.go +++ b/test/e2e/csv_e2e_test.go @@ -271,7 +271,7 @@ func TestCreateCSVWithUnmetRequirementsMinKubeVersion(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "999.999", + MinKubeVersion: "999.999.999", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -334,7 +334,7 @@ func TestCreateCSVWithUnmetRequirementsCRD(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -507,7 +507,7 @@ func TestCreateCSVWithUnmetRequirementsAPIService(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -596,7 +596,7 @@ func TestCreateCSVWithUnmetPermissionsAPIService(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -659,7 +659,7 @@ func TestCreateCSVWithUnmetRequirementsNativeAPI(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -750,7 +750,7 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -1006,7 +1006,7 @@ func TestCreateCSVRequirementsMetAPIService(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -1162,7 +1162,7 @@ func TestCreateCSVWithOwnedAPIService(t *testing.T) { csv := v1alpha1.ClusterServiceVersion{ Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -1337,7 +1337,7 @@ func TestUpdateCSVSameDeploymentName(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -1520,7 +1520,7 @@ func TestUpdateCSVDifferentDeploymentName(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -1708,7 +1708,7 @@ func TestUpdateCSVMultipleIntermediates(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -1902,7 +1902,7 @@ func TestUpdateCSVMultipleVersionCRD(t *testing.T) { Name: genName("csv"), }, Spec: v1alpha1.ClusterServiceVersionSpec{ - MinKubeVersion: "0.0", + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, diff --git a/test/e2e/subscription_e2e_test.go b/test/e2e/subscription_e2e_test.go index ed07a0e89c..eb8f18f871 100644 --- a/test/e2e/subscription_e2e_test.go +++ b/test/e2e/subscription_e2e_test.go @@ -75,6 +75,7 @@ var ( Spec: v1alpha1.ClusterServiceVersionSpec{ Replaces: "", Version: *semver.New("0.1.0"), + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace, @@ -104,6 +105,7 @@ var ( Spec: v1alpha1.ClusterServiceVersionSpec{ Replaces: outdated, Version: *semver.New("0.2.0"), + MinKubeVersion: "0.0.0", InstallModes: []v1alpha1.InstallMode{ { Type: v1alpha1.InstallModeTypeOwnNamespace,