Skip to content

Commit 9724ec3

Browse files
authored
Merge pull request #607 from joelanford/k8s-1.22
⚠ bump to kubernetes 1.22.1, remove support for legacy v1beta1 CRDs and webhooks
2 parents 14c7780 + 09f1952 commit 9724ec3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1122
-1111
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ require (
1212
github.com/spf13/pflag v1.0.5
1313
golang.org/x/tools v0.1.5
1414
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
15-
k8s.io/api v0.21.3
16-
k8s.io/apiextensions-apiserver v0.21.3
17-
k8s.io/apimachinery v0.21.3
15+
k8s.io/api v0.22.2
16+
k8s.io/apiextensions-apiserver v0.22.2
17+
k8s.io/apimachinery v0.22.2
1818
sigs.k8s.io/yaml v1.2.0
1919
)

go.sum

Lines changed: 98 additions & 72 deletions
Large diffs are not rendered by default.

pkg/crd/conv.go

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
apiextinternal "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
77
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
88
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
9-
"k8s.io/apimachinery/pkg/api/equality"
109
"k8s.io/apimachinery/pkg/runtime"
1110
"k8s.io/apimachinery/pkg/runtime/schema"
1211
)
@@ -22,13 +21,15 @@ func init() {
2221
if err := apiext.AddToScheme(conversionScheme); err != nil {
2322
panic("must be able to add apiextensions/v1 to the CRD conversion Scheme")
2423
}
25-
if err := apiextv1beta1.AddToScheme(conversionScheme); err != nil {
26-
panic("must be able to add apiextensions/v1beta1 to the CRD conversion Scheme")
27-
}
2824
}
2925

3026
// AsVersion converts a CRD from the canonical internal form (currently v1) to some external form.
3127
func AsVersion(original apiext.CustomResourceDefinition, gv schema.GroupVersion) (runtime.Object, error) {
28+
// TODO: Do we need to keep maintaining this conversion function
29+
// post 1.22 when only CRDv1 is served by the apiserver?
30+
if gv == apiextv1beta1.SchemeGroupVersion {
31+
return nil, fmt.Errorf("apiVersion %q is not supported", gv.String())
32+
}
3233
// We can use the internal versions an existing conversions from kubernetes, since they're not in k/k itself.
3334
// This punts the problem of conversion down the road for a future maintainer (or future instance of @directxman12)
3435
// when we have to support older versions that get removed, or when API machinery decides to yell at us for this
@@ -40,83 +41,3 @@ func AsVersion(original apiext.CustomResourceDefinition, gv schema.GroupVersion)
4041

4142
return conversionScheme.ConvertToVersion(intVer, gv)
4243
}
43-
44-
// mergeIdenticalSubresources checks to see if subresources are identical across
45-
// all versions, and if so, merges them into a top-level version.
46-
//
47-
// This assumes you're not using trivial versions.
48-
func mergeIdenticalSubresources(crd *apiextv1beta1.CustomResourceDefinition) {
49-
subres := crd.Spec.Versions[0].Subresources
50-
for _, ver := range crd.Spec.Versions {
51-
if ver.Subresources == nil || !equality.Semantic.DeepEqual(subres, ver.Subresources) {
52-
// either all nil, or not identical
53-
return
54-
}
55-
}
56-
57-
// things are identical if we've gotten this far, so move the subresources up
58-
// and discard the identical per-version ones
59-
crd.Spec.Subresources = subres
60-
for i := range crd.Spec.Versions {
61-
crd.Spec.Versions[i].Subresources = nil
62-
}
63-
}
64-
65-
// mergeIdenticalSchemata checks to see if schemata are identical across
66-
// all versions, and if so, merges them into a top-level version.
67-
//
68-
// This assumes you're not using trivial versions.
69-
func mergeIdenticalSchemata(crd *apiextv1beta1.CustomResourceDefinition) {
70-
schema := crd.Spec.Versions[0].Schema
71-
for _, ver := range crd.Spec.Versions {
72-
if ver.Schema == nil || !equality.Semantic.DeepEqual(schema, ver.Schema) {
73-
// either all nil, or not identical
74-
return
75-
}
76-
}
77-
78-
// things are identical if we've gotten this far, so move the schemata up
79-
// to a single schema and discard the identical per-version ones
80-
crd.Spec.Validation = schema
81-
for i := range crd.Spec.Versions {
82-
crd.Spec.Versions[i].Schema = nil
83-
}
84-
}
85-
86-
// mergeIdenticalPrinterColumns checks to see if schemata are identical across
87-
// all versions, and if so, merges them into a top-level version.
88-
//
89-
// This assumes you're not using trivial versions.
90-
func mergeIdenticalPrinterColumns(crd *apiextv1beta1.CustomResourceDefinition) {
91-
cols := crd.Spec.Versions[0].AdditionalPrinterColumns
92-
for _, ver := range crd.Spec.Versions {
93-
if len(ver.AdditionalPrinterColumns) == 0 || !equality.Semantic.DeepEqual(cols, ver.AdditionalPrinterColumns) {
94-
// either all nil, or not identical
95-
return
96-
}
97-
}
98-
99-
// things are identical if we've gotten this far, so move the printer columns up
100-
// and discard the identical per-version ones
101-
crd.Spec.AdditionalPrinterColumns = cols
102-
for i := range crd.Spec.Versions {
103-
crd.Spec.Versions[i].AdditionalPrinterColumns = nil
104-
}
105-
}
106-
107-
// MergeIdenticalVersionInfo makes sure that components of the Versions field that are identical
108-
// across all versions get merged into the top-level fields in v1beta1.
109-
//
110-
// This is required by the Kubernetes API server validation.
111-
//
112-
// The reason is that a v1beta1 -> v1 -> v1beta1 conversion cycle would need to
113-
// round-trip identically, v1 doesn't have top-level subresources, and without
114-
// this restriction it would be ambiguous how a v1-with-identical-subresources
115-
// converts into a v1beta1).
116-
func MergeIdenticalVersionInfo(crd *apiextv1beta1.CustomResourceDefinition) {
117-
if len(crd.Spec.Versions) > 0 {
118-
mergeIdenticalSubresources(crd)
119-
mergeIdenticalSchemata(crd)
120-
mergeIdenticalPrinterColumns(crd)
121-
}
122-
}

