Skip to content

Commit efc34da

Browse files
kutluhanmetinstevekuznetsov
authored andcommitted
Fix min kube version validation (openshift#286)
* fixes operator-framework/operator-sdk#5995 * fix comment change * fix imports Upstream-repository: api Upstream-commit: fdfcb35e6d330fca94841b113c8140cf58930e35 Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent dc4f266 commit efc34da

17 files changed

+88
-6
lines changed

pkg/manifests/csv.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
name: packageserver
66
namespace: openshift-operator-lifecycle-manager
77
labels:
8-
olm.version: 0.0.0-c0ff8256acdd48c68b07e8c46376ef6ff28d218a
8+
olm.version: 0.0.0-62d7be6699baacf83e06be64c8260a90377308dc
99
olm.clusteroperator.name: operator-lifecycle-manager-packageserver
1010
annotations:
1111
include.release.openshift.io/self-managed-high-availability: "true"
@@ -159,7 +159,7 @@ spec:
159159
- packageserver
160160
topologyKey: "kubernetes.io/hostname"
161161
maturity: alpha
162-
version: 0.0.0-c0ff8256acdd48c68b07e8c46376ef6ff28d218a
162+
version: 0.0.0-62d7be6699baacf83e06be64c8260a90377308dc
163163
apiservicedefinitions:
164164
owned:
165165
- group: packages.operators.coreos.com

staging/api/pkg/validation/internal/csv.go

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package internal
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/blang/semver/v4"
67
"io"
78
"reflect"
89
"strings"
@@ -45,6 +46,8 @@ func validateCSV(csv *v1alpha1.ClusterServiceVersion) errors.ManifestResult {
4546
result.Add(validateExamplesAnnotations(csv)...)
4647
// validate installModes
4748
result.Add(validateInstallModes(csv)...)
49+
// validate min Kubernetes version
50+
result.Add(validateMinKubeVersion(*csv)...)
4851
// check missing optional/mandatory fields.
4952
result.Add(checkFields(*csv)...)
5053
// validate case sensitive annotation names
@@ -240,3 +243,15 @@ func validateVersionKind(csv *v1alpha1.ClusterServiceVersion) (errs []errors.Err
240243
}
241244
return
242245
}
246+
247+
// validateMinKubeVersion checks format of spec.minKubeVersion field
248+
func validateMinKubeVersion(csv v1alpha1.ClusterServiceVersion) (errs []errors.Error) {
249+
if len(strings.TrimSpace(csv.Spec.MinKubeVersion)) == 0 {
250+
errs = append(errs, errors.WarnInvalidCSV(minKubeVersionWarnMessage, csv.GetName()))
251+
} else {
252+
if _, err := semver.Parse(csv.Spec.MinKubeVersion); err != nil {
253+
errs = append(errs, errors.ErrInvalidCSV(fmt.Sprintf("csv.Spec.MinKubeVersion has an invalid value: %s", csv.Spec.MinKubeVersion), csv.GetName()))
254+
}
255+
}
256+
return errs
257+
}

staging/api/pkg/validation/internal/csv_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"path/filepath"
77
"testing"
88

9-
"github.com/ghodss/yaml"
109
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
10+
11+
"github.com/ghodss/yaml"
1112
"github.com/operator-framework/api/pkg/validation/errors"
1213
"k8s.io/apimachinery/pkg/runtime/schema"
1314
)
@@ -107,6 +108,16 @@ func TestValidateCSV(t *testing.T) {
107108
},
108109
filepath.Join("testdata", "correct.csv.olm.properties.annotation.yaml"),
109110
},
111+
{
112+
validatorFuncTest{
113+
description: "should fail when spec.minKubeVersion is not in semantic version format",
114+
wantErr: true,
115+
errors: []errors.Error{
116+
errors.ErrInvalidCSV(`csv.Spec.MinKubeVersion has an invalid value: 1.21`, "test-operator.v0.0.1"),
117+
},
118+
},
119+
filepath.Join("testdata", "invalid_min_kube_version.csv.yaml"),
120+
},
110121
}
111122

