| 
 | 1 | +/*  | 
 | 2 | +Copyright 2025 The Kubernetes Authors.  | 
 | 3 | +
  | 
 | 4 | +Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | +you may not use this file except in compliance with the License.  | 
 | 6 | +You may obtain a copy of the License at  | 
 | 7 | +
  | 
 | 8 | +    http://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | +
  | 
 | 10 | +Unless required by applicable law or agreed to in writing, software  | 
 | 11 | +distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | +See the License for the specific language governing permissions and  | 
 | 14 | +limitations under the License.  | 
 | 15 | +*/  | 
 | 16 | + | 
 | 17 | +package controllers  | 
 | 18 | + | 
 | 19 | +import (  | 
 | 20 | +	"context"  | 
 | 21 | +	"testing"  | 
 | 22 | + | 
 | 23 | +	asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"  | 
 | 24 | +	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"  | 
 | 25 | +	. "github.com/onsi/gomega"  | 
 | 26 | +	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"  | 
 | 27 | +	"k8s.io/apimachinery/pkg/types"  | 
 | 28 | +	"k8s.io/utils/ptr"  | 
 | 29 | +	infrav1alpha "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha1"  | 
 | 30 | +	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"  | 
 | 31 | +	ctrl "sigs.k8s.io/controller-runtime"  | 
 | 32 | +	"sigs.k8s.io/controller-runtime/pkg/client/fake"  | 
 | 33 | +)  | 
 | 34 | + | 
 | 35 | +func TestAgentPoolAdoptController(t *testing.T) {  | 
 | 36 | +	g := NewWithT(t)  | 
 | 37 | +	req := ctrl.Request{NamespacedName: types.NamespacedName{Name: "fake-agent-pool", Namespace: "fake-ns"}}  | 
 | 38 | +	ctx := context.Background()  | 
 | 39 | +	scheme, err := newScheme()  | 
 | 40 | +	g.Expect(err).To(BeNil())  | 
 | 41 | + | 
 | 42 | +	agentPool := &asocontainerservicev1.ManagedClustersAgentPool{  | 
 | 43 | +		ObjectMeta: metav1.ObjectMeta{  | 
 | 44 | +			Name:      "fake-agent-pool",  | 
 | 45 | +			Namespace: "fake-ns",  | 
 | 46 | +			Annotations: map[string]string{  | 
 | 47 | +				adoptAnnotation: adoptAnnotationValue,  | 
 | 48 | +			},  | 
 | 49 | +			OwnerReferences: []metav1.OwnerReference{  | 
 | 50 | +				{  | 
 | 51 | +					Kind:       infrav1alpha.AzureASOManagedMachinePoolKind,  | 
 | 52 | +					APIVersion: infrav1alpha.GroupVersion.Identifier(),  | 
 | 53 | +				},  | 
 | 54 | +			},  | 
 | 55 | +		},  | 
 | 56 | +		Spec: asocontainerservicev1.ManagedClustersAgentPool_Spec{  | 
 | 57 | +			Count: ptr.To(1),  | 
 | 58 | +			Owner: &genruntime.KnownResourceReference{  | 
 | 59 | +				Name: "fake-managed-cluster",  | 
 | 60 | +			},  | 
 | 61 | +		},  | 
 | 62 | +	}  | 
 | 63 | +	mc := &asocontainerservicev1.ManagedCluster{  | 
 | 64 | +		ObjectMeta: metav1.ObjectMeta{  | 
 | 65 | +			Name:      "fake-managed-cluster",  | 
 | 66 | +			Namespace: "fake-ns",  | 
 | 67 | +			OwnerReferences: []metav1.OwnerReference{  | 
 | 68 | +				{  | 
 | 69 | +					Kind:       infrav1alpha.AzureASOManagedControlPlaneKind,  | 
 | 70 | +					APIVersion: infrav1alpha.GroupVersion.Identifier(),  | 
 | 71 | +					Name:       "fake-managed-cluster",  | 
 | 72 | +				},  | 
 | 73 | +			},  | 
 | 74 | +		},  | 
 | 75 | +	}  | 
 | 76 | +	asoManagedControlPlane := &infrav1alpha.AzureASOManagedControlPlane{  | 
 | 77 | +		ObjectMeta: metav1.ObjectMeta{  | 
 | 78 | +			Name:      "fake-managed-cluster",  | 
 | 79 | +			Namespace: "fake-ns",  | 
 | 80 | +			Labels: map[string]string{  | 
 | 81 | +				clusterv1.ClusterNameLabel: "cluster-name",  | 
 | 82 | +			},  | 
 | 83 | +		},  | 
 | 84 | +	}  | 
 | 85 | + | 
 | 86 | +	asocontainerservicev1.AddToScheme(scheme)  | 
 | 87 | +	infrav1alpha.AddToScheme(scheme)  | 
 | 88 | +	client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(agentPool, mc, asoManagedControlPlane).WithStatusSubresource(mc, agentPool, asoManagedControlPlane).Build()  | 
 | 89 | +	aprec := &AgentPoolAdoptReconciler{  | 
 | 90 | +		Client: client,  | 
 | 91 | +	}  | 
 | 92 | +	_, err = aprec.Reconcile(ctx, req)  | 
 | 93 | +	g.Expect(err).To(BeNil())  | 
 | 94 | +}  | 
0 commit comments