Skip to content

Commit

Permalink
Merge pull request #4097 from nojnhuh/overlay-webhook
Browse files Browse the repository at this point in the history
fix webhook for CNI overlay
  • Loading branch information
k8s-ci-robot authored Oct 6, 2023
2 parents b9430aa + b5eb475 commit e8c1108
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,10 @@ func (m *AzureManagedControlPlane) validateVirtualNetworkUpdate(old *AzureManage
func (m *AzureManagedControlPlane) validateNetworkPluginModeUpdate(old *AzureManagedControlPlane) field.ErrorList {
var allErrs field.ErrorList

if ptr.Deref(m.Spec.NetworkPluginMode, "") == NetworkPluginModeOverlay && old.Spec.NetworkPolicy != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("Spec", "NetworkPluginMode"), fmt.Sprintf("%q NetworkPolicyMode cannot be enabled when NetworkPolicy is set", NetworkPluginModeOverlay)))
if ptr.Deref(old.Spec.NetworkPluginMode, "") != NetworkPluginModeOverlay &&
ptr.Deref(m.Spec.NetworkPluginMode, "") == NetworkPluginModeOverlay &&
old.Spec.NetworkPolicy != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("Spec", "NetworkPluginMode"), fmt.Sprintf("%q NetworkPluginMode cannot be enabled when NetworkPolicy is set", NetworkPluginModeOverlay)))
}

return allErrs
Expand Down
24 changes: 24 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
Name: "test-cluster",
},
Spec: AzureManagedControlPlaneSpec{
NetworkPolicy: ptr.To("anything"),
NetworkPluginMode: ptr.To(NetworkPluginModeOverlay),
},
},
Expand Down Expand Up @@ -1583,6 +1584,29 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
},
wantErr: false,
},
{
name: "NetworkPolicy is allowed when NetworkPluginMode is not changed",
oldAMCP: &AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: AzureManagedControlPlaneSpec{
NetworkPolicy: ptr.To("anything"),
NetworkPluginMode: ptr.To(NetworkPluginModeOverlay),
},
},
amcp: &AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: AzureManagedControlPlaneSpec{
NetworkPolicy: ptr.To("anything"),
NetworkPluginMode: ptr.To(NetworkPluginModeOverlay),
Version: "v0.0.0",
},
},
wantErr: false,
},
{
name: "AzureManagedControlPlane OIDCIssuerProfile.Enabled false -> false OK",
oldAMCP: &AzureManagedControlPlane{
Expand Down

0 comments on commit e8c1108

Please sign in to comment.