Skip to content

Commit

Permalink
Upgrade to controller-runtime v0.10 and Kubernetes 1.22
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed Sep 16, 2021
1 parent 59ccc97 commit 902eee9
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 109 deletions.
4 changes: 3 additions & 1 deletion controllers/machine_controller_node_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func TestReconcileInterruptibleNodeLabel(t *testing.T) {
g.Expect(env.Create(ctx, cluster)).To(Succeed())
g.Expect(env.Create(ctx, node)).To(Succeed())
g.Expect(env.Create(ctx, infraMachine)).To(Succeed())
g.Expect(env.Create(ctx, machine)).To(Succeed())
// Note: We have to DeepCopy the machine, because the Create call clears the status and
// reconcileInterruptibleNodeLabel requires .status.nodeRef to be set.
g.Expect(env.Create(ctx, machine.DeepCopy())).To(Succeed())

// Patch infra machine status
patchHelper, err := patch.NewHelper(infraMachine, env)
Expand Down
9 changes: 5 additions & 4 deletions controllers/remote/cluster_cache_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ func TestClusterCacheTracker(t *testing.T) {
t.Log("Creating a test cluster")
clusterA = &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.GetName(),
Name: "test-cluster",
Annotations: make(map[string]string),
Namespace: ns.GetName(),
Name: "test-cluster",
},
}
g.Expect(k8sClient.Create(ctx, clusterA)).To(Succeed())
Expand Down Expand Up @@ -150,7 +149,9 @@ func TestClusterCacheTracker(t *testing.T) {
}).Should(Equal(0))

t.Log("Updating the cluster")
clusterA.Annotations["update1"] = "1"
clusterA.Annotations = map[string]string{
"update1": "1",
}
g.Expect(k8sClient.Update(ctx, clusterA)).To(Succeed())