112123
for _, c := range cases {

staging/api/pkg/validation/internal/operatorhub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func checkSpecMinKubeVersion(checks CSVChecks) CSVChecks {
240240
if len(strings.TrimSpace(checks.csv.Spec.MinKubeVersion)) == 0 {
241241
checks.warns = append(checks.warns, fmt.Errorf(minKubeVersionWarnMessage))
242242
} else {
243-
if _, err := semver.ParseTolerant(checks.csv.Spec.MinKubeVersion); err != nil {
243+
if _, err := semver.Parse(checks.csv.Spec.MinKubeVersion); err != nil {
244244
checks.errs = append(checks.errs, fmt.Errorf("csv.Spec.MinKubeVersion has an invalid value: %s", checks.csv.Spec.MinKubeVersion))
245245
}
246246
}

staging/api/pkg/validation/internal/operatorhub_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func TestCheckSpecMinKubeVersion(t *testing.T) {
218218
}{
219219
{
220220
name: "should work with a valid value",
221-
args: args{minKubeVersion: "1.16"},
221+
args: args{minKubeVersion: "1.16.0"},
222222
},
223223
{
224224
name: "should return a warning when the minKubeVersion is not informed ",

staging/api/pkg/validation/internal/testdata/badAnnotationNames.csv.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ metadata:
1414
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1515
description: etcd is a distributed key value store providing a reliable way to store data across a cluster of machines.
1616
spec:
17+
minKubeVersion: 1.21.0
1718
displayName: etcd
1819
description: |
1920
etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines. It’s open-source and available on GitHub. etcd gracefully handles leader elections during network partitions and will tolerate machine failure, including the leader. Your applications can read and write data into etcd.

staging/api/pkg/validation/internal/testdata/badName.csv.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ metadata:
1111
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1212
description: etcd is a distributed key value store providing a reliable way to store data across a cluster of machines.
1313
spec:
14+
minKubeVersion: 1.21.0
1415
displayName: etcd
1516
description: something
1617
keywords: ['etcd', 'key value', 'database', 'coreos', 'open source']

staging/api/pkg/validation/internal/testdata/correct.csv.empty.example.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
annotations:
99
"alm-examples": ""
1010
spec:
11+
minKubeVersion: 1.21.0
1112
version: 0.9.0
1213
installModes:
1314
- type: AllNamespaces

staging/api/pkg/validation/internal/testdata/correct.csv.olm.properties.annotation.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ metadata:
99
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1010
olm.properties: '[{"type": "foo", "value": "bar"}]'
1111
spec:
12+
minKubeVersion: 1.21.0
1213
version: 0.9.0
1314
installModes:
1415
- type: AllNamespaces

staging/api/pkg/validation/internal/testdata/correct.csv.with.conversion.webhook.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ metadata:
1111
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1212
description: etcd is a distributed key value store providing a reliable way to store data across a cluster of machines.
1313
spec:
14+
minKubeVersion: 1.21.0
1415
displayName: etcd
1516
description: |
1617
etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines. It’s open-source and available on GitHub. etcd gracefully handles leader elections during network partitions and will tolerate machine failure, including the leader. Your applications can read and write data into etcd.

staging/api/pkg/validation/internal/testdata/correct.csv.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ metadata:
1111
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1212
description: etcd is a distributed key value store providing a reliable way to store data across a cluster of machines.
1313
spec:
14+
minKubeVersion: 1.21.0
1415
displayName: etcd
1516
description: |
1617
etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines. It’s open-source and available on GitHub. etcd gracefully handles leader elections during network partitions and will tolerate machine failure, including the leader. Your applications can read and write data into etcd.

staging/api/pkg/validation/internal/testdata/dataTypeMismatch.csv.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ metadata:
1111
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1212
description: etcd is a distributed key value store providing a reliable way to store data across a cluster of machines.
1313
spec:
14+
minKubeVersion: 1.21.0
1415
displayName: etcd
1516
description: |
1617
etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines. It’s open-source and available on GitHub. etcd gracefully handles leader elections during network partitions and will tolerate machine failure, including the leader. Your applications can read and write data into etcd.

staging/api/pkg/validation/internal/testdata/invalid.alm-examples.csv.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ metadata:
77
name: test-operator.v0.0.1
88
namespace: placeholder
99
spec:
10+
minKubeVersion: 1.21.0
1011
displayName: test-operator
1112
install:
1213
strategy: deployment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
name: test-operator.v0.0.1
5+
namespace: placeholder
6+
spec:
7+
minKubeVersion: 1.21
8+
displayName: test-operator
9+
install:
10+
strategy: deployment
11+
installModes:
12+
- supported: true
13+
type: OwnNamespace
14+
- supported: true
15+
type: SingleNamespace
16+
- supported: false
17+
type: MultiNamespace
18+
- supported: true
19+
type: AllNamespaces
20+
keywords:
21+
- test-operator
22+
links:
23+
- name: Test Operator
24+
url: https://test-operator.domain
25+
maintainers:
26+
27+
name: Maintainer Name
28+
maturity: alpha
29+
provider:
30+
name: Provider Name
31+
url: https://your.domain
32+
version: 0.0.1

staging/api/pkg/validation/internal/testdata/noInstallMode.csv.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ metadata:
1111
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
1212
description: etcd is a distributed key value store providing a reliable way to store data across a cluster of machines.
1313
spec:
14+
minKubeVersion: 1.21.0
1415
displayName: etcd
1516
description: |
1617
etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines. It’s open-source and available on GitHub. etcd gracefully handles leader elections during network partitions and will tolerate machine failure, including the leader. Your applications can read and write data into etcd.

vendor/github.com/operator-framework/api/pkg/validation/internal/csv.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/api/pkg/validation/internal/operatorhub.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)