Skip to content

Commit

Permalink
skip mutating and validating webhooks on dry runs
Browse files Browse the repository at this point in the history
- revert using nhk fork of CAPI
  • Loading branch information
nawazkh committed Jan 15, 2025
1 parent 6cc8fbf commit 86a4ff7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions exp/api/v1beta1/azuremachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func (w *azureMachinePoolMutatingWebhook) Handle(ctx context.Context, req admiss
return admission.Errored(http.StatusBadRequest, err)
}

// if dry run is enabled, skip the defaulting logic
if req.DryRun != nil && *req.DryRun {
return admission.Allowed("dry run")
}

switch req.Operation {
case admissionv1.Create, admissionv1.Update:
// Apply defaulting logic (similar to your old amp.SetDefaults(ampw.Client))
Expand Down Expand Up @@ -129,6 +134,11 @@ type azureMachinePoolValidatingWebhook struct {
// Handle implements admission.Handler so the controller-runtime can call this
// for CREATE, UPDATE, and potentially DELETE (if you configure `verbs=delete` too).
func (w *azureMachinePoolValidatingWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
// if dry run is enabled, skip the defaulting logic
if req.DryRun != nil && *req.DryRun {
return admission.Allowed("dry run")
}

switch req.Operation {
case admissionv1.Create:
return w.handleCreate(ctx, req)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace sigs.k8s.io/cluster-api => github.com/nawazkh/cluster-api v1.1.0-beta.2.0.20250115195605-9992a46caa35

replace sigs.k8s.io/cluster-api/test => github.com/nawazkh/cluster-api/test v1.1.0-beta.2.0.20250115195605-9992a46caa35
//replace sigs.k8s.io/cluster-api => github.com/nawazkh/cluster-api v1.1.0-beta.2.0.20250115195605-9992a46caa35
//
//replace sigs.k8s.io/cluster-api/test => github.com/nawazkh/cluster-api/test v1.1.0-beta.2.0.20250115195605-9992a46caa35
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nawazkh/cluster-api v1.1.0-beta.2.0.20250115195605-9992a46caa35 h1:afbB/eJAPfbIJD8R2uJ0637DlT+pna+zB94He4kQEHw=
github.com/nawazkh/cluster-api v1.1.0-beta.2.0.20250115195605-9992a46caa35/go.mod h1:5iojv38PSvOd4cxqu08Un5TQmy2yBkd3+0U7R/e+msk=
github.com/nawazkh/cluster-api/test v1.1.0-beta.2.0.20250115195605-9992a46caa35 h1:gVUaQm6JjvvafyjYwYs0uKoYUET7Kb71J51zF9QAV44=
github.com/nawazkh/cluster-api/test v1.1.0-beta.2.0.20250115195605-9992a46caa35/go.mod h1:RbMw6WR4vwqzu9tx13MmRsnIR+WLQ6xx8BMFtvPYUOY=
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
Expand Down Expand Up @@ -737,6 +733,10 @@ sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.29 h1:qiifAaaBqV3d/EcN9dKJaJI
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.29/go.mod h1:ZFAt0qF1kR+w8nBVJK56s6CFvLrlosN1i2c+Sxb7LBk=
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.16 h1:Fm/Yjv4nXjUtJ90uXKSKwPwaTWYuDFMhDNNOd77PlOg=
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.16/go.mod h1:+kl90flu4+WCP6HBGVYbKVQR+5ztDzUNrWJz8rsnvRU=
sigs.k8s.io/cluster-api v1.9.3 h1:lKWbrXzyNmJh++IcX54ZbAmnO7tZ2wKgds7WvskpiXY=
sigs.k8s.io/cluster-api v1.9.3/go.mod h1:5iojv38PSvOd4cxqu08Un5TQmy2yBkd3+0U7R/e+msk=
sigs.k8s.io/cluster-api/test v1.9.3 h1:65w87EX4X+W+jJ1MkSh+DOTK+T9Di4yS+eMjtCKq9+8=
sigs.k8s.io/cluster-api/test v1.9.3/go.mod h1:RbMw6WR4vwqzu9tx13MmRsnIR+WLQ6xx8BMFtvPYUOY=
sigs.k8s.io/controller-runtime v0.19.3 h1:XO2GvC9OPftRst6xWCpTgBZO04S2cbp0Qqkj8bX1sPw=
sigs.k8s.io/controller-runtime v0.19.3/go.mod h1:j4j87DqtsThvwTv5/Tc5NFRyyF/RF0ip4+62tbTSIUM=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
Expand Down

0 comments on commit 86a4ff7

Please sign in to comment.