pkg/crd/crd_spec_test.go

Lines changed: 0 additions & 267 deletions
Original file line numberDiff line numberDiff line change
@@ -18,275 +18,8 @@ package crd_test
1818

1919
import (
2020
. "github.com/onsi/ginkgo"
21-
. "github.com/onsi/gomega"
22-
apiextlegacy "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
23-
24-
"sigs.k8s.io/controller-tools/pkg/crd"
2521
)
2622

2723
var _ = Describe("CRD Generation", func() {
28-
Describe("Utilities", func() {
29-
Describe("MergeIdenticalVersionInfo", func() {
30-
It("should replace per-version schemata with a top-level schema if only one version", func() {
31-
spec := &apiextlegacy.CustomResourceDefinition{
32-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
33-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
34-
{
35-
Name: "v1",
36-
Storage: true,
37-
Schema: &apiextlegacy.CustomResourceValidation{
38-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
39-
Required: []string{"foo"},
40-
Type: "object",
41-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
42-
},
43-
},
44-
},
45-
},
46-
},
47-
}
48-
crd.MergeIdenticalVersionInfo(spec)
49-
Expect(spec.Spec.Validation).To(Equal(&apiextlegacy.CustomResourceValidation{
50-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
51-
Required: []string{"foo"},
52-
Type: "object",
53-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
54-
},
55-
}))
56-
Expect(spec.Spec.Versions).To(Equal([]apiextlegacy.CustomResourceDefinitionVersion{
57-
{Name: "v1", Storage: true},
58-
}))
59-
})
60-
It("should replace per-version schemata with a top-level schema if all are identical", func() {
61-
spec := &apiextlegacy.CustomResourceDefinition{
62-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
63-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
64-
{
65-
Name: "v1",
66-
Schema: &apiextlegacy.CustomResourceValidation{
67-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
68-
Required: []string{"foo"},
69-
Type: "object",
70-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
71-
},
72-
},
73-
},
74-
{
75-
Name: "v2",
76-
Storage: true,
77-
Schema: &apiextlegacy.CustomResourceValidation{
78-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
79-
Required: []string{"foo"},
80-
Type: "object",
81-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
82-
},
83-
},
84-
},
85-
},
86-
},
87-
}
88-
crd.MergeIdenticalVersionInfo(spec)
89-
Expect(spec.Spec.Validation).To(Equal(&apiextlegacy.CustomResourceValidation{
90-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
91-
Required: []string{"foo"},
92-
Type: "object",
93-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
94-
},
95-
}))
96-
Expect(spec.Spec.Versions).To(Equal([]apiextlegacy.CustomResourceDefinitionVersion{
97-
{Name: "v1"}, {Name: "v2", Storage: true},
98-
}))
99-
})
100-
101-
It("shouldn't merge different schemata", func() {
102-
spec := &apiextlegacy.CustomResourceDefinition{
103-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
104-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
105-
{
106-
Name: "v1",
107-
Schema: &apiextlegacy.CustomResourceValidation{
108-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
109-
Type: "object",
110-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
111-
},
112-
},
113-
},
114-
{
115-
Name: "v2",
116-
Storage: true,
117-
Schema: &apiextlegacy.CustomResourceValidation{
118-
OpenAPIV3Schema: &apiextlegacy.JSONSchemaProps{
119-
Required: []string{"foo"},
120-
Type: "object",
121-
Properties: map[string]apiextlegacy.JSONSchemaProps{"foo": {Type: "string"}},
122-
},
123-
},
124-
},
125-
},
126-
},
127-
}
128-
orig := spec.DeepCopy()
129-
crd.MergeIdenticalVersionInfo(spec)
130-
Expect(spec).To(Equal(orig))
131-
})
132-
133-
It("should replace per-version subresources with top-level subresources if only one version", func() {
134-
spec := &apiextlegacy.CustomResourceDefinition{
135-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
136-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
137-
{
138-
Name: "v1",
139-
Storage: true,
140-
Subresources: &apiextlegacy.CustomResourceSubresources{
141-
Status: &apiextlegacy.CustomResourceSubresourceStatus{},
142-
},
143-
},
144-
},
145-
},
146-
}
147-
148-
crd.MergeIdenticalVersionInfo(spec)
149-
Expect(spec.Spec.Subresources).To(Equal(&apiextlegacy.CustomResourceSubresources{
150-
Status: &apiextlegacy.CustomResourceSubresourceStatus{},
151-
}))
152-
Expect(spec.Spec.Versions).To(Equal([]apiextlegacy.CustomResourceDefinitionVersion{
153-
{Name: "v1", Storage: true},
154-
}))
155-
})
156-
157-
It("should replace per-version subresources with top-level subresources if all are identical", func() {
158-
spec := &apiextlegacy.CustomResourceDefinition{
159-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
160-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
161-
{
162-
Name: "v1",
163-
Subresources: &apiextlegacy.CustomResourceSubresources{
164-
Status: &apiextlegacy.CustomResourceSubresourceStatus{},
165-
},
166-
},
167-
{
168-
Name: "v2",
169-
Storage: true,
170-
Subresources: &apiextlegacy.CustomResourceSubresources{
171-
Status: &apiextlegacy.CustomResourceSubresourceStatus{},
172-
},
173-
},
174-
},
175-
},
176-
}
177-
178-
crd.MergeIdenticalVersionInfo(spec)
179-
Expect(spec.Spec.Subresources).To(Equal(&apiextlegacy.CustomResourceSubresources{
180-
Status: &apiextlegacy.CustomResourceSubresourceStatus{},
181-
}))
182-
Expect(spec.Spec.Versions).To(Equal([]apiextlegacy.CustomResourceDefinitionVersion{
183-
{Name: "v1"}, {Name: "v2", Storage: true},
184-
}))
185-
})
186-
187-
It("shouldn't merge different subresources", func() {
188-
spec := &apiextlegacy.CustomResourceDefinition{
189-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
190-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
191-
{
192-
Name: "v1",
193-
Subresources: &apiextlegacy.CustomResourceSubresources{
194-
Status: &apiextlegacy.CustomResourceSubresourceStatus{},
195-
},
196-
},
197-
{
198-
Name: "v2",
199-
Storage: true,
200-
},
201-
},
202-
},
203-
}
204-
orig := spec.DeepCopy()
205-
crd.MergeIdenticalVersionInfo(spec)
206-
Expect(spec).To(Equal(orig))
207-
})
208-
209-
It("should replace per-version printer columns with top-level printer columns if only one version", func() {
210-
spec := &apiextlegacy.CustomResourceDefinition{
211-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
212-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
213-
{
214-
Name: "v1",
215-
Storage: true,
216-
AdditionalPrinterColumns: []apiextlegacy.CustomResourceColumnDefinition{
217-
{Name: "Cheddar", JSONPath: ".spec.cheddar"},
218-
{Name: "Parmesan", JSONPath: ".status.parmesan"},
219-
},
220-
},
221-
},
222-
},
223-
}
224-
225-
crd.MergeIdenticalVersionInfo(spec)
226-
Expect(spec.Spec.AdditionalPrinterColumns).To(Equal([]apiextlegacy.CustomResourceColumnDefinition{
227-
{Name: "Cheddar", JSONPath: ".spec.cheddar"},
228-
{Name: "Parmesan", JSONPath: ".status.parmesan"},
229-
}))
230-
Expect(spec.Spec.Versions).To(Equal([]apiextlegacy.CustomResourceDefinitionVersion{
231-
{Name: "v1", Storage: true},
232-
}))
233-
})
234-
235-
It("should replace per-version printer columns with top-level printer columns if all are identical", func() {
236-
spec := &apiextlegacy.CustomResourceDefinition{
237-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
238-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
239-
{
240-
Name: "v1",
241-
AdditionalPrinterColumns: []apiextlegacy.CustomResourceColumnDefinition{
242-
{Name: "Cheddar", JSONPath: ".spec.cheddar"},
243-
{Name: "Parmesan", JSONPath: ".status.parmesan"},
244-
},
245-
},
246-
{
247-
Name: "v2",
248-
Storage: true,
249-
AdditionalPrinterColumns: []apiextlegacy.CustomResourceColumnDefinition{
250-
{Name: "Cheddar", JSONPath: ".spec.cheddar"},
251-
{Name: "Parmesan", JSONPath: ".status.parmesan"},
252-
},
253-
},
254-
},
255-
},
256-
}
257-
258-
crd.MergeIdenticalVersionInfo(spec)
259-
Expect(spec.Spec.AdditionalPrinterColumns).To(Equal([]apiextlegacy.CustomResourceColumnDefinition{
260-
{Name: "Cheddar", JSONPath: ".spec.cheddar"},
261-
{Name: "Parmesan", JSONPath: ".status.parmesan"},
262-
}))
263-
Expect(spec.Spec.Versions).To(Equal([]apiextlegacy.CustomResourceDefinitionVersion{
264-
{Name: "v1"}, {Name: "v2", Storage: true},
265-
}))
266-
})
26724

268-
It("shouldn't merge different printer columns", func() {
269-
spec := &apiextlegacy.CustomResourceDefinition{
270-
Spec: apiextlegacy.CustomResourceDefinitionSpec{
271-
Versions: []apiextlegacy.CustomResourceDefinitionVersion{
272-
{
273-
Name: "v1",
274-
AdditionalPrinterColumns: []apiextlegacy.CustomResourceColumnDefinition{
275-
{Name: "Cheddar", JSONPath: ".spec.cheddar"},
276-
{Name: "Parmesan", JSONPath: ".status.parmesan"},
277-
},
278-
},
279-
{
280-
Name: "v2",
281-
Storage: true,
282-
},
283-
},
284-
},
285-
}
286-
orig := spec.DeepCopy()
287-
crd.MergeIdenticalVersionInfo(spec)
288-
Expect(spec).To(Equal(orig))
289-
})
290-
})
291-
})
29225
})

0 commit comments

Comments
 (0)