Skip to content

Commit

Permalink
fixup! ASOAPI: add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Apr 29, 2024
1 parent a892adf commit 0515d35
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/e2e/azure_clusterproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubectl/pkg/describe"
Expand All @@ -49,6 +51,7 @@ import (
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type (
Expand All @@ -74,6 +77,7 @@ func initScheme() *runtime.Scheme {
Expect(infrav1exp.AddToScheme(scheme)).To(Succeed())
Expect(infrav1expalpha.AddToScheme(scheme)).To(Succeed())
Expect(expv1.AddToScheme(scheme)).To(Succeed())
Expect(asoresourcesv1.AddToScheme(scheme)).To(Succeed())
Expect(asocontainerservicev1.AddToScheme(scheme)).To(Succeed())
Expect(asocontainerservicev1preview.AddToScheme(scheme)).To(Succeed())
return scheme
Expand Down Expand Up @@ -225,6 +229,26 @@ func (acp *AzureClusterProxy) collectActivityLogs(ctx context.Context, namespace
workloadCluster, err := getAzureCluster(timeoutctx, clusterClient, namespace, name)
if apierrors.IsNotFound(err) {
controlPlane, err := getAzureManagedControlPlane(timeoutctx, clusterClient, namespace, name)
if apierrors.IsNotFound(err) {
asoCluster, err := getAzureASOManagedCluster(timeoutctx, clusterClient, namespace, name)
if err != nil {
// Failing to fetch logs should not cause the test to fail
Logf("Error fetching activity logs for cluster %s in namespace %s. Not able to find the AzureASOManagedCluster on the management cluster: %v", name, namespace, err)
return
}
for _, resource := range asoCluster.Spec.Resources {
u := &unstructured.Unstructured{}
Expect(u.UnmarshalJSON(resource.Raw)).To(Succeed())
if u.GroupVersionKind().Kind != "ResourceGroup" {
continue
}
// AzureName might not be specified in the CAPZ resource. GET the rg to make sure we have it.
rg := &asoresourcesv1.ResourceGroup{}
Expect(clusterClient.Get(ctx, client.ObjectKeyFromObject(u), rg)).To(Succeed())
groupName = rg.AzureName()

Check failure on line 248 in test/e2e/azure_clusterproxy.go

View workflow job for this annotation

GitHub Actions / coverage

ineffectual assignment to groupName (ineffassign)
break
}
}
if err != nil {
// Failing to fetch logs should not cause the test to fail
Logf("Error fetching activity logs for cluster %s in namespace %s. Not able to find the AzureManagedControlPlane on the management cluster: %v", name, namespace, err)
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/azure_logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
infrav1expalpha "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha1"
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -94,6 +95,10 @@ func (k AzureLogCollector) CollectMachinePoolLog(ctx context.Context, management
// Machine pool can be an AzureManagedMachinePool for AKS clusters.
_, err = getAzureManagedMachinePool(ctx, managementClusterClient, mp)
if err != nil {
if !apierrors.IsNotFound(err) {
return err
}
_, err = getAzureASOManagedMachinePool(ctx, managementClusterClient, mp)
return err
}
} else {
Expand Down Expand Up @@ -205,6 +210,17 @@ func getAzureManagedControlPlane(ctx context.Context, managementClusterClient cl
return azManagedControlPlane, err
}

func getAzureASOManagedCluster(ctx context.Context, managementClusterClient client.Client, namespace, name string) (*infrav1expalpha.AzureASOManagedCluster, error) {
key := client.ObjectKey{
Namespace: namespace,
Name: name,
}

azManagedCluster := &infrav1expalpha.AzureASOManagedCluster{}
err := managementClusterClient.Get(ctx, key, azManagedCluster)
return azManagedCluster, err
}

func getAzureMachine(ctx context.Context, managementClusterClient client.Client, m *clusterv1.Machine) (*infrav1.AzureMachine, error) {
key := client.ObjectKey{
Namespace: m.Spec.InfrastructureRef.Namespace,
Expand Down Expand Up @@ -238,6 +254,17 @@ func getAzureManagedMachinePool(ctx context.Context, managementClusterClient cli
return azManagedMachinePool, err
}

func getAzureASOManagedMachinePool(ctx context.Context, managementClusterClient client.Client, mp *expv1.MachinePool) (*infrav1expalpha.AzureASOManagedMachinePool, error) {
key := client.ObjectKey{
Namespace: mp.Spec.Template.Spec.InfrastructureRef.Namespace,
Name: mp.Spec.Template.Spec.InfrastructureRef.Name,
}

azManagedMachinePool := &infrav1expalpha.AzureASOManagedMachinePool{}
err := managementClusterClient.Get(ctx, key, azManagedMachinePool)
return azManagedMachinePool, err
}

func linuxLogs(execToPathFn func(outputFileName string, command string, args ...string) func() error) []func() error {
return []func() error{
execToPathFn(
Expand Down

0 comments on commit 0515d35

Please sign in to comment.