Skip to content

Commit f80289f

Browse files
authored
Merge pull request kubernetes-sigs#277 from aamoyel/topology-dryrun-check
feat: check if the request is a dry-run to match CAPI topology design
2 parents d2b2668 + 5b1a081 commit f80289f

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

e2e/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
k8s.io/api v0.28.3
1111
k8s.io/apimachinery v0.28.3
1212
k8s.io/client-go v12.0.0+incompatible
13-
k8s.io/utils v0.0.0-20230505201702-9f6742963106
13+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
1414
kubevirt.io/api v1.0.0
1515
kubevirt.io/client-go v0.0.0-00010101000000-000000000000
1616
sigs.k8s.io/cluster-api v1.5.2

e2e/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,8 +1683,8 @@ k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6/go.mod h1:sZAwmy6armz5eXlNoLmJcl
16831683
k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
16841684
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
16851685
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1686-
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
1687-
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1686+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
1687+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
16881688
kubevirt.io/api v1.0.0 h1:RBdXP5CDhE0v5qL2OUQdrYyRrHe/F68Z91GWqBDF6nw=
16891689
kubevirt.io/api v1.0.0/go.mod h1:CJ4vZsaWhVN3jNbyc9y3lIZhw8nUHbWjap0xHABQiqc=
16901690
kubevirt.io/client-go v1.0.0 h1:MMn41j/lFd+lJ7gWn7yuIZYW/aT9fI3bUimAuxAQ+Xk=

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ require (
1818
k8s.io/component-base v0.28.3
1919
k8s.io/klog/v2 v2.100.1
2020
k8s.io/kubectl v0.28.3
21-
k8s.io/utils v0.0.0-20230505201702-9f6742963106
21+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
2222
kubevirt.io/api v1.0.0
23+
kubevirt.io/containerized-data-importer-api v1.57.0
2324
sigs.k8s.io/cluster-api v1.5.2
2425
sigs.k8s.io/controller-runtime v0.16.2
2526
sigs.k8s.io/kind v0.20.0
@@ -102,7 +103,6 @@ require (
102103
k8s.io/apiextensions-apiserver v0.28.0 // indirect
103104
k8s.io/cli-runtime v0.28.3 // indirect
104105
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
105-
kubevirt.io/containerized-data-importer-api v1.57.0 // indirect
106106
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
107107
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
108108
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ k8s.io/kubectl v0.28.3 h1:H1Peu1O3EbN9zHkJCcvhiJ4NUj6lb88sGPO5wrWIM6k=
496496
k8s.io/kubectl v0.28.3/go.mod h1:RDAudrth/2wQ3Sg46fbKKl4/g+XImzvbsSRZdP2RiyE=
497497
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
498498
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
499-
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
500-
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
499+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
500+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
501501
kubevirt.io/api v1.0.0 h1:RBdXP5CDhE0v5qL2OUQdrYyRrHe/F68Z91GWqBDF6nw=
502502
kubevirt.io/api v1.0.0/go.mod h1:CJ4vZsaWhVN3jNbyc9y3lIZhw8nUHbWjap0xHABQiqc=
503503
kubevirt.io/containerized-data-importer-api v1.57.0 h1:IpRCUyDS0x7BaVa5q5MCzuWRAfvXT54GpEnNJke5hSE=

pkg/webhookhandler/validator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ func (wh *kubevirtMachineTemplateHandler) Handle(_ context.Context, req admissio
6767

6868
case admissionv1.Update:
6969
oldKVTmplt := &v1alpha1.KubevirtMachineTemplate{}
70+
// Server Side Apply implementation in ClusterClass and managed topologies requires to dry-run changes on templates.
71+
// cf: https://cluster-api.sigs.k8s.io/developer/providers/migrations/v1.1-to-v1.2?search=#required-api-changes-for-providers
72+
if *req.DryRun {
73+
return admission.Allowed("")
74+
}
7075
if err := wh.decoder.DecodeRaw(req.Object, kvTmplt); err != nil {
7176
return admission.Errored(http.StatusBadRequest, err)
7277
}

pkg/webhookhandler/validator_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ package webhookhandler
1818
import (
1919
"context"
2020
"errors"
21-
"k8s.io/apimachinery/pkg/runtime/serializer"
2221
"net/http"
2322

23+
"k8s.io/apimachinery/pkg/runtime/serializer"
24+
2425
. "github.com/onsi/ginkgo/v2"
2526
. "github.com/onsi/gomega"
2627
admissionv1 "k8s.io/api/admission/v1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
"k8s.io/client-go/kubernetes/scheme"
3031
"k8s.io/utils/pointer"
32+
"k8s.io/utils/ptr"
3133
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3234

3335
"sigs.k8s.io/cluster-api-provider-kubevirt/api/v1alpha1"
@@ -180,6 +182,7 @@ func newRequest(operation admissionv1.Operation, oldObj, newObj *v1alpha1.Kubevi
180182
Object: oldObj,
181183
}
182184
case admissionv1.Update:
185+
req.DryRun = ptr.To(false)
183186
req.Object = runtime.RawExtension{
184187
Raw: []byte(runtime.EncodeOrDie(encoder, newObj)),
185188
Object: oldObj,

0 commit comments

Comments
 (0)