Skip to content

Commit 4543ef5

Browse files
authored
Merge pull request #5139 from nojnhuh/aks-ext
delete AKS extensions when they are removed from spec
2 parents 5068143 + cccdcd5 commit 4543ef5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

azure/services/aksextensions/aksextensions.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ limitations under the License.
1717
package aksextensions
1818

1919
import (
20+
"context"
21+
2022
asokubernetesconfigurationv1 "github.com/Azure/azure-service-operator/v2/api/kubernetesconfiguration/v1api20230501"
2123
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2224
"sigs.k8s.io/cluster-api-provider-azure/azure"
2325
"sigs.k8s.io/cluster-api-provider-azure/azure/services/aso"
26+
"sigs.k8s.io/cluster-api-provider-azure/util/slice"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
2428
)
2529

2630
const serviceName = "extension"
@@ -41,10 +45,17 @@ type Service struct {
4145
// New creates a new service.
4246
func New(scope AKSExtensionScope) *Service {
4347
svc := aso.NewService[*asokubernetesconfigurationv1.Extension, AKSExtensionScope](serviceName, scope)
48+
svc.ListFunc = list
4449
svc.Specs = scope.AKSExtensionSpecs()
4550
svc.ConditionType = infrav1.AKSExtensionsReadyCondition
4651
return &Service{
4752
Scope: scope,
4853
Service: svc,
4954
}
5055
}
56+
57+
func list(ctx context.Context, client client.Client, opts ...client.ListOption) ([]*asokubernetesconfigurationv1.Extension, error) {
58+
list := &asokubernetesconfigurationv1.ExtensionList{}
59+
err := client.List(ctx, list, opts...)
60+
return slice.ToPtrs(list.Items), err
61+
}

test/e2e/aks_marketplace.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)