Skip to content

Commit

Permalink
Move webhook registration behind feature gate flag
Browse files Browse the repository at this point in the history
Move webhook registration behind feature gate flags similar to
controller registration.

Signed-off-by: Bryan Cox <[email protected]>
  • Loading branch information
bryan-cox committed Aug 28, 2024
1 parent cc3e8e9 commit 83f3f66
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ func registerWebhooks(mgr manager.Manager) {
os.Exit(1)
}

if err := infrav1.SetupAzureMachineWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachine")
os.Exit(1)

Check warning on line 594 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L592-L594

Added lines #L592 - L594 were not covered by tests
}

if err := (&infrav1.AzureMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachineTemplate")
os.Exit(1)
Expand All @@ -599,66 +604,65 @@ func registerWebhooks(mgr manager.Manager) {
os.Exit(1)
}

if err := (&infrav1exp.AzureMachinePoolMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachinePoolMachine")
os.Exit(1)
}

// NOTE: AzureManagedCluster is behind AKS feature gate flag; the webhook
// is going to prevent creating or updating new objects in case the feature flag is disabled
if err := (&infrav1.AzureManagedCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedCluster")
os.Exit(1)
}
if feature.Gates.Enabled(capifeature.MachinePool) {
if err := infrav1exp.SetupAzureMachinePoolWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachinePool")
os.Exit(1)

Check warning on line 610 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L607-L610

Added lines #L607 - L610 were not covered by tests
}

if err := (&infrav1.AzureManagedClusterTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedClusterTemplate")
os.Exit(1)
}
if err := (&infrav1exp.AzureMachinePoolMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachinePoolMachine")
os.Exit(1)

Check warning on line 615 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L613-L615

Added lines #L613 - L615 were not covered by tests
}

if err := infrav1exp.SetupAzureMachinePoolWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachinePool")
os.Exit(1)
}
if err := infrav1.SetupAzureManagedMachinePoolWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedMachinePool")
os.Exit(1)

Check warning on line 620 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L618-L620

Added lines #L618 - L620 were not covered by tests
}

if err := infrav1.SetupAzureMachineWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureMachine")
os.Exit(1)
}
if err := infrav1.SetupAzureManagedMachinePoolTemplateWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedMachinePoolTemplate")
os.Exit(1)

Check warning on line 625 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L623-L625

Added lines #L623 - L625 were not covered by tests
}

if err := infrav1.SetupAzureManagedMachinePoolWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedMachinePool")
os.Exit(1)
}
// NOTE: AzureManagedCluster is behind AKS feature gate flag; the webhook
// is going to prevent creating or updating new objects in case the feature flag is disabled
if err := (&infrav1.AzureManagedCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedCluster")
os.Exit(1)

Check warning on line 632 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L630-L632

Added lines #L630 - L632 were not covered by tests
}

if err := infrav1.SetupAzureManagedMachinePoolTemplateWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedMachinePoolTemplate")
os.Exit(1)
}
if err := (&infrav1.AzureManagedClusterTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedClusterTemplate")
os.Exit(1)

Check warning on line 637 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L635-L637

Added lines #L635 - L637 were not covered by tests
}

if err := infrav1.SetupAzureManagedControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedControlPlane")
os.Exit(1)
}
if err := infrav1.SetupAzureManagedControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedControlPlane")
os.Exit(1)

Check warning on line 642 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L640-L642

Added lines #L640 - L642 were not covered by tests
}

if err := infrav1.SetupAzureManagedControlPlaneTemplateWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedControlPlaneTemplate")
os.Exit(1)
if err := infrav1.SetupAzureManagedControlPlaneTemplateWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureManagedControlPlaneTemplate")
os.Exit(1)

Check warning on line 647 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L645-L647

Added lines #L645 - L647 were not covered by tests
}
}

if err := infrav1alpha.SetupAzureASOManagedClusterWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureASOManagedCluster")
os.Exit(1)
}
if feature.Gates.Enabled(feature.ASOAPI) {
if err := infrav1alpha.SetupAzureASOManagedClusterWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureASOManagedCluster")
os.Exit(1)

Check warning on line 654 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L651-L654

Added lines #L651 - L654 were not covered by tests
}

if err := infrav1alpha.SetupAzureASOManagedControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureASOManagedControlPlane")
os.Exit(1)
}
if err := infrav1alpha.SetupAzureASOManagedControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureASOManagedControlPlane")
os.Exit(1)

Check warning on line 659 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L657-L659

Added lines #L657 - L659 were not covered by tests
}

if err := infrav1alpha.SetupAzureASOManagedMachinePoolWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureASOManagedMachinePool")
os.Exit(1)
if err := infrav1alpha.SetupAzureASOManagedMachinePoolWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureASOManagedMachinePool")
os.Exit(1)

Check warning on line 664 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L662-L664

Added lines #L662 - L664 were not covered by tests
}
}

if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
Expand Down

0 comments on commit 83f3f66

Please sign in to comment.