Skip to content

Commit

Permalink
Migrate away from metadata.ClusterName use for k8s 1.25 support (#393)
Browse files Browse the repository at this point in the history
* k8s1.25

* GetAnnotations() replaces ClusterName field in ClusterResourceId interface

* actually support k8s v1.25 (with controller-runtime v0.13.1)

* update go templates; changelog; dep updates

* put changelog in folder

* update from generated code

* add annotations field to ClusterObjectRef proto to match ClusterResourceId interface

* remove annotations field from ClusterObjectRef proto

* Adding changelog file to new location

* Deleting changelog file from old location

* contrib/reconciler: Update to converting to new interface. Not stored directly as its not exported.

* Adding changelog file to new location

* Deleting changelog file from old location

* handle istio changing their api in pointless ways

* Adding changelog file to new location

* Deleting changelog file from old location

* make generated-code -B; update changelog

* move changelog

* make generated-code -B

* GetClusterName should check for deprecated cluster name approach

* update changelog folder

* codegen

* silly diff in codegen (bc of go version used locally)

* handle the possibility that k8s apimachinery v0.24.x is being used by importing project (which gets clusterName with ZZZ nonsense)

* update changelog; make GetDeprecatedClusterName() an internal method

* only call the deprecated func if needed

Co-authored-by: Jenny Shu <[email protected]>

* actually, it's a breaking change

* update changelog folder

Co-authored-by: Eitan Yarmush <[email protected]>
Co-authored-by: changelog-bot <changelog-bot>
Co-authored-by: nfuden <[email protected]>
Co-authored-by: Jenny Shu <[email protected]>
  • Loading branch information
4 people authored Jan 13, 2023
1 parent 32358d3 commit feb141e
Show file tree
Hide file tree
Showing 31 changed files with 495 additions and 1,031 deletions.
6 changes: 6 additions & 0 deletions changelog/v0.27.0/support-k8s-1.25.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: BREAKING_CHANGE
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/5158
description: |
Go dependencies updated to k8s v1.25; support k8s versions pre-v1.24, v1.24, and post-v1.24
that gradually change how metadata.clusterName is accessed (i.e. deprecation -> removal)
3 changes: 0 additions & 3 deletions ci/oss_compliance/osa_included.md
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
Name|Version|License
---|---|---
[golang-lru/simplelru](https://github.com/hashicorp/golang-lru)|v0.5.4|Mozilla Public License 2.0
62 changes: 36 additions & 26 deletions ci/oss_compliance/osa_provided.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,63 @@
Name|Version|License
---|---|---
[PuerkitoBio/purell](https://github.com/PuerkitoBio/purell)|v1.1.1|BSD 3-clause "New" or "Revised" License
[PuerkitoBio/urlesc](https://github.com/PuerkitoBio/urlesc)|v0.0.0-20170810143723-de5bf2ad4578|BSD 3-clause "New" or "Revised" License
[perks/quantile](https://github.com/beorn7/perks)|v1.0.1|MIT License
[xxhash/v2](https://github.com/cespare/xxhash)|v2.1.1|MIT License
[xxhash/v2](https://github.com/cespare/xxhash)|v2.1.2|MIT License
[go-spew/spew](https://github.com/davecgh/go-spew)|v1.1.1|ISC License
[evanphx/json-patch](https://github.com/evanphx/json-patch)|v4.11.0+incompatible|BSD 3-clause "New" or "Revised" License
[fsnotify/fsnotify](https://github.com/fsnotify/fsnotify)|v1.4.9|BSD 3-clause "New" or "Revised" License
[go-logr/logr](https://github.com/go-logr/logr)|v0.4.0|Apache License 2.0
[v3/log](https://github.com/emicklei/go-restful)|v3.8.0|MIT License
[json-patch/v5](https://github.com/evanphx/json-patch)|v5.6.0|BSD 3-clause "New" or "Revised" License
[fsnotify/fsnotify](https://github.com/fsnotify/fsnotify)|v1.5.4|BSD 3-clause "New" or "Revised" License
[go-logr/logr](https://github.com/go-logr/logr)|v1.2.3|Apache License 2.0
[go-openapi/jsonpointer](https://github.com/go-openapi/jsonpointer)|v0.19.5|Apache License 2.0
[go-openapi/jsonreference](https://github.com/go-openapi/jsonreference)|v0.19.5|Apache License 2.0
[go-openapi/swag](https://github.com/go-openapi/swag)|v0.19.14|Apache License 2.0
[gogo/protobuf](https://github.com/gogo/protobuf)|v1.3.2|BSD 3-clause "New" or "Revised" License
[groupcache/lru](https://github.com/golang/groupcache)|v0.0.0-20200121045136-8c9f03a8e57e|Apache License 2.0
[groupcache/lru](https://github.com/golang/groupcache)|v0.0.0-20210331224755-41bb18bfe9da|Apache License 2.0
[golang/protobuf](https://github.com/golang/protobuf)|v1.5.2|BSD 3-clause "New" or "Revised" License
[google/gnostic](https://github.com/google/gnostic)|v0.5.7-v3refs|Apache License 2.0
[cmp/internal](https://github.com/google/go-cmp)|v0.5.8|BSD 3-clause "New" or "Revised" License
[google/gofuzz](https://github.com/google/gofuzz)|v1.1.0|Apache License 2.0
[google/uuid](https://github.com/google/uuid)|v1.2.0|BSD 3-clause "New" or "Revised" License
[googleapis/gnostic](https://github.com/googleapis/gnostic)|v0.5.5|Apache License 2.0
[json-iterator/go](https://github.com/json-iterator/go)|v1.1.11|MIT License
[josharian/intern](https://github.com/josharian/intern)|v1.0.0|MIT License
[json-iterator/go](https://github.com/json-iterator/go)|v1.1.12|MIT License
[mailru/easyjson](https://github.com/mailru/easyjson)|v0.7.6|MIT License
[golang_protobuf_extensions/pbutil](https://github.com/matttproud/golang_protobuf_extensions)|v1.0.2-0.20181231171920-c182affec369|Apache License 2.0
[modern-go/concurrent](https://github.com/modern-go/concurrent)|v0.0.0-20180306012644-bacd9c7ef1dd|Apache License 2.0
[modern-go/reflect2](https://github.com/modern-go/reflect2)|v1.0.1|Apache License 2.0
[modern-go/reflect2](https://github.com/modern-go/reflect2)|v1.0.2|Apache License 2.0
[munnerz/goautoneg](https://github.com/munnerz/goautoneg)|v0.0.0-20191010083416-a7dc8b61c822|BSD 3-clause "New" or "Revised" License
[pkg/errors](https://github.com/pkg/errors)|v0.9.1|BSD 2-clause "Simplified" License
[client_golang/prometheus](https://github.com/prometheus/client_golang)|v1.11.0|Apache License 2.0
[client_golang/prometheus](https://github.com/prometheus/client_golang)|v1.12.2|Apache License 2.0
[client_model/go](https://github.com/prometheus/client_model)|v0.2.0|Apache License 2.0
[prometheus/common](https://github.com/prometheus/common)|v0.26.0|Apache License 2.0
[procfs/internal](https://github.com/prometheus/procfs)|v0.6.0|Apache License 2.0
[prometheus/common](https://github.com/prometheus/common)|v0.32.1|Apache License 2.0
[procfs/internal](https://github.com/prometheus/procfs)|v0.7.3|Apache License 2.0
[rotisserie/eris](https://github.com/rotisserie/eris)|v0.1.1|MIT License
[go.uber.org/atomic](https://go.uber.org/atomic)|v1.7.0|MIT License
[go.uber.org/multierr](https://go.uber.org/multierr)|v1.6.0|MIT License
[go.uber.org/zap](https://go.uber.org/zap)|v1.19.0|MIT License
[go.uber.org/zap](https://go.uber.org/zap)|v1.21.0|MIT License
[exp/maps](https://golang.org/x/exp/maps)|v0.0.0-20220921164117-439092de6870|BSD 3-clause "New" or "Revised" License
[x/net](https://golang.org/x/net)|v0.0.0-20220722155237-a158d28d115b|BSD 3-clause "New" or "Revised" License
[oauth2/internal](https://golang.org/x/oauth2/internal)|v0.0.0-20210201163806-010130855d6c|BSD 3-clause "New" or "Revised" License
[oauth2/internal](https://golang.org/x/oauth2/internal)|v0.0.0-20211104180415-d3ed0bb246c8|BSD 3-clause "New" or "Revised" License
[x/sys](https://golang.org/x/sys)|v0.0.0-20220722155257-8c9f86f7a55f|BSD 3-clause "New" or "Revised" License
[x/term](https://golang.org/x/term)|v0.0.0-20210927222741-03fcf44c2211|BSD 3-clause "New" or "Revised" License
[x/text](https://golang.org/x/text)|v0.3.7|BSD 3-clause "New" or "Revised" License
[time/rate](https://golang.org/x/time/rate)|v0.0.0-20210723032227-1f47c861a9ac|BSD 3-clause "New" or "Revised" License
[time/rate](https://golang.org/x/time/rate)|v0.0.0-20220609170525-579cf78fd858|BSD 3-clause "New" or "Revised" License
[jsonpatch/v2](https://gomodules.xyz/jsonpatch/v2)|v2.2.0|Apache License 2.0
[google.golang.org/protobuf](https://google.golang.org/protobuf)|v1.27.1|BSD 3-clause "New" or "Revised" License
[google.golang.org/protobuf](https://google.golang.org/protobuf)|v1.28.0|BSD 3-clause "New" or "Revised" License
[gopkg.in/inf.v0](https://gopkg.in/inf.v0)|v0.9.1|BSD 3-clause "New" or "Revised" License
[gopkg.in/yaml.v2](https://gopkg.in/yaml.v2)|v2.4.0|Apache License 2.0
[gopkg.in/yaml.v3](https://gopkg.in/yaml.v3)|v3.0.0-20210107192922-496545a6307b|MIT License
[k8s.io/api](https://k8s.io/api)|v0.21.4|Apache License 2.0
[k8s.io/apimachinery](https://k8s.io/apimachinery)|v0.21.4|Apache License 2.0
[k8s.io/client-go](https://k8s.io/client-go)|v0.21.4|Apache License 2.0
[config/v1alpha1](https://k8s.io/component-base/config/v1alpha1)|v0.21.4|Apache License 2.0
[klog/v2](https://k8s.io/klog/v2)|v2.8.0|Apache License 2.0
[util/proto](https://k8s.io/kube-openapi/pkg/util/proto)|v0.0.0-20210305001622-591a79e4bda7|Apache License 2.0
[k8s.io/utils](https://k8s.io/utils)|v0.0.0-20210802155522-efc7438f0176|Apache License 2.0
[controller-runtime/pkg](https://sigs.k8s.io/controller-runtime/pkg)|v0.9.7|Apache License 2.0
[structured-merge-diff/v4](https://sigs.k8s.io/structured-merge-diff/v4)|v4.1.2|Apache License 2.0
[sigs.k8s.io/yaml](https://sigs.k8s.io/yaml)|v1.2.0|MIT License
[gopkg.in/yaml.v3](https://gopkg.in/yaml.v3)|v3.0.1|MIT License
[k8s.io/api](https://k8s.io/api)|v0.25.4|Apache License 2.0
[k8s.io/apimachinery](https://k8s.io/apimachinery)|v0.25.4|Apache License 2.0
[k8s.io/client-go](https://k8s.io/client-go)|v0.25.4|Apache License 2.0
[config/v1alpha1](https://k8s.io/component-base/config/v1alpha1)|v0.25.4|Apache License 2.0
[v2/internal](https://k8s.io/klog/v2/internal)|v2.70.1|Apache License 2.0
[kube-openapi/pkg](https://k8s.io/kube-openapi/pkg)|v0.0.0-20220803162953-67bda5d908f1|Apache License 2.0
[k8s.io/utils](https://k8s.io/utils)|v0.0.0-20220728103510-ee6ede2d64ed|Apache License 2.0
[controller-runtime/pkg](https://sigs.k8s.io/controller-runtime/pkg)|v0.13.1|Apache License 2.0
[encoding/json](https://sigs.k8s.io/json/internal/golang/encoding/json)|v0.0.0-20220713155537-f223a00ba0e2|Apache License 2.0
[structured-merge-diff/v4](https://sigs.k8s.io/structured-merge-diff/v4)|v4.2.3|Apache License 2.0
[sigs.k8s.io/yaml](https://sigs.k8s.io/yaml)|v1.3.0|MIT License
[cmd/goimports](https://golang.org/x/tools/cmd/goimports)|latest|MIT License
[gogo/protobuf](https://github.com/gogo/protobuf)|latest|MIT License
[envoyproxy/envoy](https://github.com/envoyproxy/envoy)|latest|Apache License 2.0
Expand Down
13 changes: 7 additions & 6 deletions codegen/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ var _ = Describe("Cmd", func() {
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(8080),
Expand Down Expand Up @@ -385,7 +385,7 @@ var _ = Describe("Cmd", func() {
},
},
LivenessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(8080),
Expand Down Expand Up @@ -520,7 +520,7 @@ var _ = Describe("Cmd", func() {
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(8080),
Expand Down Expand Up @@ -549,7 +549,7 @@ var _ = Describe("Cmd", func() {
},
},
LivenessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(8080),
Expand Down Expand Up @@ -784,6 +784,7 @@ var _ = Describe("Cmd", func() {
RenderManifests: true,
RenderValidationSchemas: true,
ApiRoot: "codegen/test/api",
PointerSlices: true,
},
},
AnyVendorConfig: skv2Imports,
Expand All @@ -809,7 +810,7 @@ var _ = Describe("Cmd", func() {
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(8080),
Expand Down Expand Up @@ -839,7 +840,7 @@ var _ = Describe("Cmd", func() {
},
},
LivenessProbe: &v1.Probe{
Handler: v1.Handler{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(8080),
Expand Down
4 changes: 2 additions & 2 deletions codegen/kuberesource/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ var _ = Describe("Crd", func() {
o, err := CustomResourceDefinitions(grp)
Expect(err).NotTo(HaveOccurred())
Expect(o).To(HaveLen(1))
// note: we intentionally provide the "5770277ee8c9bc92" hash in the test, as it shouldn't change
// note: we intentionally provide the "b6ec737002f7d02e" hash in the test, as it shouldn't change
// between runs.
Expect(o[0].GetAnnotations()).To(HaveKeyWithValue(crdutils.CRDSpecHashKey, "5770277ee8c9bc92"))
Expect(o[0].GetAnnotations()).To(HaveKeyWithValue(crdutils.CRDSpecHashKey, "b6ec737002f7d02e"))

})
It("should not generate spec hash", func() {
Expand Down
3 changes: 3 additions & 0 deletions codegen/model/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type Group struct {

// Custom properties used for custom templates
Properties

// Some resources use pointer slices for the Items field.
PointerSlices bool `default:"false"`
}

func (g Group) HasProtos() bool {
Expand Down
2 changes: 1 addition & 1 deletion codegen/render/manifests_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("ManifestsRenderer", func() {
Expect(err).NotTo(HaveOccurred())
Expect(outFiles).To(HaveLen(1))
Expect(outFiles[0].Content).To(ContainSubstring(crdutils.CRDVersionKey + ": 1.0.0"))
Expect(outFiles[0].Content).To(ContainSubstring(crdutils.CRDSpecHashKey + ": 5770277ee8c9bc92"))
Expect(outFiles[0].Content).To(ContainSubstring(crdutils.CRDSpecHashKey + ": b6ec737002f7d02e"))

})
})
Expand Down
4 changes: 4 additions & 0 deletions codegen/templates/code/types/types.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func ({{ $resource.Kind}}) GVK() schema.GroupVersionKind {
type {{ $resource.Kind}}List struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
{{- if $resource.Group.PointerSlices }}
Items []*{{ $resource.Kind }} `json:"items"`
{{- else }}
Items []{{ $resource.Kind }} `json:"items"`
{{- end }}
}
{{- end }}

Expand Down
4 changes: 2 additions & 2 deletions codegen/test/chart-no-desc/crds/things.test.io_v1_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
crd.solo.io/specHash: f3871dd356eb8d5a
crd.solo.io/specHash: 52f9159d46759d37
labels:
app: ""
app.kubernetes.io/name: ""
Expand Down Expand Up @@ -138,7 +138,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
crd.solo.io/specHash: 89866f4e2ca2348e
crd.solo.io/specHash: a7f6c51daca2a86e
labels:
app: ""
app.kubernetes.io/name: ""
Expand Down
4 changes: 2 additions & 2 deletions codegen/test/chart/crds/things.test.io_v1_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
crd.solo.io/specHash: 87c5526152abe427
crd.solo.io/specHash: 888c42601b3e10b6
labels:
app: ""
app.kubernetes.io/name: ""
Expand Down Expand Up @@ -142,7 +142,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
crd.solo.io/specHash: 89866f4e2ca2348e
crd.solo.io/specHash: a7f6c51daca2a86e
labels:
app: ""
app.kubernetes.io/name: ""
Expand Down
2 changes: 1 addition & 1 deletion contrib/codegen/templates/input/input_reconciler.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func RegisterSingleCluster{{ $snapshotName }}Reconciler(
Name: obj.Name,
Namespace: obj.Namespace,
}
_, err := r.base.ReconcileLocalGeneric(ref)
_, err := r.base.ReconcileLocalGeneric(ezkube.ConvertRefToId(ref))
return err
},
}, predicates...); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions contrib/codegen/templates/sets/sets.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func New{{ $resource.Kind }}Set({{ $kindLowerCamel }}List ...*{{ $import_prefix
func New{{ $resource.Kind }}SetFromList({{ $kindLowerCamel }}List *{{ $import_prefix }}.{{ $resource.Kind }}List) {{ $resource.Kind }}Set {
list := make([]*{{ $import_prefix }}.{{ $resource.Kind }}, 0, len({{ $kindLowerCamel }}List.Items))
for idx := range {{ $kindLowerCamel }}List.Items {
{{- if $resource.PointerSlices }}
list = append(list, {{ $kindLowerCamel }}List.Items[idx])
{{- else }}
list = append(list, &{{ $kindLowerCamel }}List.Items[idx])
{{- end }}
}
return &{{ $kindLowerCamel }}Set{set: makeGeneric{{ $resource.Kind }}Set(list)}
}
Expand Down
2 changes: 1 addition & 1 deletion crds/multicluster.solo.io_v1alpha1_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
crd.solo.io/specHash: ad9e1dd2ecf8891d
crd.solo.io/specHash: 396fd84315636ecb
labels:
app: skv2
app.kubernetes.io/name: skv2
Expand Down
Loading

0 comments on commit feb141e

Please sign in to comment.