@@ -32,6 +32,7 @@ import (
3232 "k8s.io/apimachinery/pkg/types"
3333 "k8s.io/utils/ptr"
3434 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
35+ "sigs.k8s.io/cluster-api-provider-azure/azure"
3536 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3637 "sigs.k8s.io/cluster-api/util/conditions"
3738 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -165,6 +166,21 @@ func AKSMarketplaceExtensionSpec(ctx context.Context, inputGetter func() AKSMark
165166 ensureAKSExtensionAdded (ctx , input , extensionName , "TraefikLabs.TraefikProxy" , extensionClient , amcp )
166167 ensureAKSExtensionAdded (ctx , input , officialExtensionName , "microsoft.flux" , extensionClient , amcp )
167168
169+ By ("Deleting the AKS Marketplace Extension" )
170+ Eventually (func (g Gomega ) {
171+ err = mgmtClient .Get (ctx , client.ObjectKey {
172+ Namespace : input .Cluster .Spec .ControlPlaneRef .Namespace ,
173+ Name : input .Cluster .Spec .ControlPlaneRef .Name ,
174+ }, infraControlPlane )
175+ g .Expect (err ).NotTo (HaveOccurred ())
176+ infraControlPlane .Spec .Extensions = []infrav1.AKSExtension {}
177+ g .Expect (mgmtClient .Update (ctx , infraControlPlane )).To (Succeed ())
178+ }, input .WaitIntervals ... ).Should (Succeed ())
179+
180+ By ("Ensuring the AKS Marketplace Extension is deleted from the AzureManagedControlPlane" )
181+ ensureAKSExtensionDeleted (ctx , input , extensionName , extensionClient , amcp )
182+ ensureAKSExtensionDeleted (ctx , input , officialExtensionName , extensionClient , amcp )
183+
168184 By ("Restoring initial taints for Windows machine pool" )
169185 expectedTaints = initialTaints
170186 Eventually (func (g Gomega ) {
@@ -187,3 +203,10 @@ func ensureAKSExtensionAdded(ctx context.Context, input AKSMarketplaceExtensionS
187203 g .Expect (extension .Properties .ExtensionType ).To (Equal (ptr .To (extensionType )))
188204 }, input .WaitIntervals ... ).Should (Succeed ())
189205}
206+
207+ func ensureAKSExtensionDeleted (ctx context.Context , input AKSMarketplaceExtensionSpecInput , extensionName string , extensionClient * armkubernetesconfiguration.ExtensionsClient , amcp * infrav1.AzureManagedControlPlane ) {
208+ Eventually (func (g Gomega ) {
209+ _ , err := extensionClient .Get (ctx , amcp .Spec .ResourceGroupName , "Microsoft.ContainerService" , "managedClusters" , input .Cluster .Name , extensionName , nil )
210+ g .Expect (azure .ResourceNotFound (err )).To (BeTrue ())
211+ }, input .WaitIntervals ... ).Should (Succeed ())
212+ }
0 commit comments