@@ -36,10 +36,12 @@ import (
3636 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
3737 asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
3838 asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
39+ asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
3940 . "github.com/onsi/ginkgo/v2"
4041 . "github.com/onsi/gomega"
4142 corev1 "k8s.io/api/core/v1"
4243 apierrors "k8s.io/apimachinery/pkg/api/errors"
44+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
4345 "k8s.io/apimachinery/pkg/runtime"
4446 "k8s.io/apimachinery/pkg/runtime/schema"
4547 "k8s.io/kubectl/pkg/describe"
@@ -49,6 +51,7 @@ import (
4951 infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
5052 expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
5153 "sigs.k8s.io/cluster-api/test/framework"
54+ "sigs.k8s.io/controller-runtime/pkg/client"
5255)
5356
5457type (
@@ -74,6 +77,7 @@ func initScheme() *runtime.Scheme {
7477 Expect (infrav1exp .AddToScheme (scheme )).To (Succeed ())
7578 Expect (infrav1expalpha .AddToScheme (scheme )).To (Succeed ())
7679 Expect (expv1 .AddToScheme (scheme )).To (Succeed ())
80+ Expect (asoresourcesv1 .AddToScheme (scheme )).To (Succeed ())
7781 Expect (asocontainerservicev1 .AddToScheme (scheme )).To (Succeed ())
7882 Expect (asocontainerservicev1preview .AddToScheme (scheme )).To (Succeed ())
7983 return scheme
@@ -225,6 +229,26 @@ func (acp *AzureClusterProxy) collectActivityLogs(ctx context.Context, namespace
225229 workloadCluster , err := getAzureCluster (timeoutctx , clusterClient , namespace , name )
226230 if apierrors .IsNotFound (err ) {
227231 controlPlane , err := getAzureManagedControlPlane (timeoutctx , clusterClient , namespace , name )
232+ if apierrors .IsNotFound (err ) {
233+ asoCluster , err := getAzureASOManagedCluster (timeoutctx , clusterClient , namespace , name )
234+ if err != nil {
235+ // Failing to fetch logs should not cause the test to fail
236+ 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 )
237+ return
238+ }
239+ for _ , resource := range asoCluster .Spec .Resources {
240+ u := & unstructured.Unstructured {}
241+ Expect (u .UnmarshalJSON (resource .Raw )).To (Succeed ())
242+ if u .GroupVersionKind ().Kind != "ResourceGroup" {
243+ continue
244+ }
245+ // AzureName might not be specified in the CAPZ resource. GET the rg to make sure we have it.
246+ rg := & asoresourcesv1.ResourceGroup {}
247+ Expect (clusterClient .Get (ctx , client .ObjectKeyFromObject (u ), rg )).To (Succeed ())
248+ groupName = rg .AzureName ()
249+ break
250+ }
251+ }
228252 if err != nil {
229253 // Failing to fetch logs should not cause the test to fail
230254 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 )
0 commit comments