t.Log("Waiting to receive the watch notification")
Expand Down
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ require (
github.com/drone/envsubst/v2 v2.0.0-20210615175204-7bf45dbf5372
github.com/evanphx/json-patch v4.11.0+incompatible
github.com/fatih/color v1.12.0
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/go-logr/logr v0.4.0
github.com/gobuffalo/flect v0.2.3
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.5.6
github.com/google/go-github/v33 v33.0.0
github.com/google/gofuzz v1.2.0
Expand All @@ -30,16 +28,16 @@ require (
go.etcd.io/etcd/client/v3 v3.5.0
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
google.golang.org/grpc v1.39.0
k8s.io/api v0.21.4
k8s.io/apiextensions-apiserver v0.21.4
k8s.io/apimachinery v0.21.4
k8s.io/apiserver v0.21.4
k8s.io/client-go v0.21.4
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.22.1
k8s.io/apimachinery v0.22.1
k8s.io/apiserver v0.22.1
k8s.io/client-go v0.22.1
k8s.io/cluster-bootstrap v0.21.4
k8s.io/component-base v0.21.4
k8s.io/component-base v0.22.1
k8s.io/klog/v2 v2.9.0
k8s.io/kubectl v0.21.4
k8s.io/utils v0.0.0-20210802155522-efc7438f0176
sigs.k8s.io/controller-runtime v0.9.7
sigs.k8s.io/controller-runtime v0.10.0
sigs.k8s.io/yaml v1.2.0
)
125 changes: 78 additions & 47 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
golang.org/x/tools v0.1.5
gotest.tools/gotestsum v1.6.4
k8s.io/code-generator v0.21.3
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210706144019-ef5c8a3ffd28
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210827150604-1730628f118b
sigs.k8s.io/controller-tools v0.6.2
sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20210702145813-742983631190
)
19 changes: 12 additions & 7 deletions hack/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down Expand Up @@ -417,17 +419,16 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.1/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg=
github.com/onsi/gomega v1.14.0 h1:ep6kpPVwmr/nTbklSx2nrLNSIO62DoYAhnPNIMhK8gI=
github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU=
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
Expand Down Expand Up @@ -586,6 +587,8 @@ go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
Expand All @@ -595,8 +598,9 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -640,6 +644,7 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
Expand Down Expand Up @@ -696,7 +701,6 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down Expand Up @@ -836,6 +840,7 @@ golang.org/x/tools v0.0.0-20191004183538-27eeabb02079/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down Expand Up @@ -1073,8 +1078,8 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.19/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210706144019-ef5c8a3ffd28 h1:Q1AuEbhxBNLLJmro5LeXl4oS2aPIfxGhEzd6EgRNGsE=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210706144019-ef5c8a3ffd28/go.mod h1:jqzBWjsNdxfl/cDmihB034I5aCqlfw2p24HYs3Eo4K4=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210827150604-1730628f118b h1:DzEpvyjrou46yDaQ5/gACrHUMwT8howR0Pn/pFuVD3w=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210827150604-1730628f118b/go.mod h1:Fxb8+lsIhcPWKq89RReMSzjcv3COhP0D37vJplt4ABg=
sigs.k8s.io/controller-tools v0.6.2 h1:+Y8L0UsAugDipGRw8lrkPoAi6XqlQVZuf1DQHME3PgU=
sigs.k8s.io/controller-tools v0.6.2/go.mod h1:oaeGpjXn6+ZSEIQkUe/+3I40PNiDYp9aeawbt3xTgJ8=
sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20210702145813-742983631190 h1:y13LG4qWQA8VxwrrLWp458Gw8i9nfy1qImu8kW1jOkg=
Expand Down
23 changes: 12 additions & 11 deletions internal/envtest/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func init() {

// Calculate the scheme.
utilruntime.Must(apiextensionsv1.AddToScheme(scheme.Scheme))
utilruntime.Must(admissionv1.AddToScheme(scheme.Scheme))
utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme))
utilruntime.Must(bootstrapv1.AddToScheme(scheme.Scheme))
utilruntime.Must(expv1.AddToScheme(scheme.Scheme))
Expand Down Expand Up @@ -159,17 +160,17 @@ func new(uncachedObjs ...client.Object) *Environment {
filepath.Join(root, "controlplane", "kubeadm", "config", "crd", "bases"),
filepath.Join(root, "bootstrap", "kubeadm", "config", "crd", "bases"),
},
CRDs: []client.Object{
testtypes.GenericBootstrapConfigCRD.DeepCopy(),
testtypes.GenericBootstrapConfigTemplateCRD.DeepCopy(),
testtypes.GenericControlPlaneCRD.DeepCopy(),
testtypes.GenericControlPlaneTemplateCRD.DeepCopy(),
testtypes.GenericInfrastructureMachineCRD.DeepCopy(),
testtypes.GenericInfrastructureMachineTemplateCRD.DeepCopy(),
testtypes.GenericInfrastructureClusterCRD.DeepCopy(),
testtypes.GenericInfrastructureClusterTemplateCRD.DeepCopy(),
testtypes.GenericRemediationCRD.DeepCopy(),
testtypes.GenericRemediationTemplateCRD.DeepCopy(),
CRDs: []apiextensionsv1.CustomResourceDefinition{
*testtypes.GenericBootstrapConfigCRD.DeepCopy(),
*testtypes.GenericBootstrapConfigTemplateCRD.DeepCopy(),
*testtypes.GenericControlPlaneCRD.DeepCopy(),
*testtypes.GenericControlPlaneTemplateCRD.DeepCopy(),
*testtypes.GenericInfrastructureMachineCRD.DeepCopy(),
*testtypes.GenericInfrastructureMachineTemplateCRD.DeepCopy(),
*testtypes.GenericInfrastructureClusterCRD.DeepCopy(),
*testtypes.GenericInfrastructureClusterTemplateCRD.DeepCopy(),
*testtypes.GenericRemediationCRD.DeepCopy(),
*testtypes.GenericRemediationTemplateCRD.DeepCopy(),
},
// initialize webhook here to be able to test the envtest install via webhookOptions
// This should set LocalServingCertDir and LocalServingPort that are used below.
Expand Down
40 changes: 34 additions & 6 deletions internal/envtest/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"strings"
"time"

admissionv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)

Expand All @@ -38,8 +40,8 @@ const (
)

