@@ -73,6 +73,9 @@ func TestAKSOtelContainerInsights(t *testing.T) {
7373 t .Run ("OTELConfigRouting" , func (t * testing.T ) {
7474 validateOTELConfigRoutingAKS (t , agentMap )
7575 })
76+ t .Run ("WebhookEnforcerDisabled" , func (t * testing.T ) {
77+ validateAKSWebhookEnforcerDisabled (t , k8sClient )
78+ })
7679
7780 t .Log ("AKS OTEL Container Insights scenario validation passed" )
7881}
@@ -197,3 +200,39 @@ func validateAKSHostAttributes(t *testing.T, agentMap map[string]unstructured.Un
197200 assertEnabled ("node agent" , otelConfigOf (t , agentMap , "cloudwatch-agent" ), true )
198201 assertEnabled ("cluster-scraper" , otelConfigOf (t , agentMap , "cloudwatch-agent-cluster-scraper" ), false )
199202}
203+
204+ // validateAKSWebhookEnforcerDisabled checks the webhook configurations carry the
205+ // admissions.enforcer/disabled annotation on AKS. Without it, the AKS admissionsenforcer rewrites each
206+ // webhook's namespaceSelector and takes server-side-apply ownership of the field, which makes the next
207+ // helm upgrade fail with an apply conflict.
208+ func validateAKSWebhookEnforcerDisabled (t * testing.T , k8sClient * util.K8sClient ) {
209+ const enforcerDisabled = "admissions.enforcer/disabled"
210+
211+ mwc , err := k8sClient .ListMutatingWebhookConfigurations ()
212+ require .NoError (t , err , "failed to list MutatingWebhookConfigurations" )
213+ assertEnforcerDisabled := func (name string , annotations map [string ]string ) {
214+ assert .Equal (t , "true" , annotations [enforcerDisabled ],
215+ "%s should set %s on AKS" , name , enforcerDisabled )
216+ }
217+
218+ foundMutating := false
219+ for _ , wh := range mwc .Items {
220+ if wh .Name == minikube .WebhookName {
221+ foundMutating = true
222+ assertEnforcerDisabled (wh .Name , wh .Annotations )
223+ }
224+ }
225+ assert .True (t , foundMutating , "mutating webhook configuration %s should exist" , minikube .WebhookName )
226+
227+ vwc , err := k8sClient .ListValidatingWebhookConfigurations ()
228+ require .NoError (t , err , "failed to list ValidatingWebhookConfigurations" )
229+ validatingName := "amazon-cloudwatch-observability-validating-webhook-configuration"
230+ foundValidating := false
231+ for _ , wh := range vwc .Items {
232+ if wh .Name == validatingName {
233+ foundValidating = true
234+ assertEnforcerDisabled (wh .Name , wh .Annotations )
235+ }
236+ }
237+ assert .True (t , foundValidating , "validating webhook configuration %s should exist" , validatingName )
238+ }
0 commit comments