Skip to content

Commit

Permalink
Merge pull request #277 from aamoyel/topology-dryrun-check
Browse files Browse the repository at this point in the history
feat: check if the request is a dry-run to match CAPI topology design
  • Loading branch information
k8s-ci-robot committed Mar 6, 2024
2 parents d2b2668 + 5b1a081 commit f80289f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v12.0.0+incompatible
k8s.io/utils v0.0.0-20230505201702-9f6742963106
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
kubevirt.io/api v1.0.0
kubevirt.io/client-go v0.0.0-00010101000000-000000000000
sigs.k8s.io/cluster-api v1.5.2
Expand Down
4 changes: 2 additions & 2 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1683,8 +1683,8 @@ k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6/go.mod h1:sZAwmy6armz5eXlNoLmJcl
k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kubevirt.io/api v1.0.0 h1:RBdXP5CDhE0v5qL2OUQdrYyRrHe/F68Z91GWqBDF6nw=
kubevirt.io/api v1.0.0/go.mod h1:CJ4vZsaWhVN3jNbyc9y3lIZhw8nUHbWjap0xHABQiqc=
kubevirt.io/client-go v1.0.0 h1:MMn41j/lFd+lJ7gWn7yuIZYW/aT9fI3bUimAuxAQ+Xk=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ require (
k8s.io/component-base v0.28.3
k8s.io/klog/v2 v2.100.1
k8s.io/kubectl v0.28.3
k8s.io/utils v0.0.0-20230505201702-9f6742963106
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
kubevirt.io/api v1.0.0
kubevirt.io/containerized-data-importer-api v1.57.0
sigs.k8s.io/cluster-api v1.5.2
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/kind v0.20.0
Expand Down Expand Up @@ -102,7 +103,6 @@ require (
k8s.io/apiextensions-apiserver v0.28.0 // indirect
k8s.io/cli-runtime v0.28.3 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
kubevirt.io/containerized-data-importer-api v1.57.0 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ k8s.io/kubectl v0.28.3 h1:H1Peu1O3EbN9zHkJCcvhiJ4NUj6lb88sGPO5wrWIM6k=
k8s.io/kubectl v0.28.3/go.mod h1:RDAudrth/2wQ3Sg46fbKKl4/g+XImzvbsSRZdP2RiyE=
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kubevirt.io/api v1.0.0 h1:RBdXP5CDhE0v5qL2OUQdrYyRrHe/F68Z91GWqBDF6nw=
kubevirt.io/api v1.0.0/go.mod h1:CJ4vZsaWhVN3jNbyc9y3lIZhw8nUHbWjap0xHABQiqc=
kubevirt.io/containerized-data-importer-api v1.57.0 h1:IpRCUyDS0x7BaVa5q5MCzuWRAfvXT54GpEnNJke5hSE=
Expand Down
5 changes: 5 additions & 0 deletions pkg/webhookhandler/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (wh *kubevirtMachineTemplateHandler) Handle(_ context.Context, req admissio

case admissionv1.Update:
oldKVTmplt := &v1alpha1.KubevirtMachineTemplate{}
// Server Side Apply implementation in ClusterClass and managed topologies requires to dry-run changes on templates.
// cf: https://cluster-api.sigs.k8s.io/developer/providers/migrations/v1.1-to-v1.2?search=#required-api-changes-for-providers
if *req.DryRun {
return admission.Allowed("")
}
if err := wh.decoder.DecodeRaw(req.Object, kvTmplt); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/webhookhandler/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ package webhookhandler
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/serializer"
"net/http"

"k8s.io/apimachinery/pkg/runtime/serializer"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
admissionv1 "k8s.io/api/admission/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

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

0 comments on commit f80289f

Please sign in to comment.