func initWebhookInstallOptions() envtest.WebhookInstallOptions {
validatingWebhooks := []client.Object{}
mutatingWebhooks := []client.Object{}
validatingWebhooks := []admissionv1.ValidatingWebhookConfiguration{}
mutatingWebhooks := []admissionv1.MutatingWebhookConfiguration{}

// Get the root of the current file to use in CRD paths.
_, filename, _, _ := goruntime.Caller(0) //nolint
Expand Down Expand Up @@ -85,7 +87,7 @@ func initWebhookInstallOptions() envtest.WebhookInstallOptions {

// Mutate the name of each webhook, because kubebuilder generates the same name for all controllers.
// In normal usage, kustomize will prefix the controller name, which we have to do manually here.
func appendWebhookConfiguration(mutatingWebhooks []client.Object, validatingWebhooks []client.Object, configyamlFile []byte, tag string) ([]client.Object, []client.Object, error) {
func appendWebhookConfiguration(mutatingWebhooks []admissionv1.MutatingWebhookConfiguration, validatingWebhooks []admissionv1.ValidatingWebhookConfiguration, configyamlFile []byte, tag string) ([]admissionv1.MutatingWebhookConfiguration, []admissionv1.ValidatingWebhookConfiguration, error) {
objs, err := utilyaml.ToUnstructured(configyamlFile)
if err != nil {
klog.Fatalf("failed to parse yaml")
Expand All @@ -97,14 +99,40 @@ func appendWebhookConfiguration(mutatingWebhooks []client.Object, validatingWebh
// update the name in metadata
if o.GetName() == mutatingwebhook {
o.SetName(strings.Join([]string{mutatingwebhook, "-", tag}, ""))
mutatingWebhooks = append(mutatingWebhooks, &o)

webhook := &admissionv1.MutatingWebhookConfiguration{}
if err := scheme.Scheme.Convert(&o, webhook, nil); err != nil {
klog.Fatalf("failed to convert MutatingWebhookConfiguration %s", o.GetName())
}

// TODO(sbueringer): drop this code after https://github.com/kubernetes-sigs/controller-runtime/pull/1665 has been merged
gvk, err := apiutil.GVKForObject(webhook, scheme.Scheme)
if err != nil {
klog.Fatalf("failed to get gvk for ValidatingWebhookConfiguration %s", o.GetName())
}
webhook.SetGroupVersionKind(gvk)

mutatingWebhooks = append(mutatingWebhooks, *webhook)
}
}
if o.GetKind() == validatingWebhookKind {
// update the name in metadata
if o.GetName() == validatingwebhook {
o.SetName(strings.Join([]string{validatingwebhook, "-", tag}, ""))
validatingWebhooks = append(validatingWebhooks, &o)

webhook := &admissionv1.ValidatingWebhookConfiguration{}
if err := scheme.Scheme.Convert(&o, webhook, nil); err != nil {
klog.Fatalf("failed to convert ValidatingWebhookConfiguration %s", o.GetName())
}

// TODO(sbueringer): drop this code after https://github.com/kubernetes-sigs/controller-runtime/pull/1665 has been merged
gvk, err := apiutil.GVKForObject(webhook, scheme.Scheme)
if err != nil {
klog.Fatalf("failed to get gvk for ValidatingWebhookConfiguration %s", o.GetName())
}
webhook.SetGroupVersionKind(gvk)

validatingWebhooks = append(validatingWebhooks, *webhook)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ require (
github.com/onsi/gomega v1.15.0
github.com/pkg/errors v0.9.1
github.com/spf13/pflag v1.0.5
k8s.io/api v0.21.4
k8s.io/apiextensions-apiserver v0.21.4
k8s.io/apimachinery v0.21.4
k8s.io/client-go v0.21.4
k8s.io/component-base v0.21.4
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.22.1
k8s.io/apimachinery v0.22.1
k8s.io/client-go v0.22.1
k8s.io/component-base v0.22.1
k8s.io/klog/v2 v2.9.0
k8s.io/utils v0.0.0-20210802155522-efc7438f0176
sigs.k8s.io/cluster-api v0.0.0-00010101000000-000000000000
sigs.k8s.io/controller-runtime v0.9.7
sigs.k8s.io/controller-runtime v0.10.0
sigs.k8s.io/kind v0.11.1
sigs.k8s.io/yaml v1.2.0
)

0 comments on commit 902eee9

Please sign in to comment.