Skip to content

Commit 9f0bd9c

Browse files
authored
Merge pull request #44 from dinhxuanvu/crd-version-validation
fix(crd): Fix CRD validation falsely error on unused CRD versions
2 parents 6468209 + bedd1e3 commit 9f0bd9c

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

pkg/validation/internal/bundle.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,25 @@ func validateOwnedCRDs(bundle *manifests.Bundle, csv *operatorsv1alpha1.ClusterS
4343
}
4444

4545
// All owned keys must match a CRD in bundle.
46+
ownedGVSet := make(map[schema.GroupKind]struct{})
4647
for _, ownedKey := range ownedKeys {
4748
if _, ok := keySet[ownedKey]; !ok {
4849
result.Add(errors.ErrInvalidBundle(fmt.Sprintf("owned CRD %q not found in bundle %q", ownedKey, bundle.Name), ownedKey))
4950
} else {
5051
delete(keySet, ownedKey)
52+
gvKey := schema.GroupKind{Group: ownedKey.Group, Kind: ownedKey.Kind}
53+
ownedGVSet[gvKey] = struct{}{}
5154
}
5255
}
56+
57+
// Filter out unused versions of the same CRD
58+
for key := range keySet {
59+
gvKey := schema.GroupKind{Group: key.Group, Kind: key.Kind}
60+
if _, ok := ownedGVSet[gvKey]; ok {
61+
delete(keySet, key)
62+
}
63+
}
64+
5365
// All CRDs present in a CSV must be present in the bundle.
5466
for key := range keySet {
5567
result.Add(errors.WarnInvalidBundle(fmt.Sprintf("CRD %q is present in bundle %q but not defined in CSV", key, bundle.Name), key))

pkg/validation/internal/bundle_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ func TestValidateBundle(t *testing.T) {
2020
directory: "./testdata/valid_bundle",
2121
hasError: false,
2222
},
23+
{
24+
description: "registryv1 valid bundle with multiple versions in CRD",
25+
directory: "./testdata/valid_bundle_2",
26+
hasError: false,
27+
},
2328
{
2429
description: "registryv1 invalid bundle without CRD etcdclusters v1beta2 in bundle",
2530
directory: "./testdata/invalid_bundle",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
annotations:
5+
capabilities: Basic Install
6+
name: test-operator.v0.0.1
7+
namespace: placeholder
8+
spec:
9+
apiservicedefinitions: {}
10+
customresourcedefinitions:
11+
owned:
12+
- description: Test is the Schema for the tests API
13+
kind: Test
14+
name: tests.test.example.com
15+
version: v1alpha1
16+
- description: TestTwo is the Schema for the tests API
17+
kind: TestTwo
18+
name: TestTwos.test.example.com
19+
version: v1beta1
20+
installModes:
21+
- supported: true
22+
type: OwnNamespace
23+
- supported: true
24+
type: SingleNamespace
25+
- supported: false
26+
type: MultiNamespace
27+
- supported: true
28+
type: AllNamespaces
29+
keywords:
30+
- test-operator
31+
links:
32+
- name: Test Operator
33+
url: https://test-operator.domain
34+
maintainers:
35+
36+
name: Maintainer Name
37+
maturity: alpha
38+
provider:
39+
name: Provider Name
40+
url: https://your.domain
41+
version: 0.0.1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: tests.test.example.com
5+
spec:
6+
group: test.example.com
7+
names:
8+
kind: Test
9+
listKind: TestList
10+
plural: tests
11+
singular: test
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
served: true
16+
storage: true
17+
- name: v1beta1
18+
served: true
19+
storage: false
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: testtwos.test.example.com
5+
spec:
6+
group: test.example.com
7+
names:
8+
kind: TestTwo
9+
listKind: TestTwoList
10+
plural: testtwos
11+
singular: testtwo
12+
scope: Namespaced
13+
version: v1beta1
14+
versions:
15+
- name: v1beta1
16+
served: true
17+
storage: true
18+
- name: v1alpha1
19+
served: true
20+
storage: false

0 commit comments

Comments
 (0)