Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions azure/services/aksextensions/aksextensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ limitations under the License.
package aksextensions

import (
"context"

asokubernetesconfigurationv1 "github.com/Azure/azure-service-operator/v2/api/kubernetesconfiguration/v1api20230501"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/aso"
"sigs.k8s.io/cluster-api-provider-azure/util/slice"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const serviceName = "extension"
Expand All @@ -41,10 +45,17 @@ type Service struct {
// New creates a new service.
func New(scope AKSExtensionScope) *Service {
svc := aso.NewService[*asokubernetesconfigurationv1.Extension, AKSExtensionScope](serviceName, scope)
svc.ListFunc = list
svc.Specs = scope.AKSExtensionSpecs()
svc.ConditionType = infrav1.AKSExtensionsReadyCondition
return &Service{
Scope: scope,
Service: svc,
}
}

func list(ctx context.Context, client client.Client, opts ...client.ListOption) ([]*asokubernetesconfigurationv1.Extension, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you name this to something more descriptive like listAKSExtensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the signature and this existing in the aksextensions package make that clear? I've been trying to optimize these for copy-paste-ability since it's pretty much the same between all the ASO services so adding the type again here would be one more place to change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me!

list := &asokubernetesconfigurationv1.ExtensionList{}
err := client.List(ctx, list, opts...)
return slice.ToPtrs(list.Items), err
}
23 changes: 23 additions & 0 deletions test/e2e/aks_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -165,6 +166,21 @@ func AKSMarketplaceExtensionSpec(ctx context.Context, inputGetter func() AKSMark
ensureAKSExtensionAdded(ctx, input, extensionName, "TraefikLabs.TraefikProxy", extensionClient, amcp)
ensureAKSExtensionAdded(ctx, input, officialExtensionName, "microsoft.flux", extensionClient, amcp)

By("Deleting the AKS Marketplace Extension")
Eventually(func(g Gomega) {
err = mgmtClient.Get(ctx, client.ObjectKey{
Namespace: input.Cluster.Spec.ControlPlaneRef.Namespace,
Name: input.Cluster.Spec.ControlPlaneRef.Name,
}, infraControlPlane)
g.Expect(err).NotTo(HaveOccurred())
infraControlPlane.Spec.Extensions = []infrav1.AKSExtension{}
g.Expect(mgmtClient.Update(ctx, infraControlPlane)).To(Succeed())
}, input.WaitIntervals...).Should(Succeed())

By("Ensuring the AKS Marketplace Extension is deleted from the AzureManagedControlPlane")
ensureAKSExtensionDeleted(ctx, input, extensionName, extensionClient, amcp)
ensureAKSExtensionDeleted(ctx, input, officialExtensionName, extensionClient, amcp)

By("Restoring initial taints for Windows machine pool")
expectedTaints = initialTaints
Eventually(func(g Gomega) {
Expand All @@ -187,3 +203,10 @@ func ensureAKSExtensionAdded(ctx context.Context, input AKSMarketplaceExtensionS
g.Expect(extension.Properties.ExtensionType).To(Equal(ptr.To(extensionType)))
}, input.WaitIntervals...).Should(Succeed())
}

func ensureAKSExtensionDeleted(ctx context.Context, input AKSMarketplaceExtensionSpecInput, extensionName string, extensionClient *armkubernetesconfiguration.ExtensionsClient, amcp *infrav1.AzureManagedControlPlane) {
Eventually(func(g Gomega) {
_, err := extensionClient.Get(ctx, amcp.Spec.ResourceGroupName, "Microsoft.ContainerService", "managedClusters", input.Cluster.Name, extensionName, nil)
g.Expect(azure.ResourceNotFound(err)).To(BeTrue())
}, input.WaitIntervals...).Should(Succeed())
}