From a752b2740bd843503d3e916bab73b55d10b6c475 Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Sat, 10 Aug 2024 02:38:57 -0500 Subject: [PATCH] clean up scope unit tests --- azure/scope/cluster_test.go | 862 +++--------------------- azure/scope/managedcontrolplane_test.go | 569 +++------------- azure/scope/managedmachinepool_test.go | 402 +++-------- 3 files changed, 326 insertions(+), 1507 deletions(-) diff --git a/azure/scope/cluster_test.go b/azure/scope/cluster_test.go index 83caf5ca700..9f7dd49fff6 100644 --- a/azure/scope/cluster_test.go +++ b/azure/scope/cluster_test.go @@ -71,9 +71,58 @@ func specArrayToString[T any](specs []T) string { return sb.String() } -func TestAPIServerHost(t *testing.T) { +func TestNewClusterScope(t *testing.T) { + g := NewWithT(t) + + scheme := runtime.NewScheme() + _ = clusterv1.AddToScheme(scheme) + _ = infrav1.AddToScheme(scheme) + _ = corev1.AddToScheme(scheme) + fakeSubscriptionID := "123" + cluster := &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-cluster", + Namespace: "default", + }, + } + azureCluster := &infrav1.AzureCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: cluster.Name, + }, + Spec: infrav1.AzureClusterSpec{ + AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ + SubscriptionID: fakeSubscriptionID, + IdentityRef: &corev1.ObjectReference{ + Kind: infrav1.AzureClusterIdentityKind, + }, + }, + }, + } + azureCluster.Default() + + fakeIdentity := &infrav1.AzureClusterIdentity{ + Spec: infrav1.AzureClusterIdentitySpec{ + Type: infrav1.ServicePrincipal, + ClientID: fakeClientID, + TenantID: fakeTenantID, + }, + } + fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} + + initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} + fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() + + _, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + Cluster: cluster, + AzureCluster: azureCluster, + Client: fakeClient, + }) + g.Expect(err).NotTo(HaveOccurred()) +} + +func TestAPIServerHost(t *testing.T) { tests := []struct { name string azureCluster infrav1.AzureCluster @@ -83,12 +132,6 @@ func TestAPIServerHost(t *testing.T) { name: "public apiserver lb (user-defined dns)", azureCluster: infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: fakeSubscriptionID, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, NetworkSpec: infrav1.NetworkSpec{ APIServerLB: infrav1.LoadBalancerSpec{ FrontendIPs: []infrav1.FrontendIP{ @@ -111,12 +154,6 @@ func TestAPIServerHost(t *testing.T) { name: "private apiserver lb (default private dns zone)", azureCluster: infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: fakeSubscriptionID, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, NetworkSpec: infrav1.NetworkSpec{ APIServerLB: infrav1.LoadBalancerSpec{ FrontendIPs: []infrav1.FrontendIP{ @@ -139,12 +176,6 @@ func TestAPIServerHost(t *testing.T) { name: "private apiserver (user-defined private dns zone)", azureCluster: infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: fakeSubscriptionID, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, NetworkSpec: infrav1.NetworkSpec{ NetworkClassSpec: infrav1.NetworkClassSpec{ PrivateDNSZoneName: "example.private", @@ -164,10 +195,6 @@ func TestAPIServerHost(t *testing.T) { for _, tc := range tests { tc := tc g := NewWithT(t) - scheme := runtime.NewScheme() - _ = clusterv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -178,34 +205,13 @@ func TestAPIServerHost(t *testing.T) { tc.azureCluster.ObjectMeta = metav1.ObjectMeta{ Name: cluster.Name, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, } tc.azureCluster.Default() - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, &tc.azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: &tc.azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } g.Expect(clusterScope.APIServerHost()).Should(Equal(tc.want)) } @@ -213,10 +219,6 @@ func TestAPIServerHost(t *testing.T) { func TestGettingSecurityRules(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = clusterv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -228,21 +230,8 @@ func TestGettingSecurityRules(t *testing.T) { azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-azure-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ { @@ -257,25 +246,10 @@ func TestGettingSecurityRules(t *testing.T) { } azureCluster.Default() - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) - + } clusterScope.SetControlPlaneSecurityRules() subnet, err := clusterScope.AzureCluster.Spec.NetworkSpec.GetControlPlaneSubnet() @@ -294,13 +268,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -312,15 +279,11 @@ func TestPublicIPSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ APIServerLB: infrav1.LoadBalancerSpec{ @@ -338,13 +301,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -356,15 +312,11 @@ func TestPublicIPSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ @@ -385,13 +337,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -403,15 +348,11 @@ func TestPublicIPSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ @@ -455,13 +396,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -473,15 +407,11 @@ func TestPublicIPSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ @@ -563,13 +493,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -581,15 +504,11 @@ func TestPublicIPSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ @@ -630,13 +549,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -648,15 +560,11 @@ func TestPublicIPSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ @@ -700,13 +608,6 @@ func TestPublicIPSpecs(t *testing.T) { azureCluster: &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Status: infrav1.AzureClusterStatus{ FailureDomains: map[string]clusterv1.FailureDomainSpec{ @@ -726,15 +627,11 @@ func TestPublicIPSpecs(t *testing.T) { }, }, AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: "centralIndia", + Location: "centralIndia", AdditionalTags: infrav1.Tags{ "Name": "my-publicip-ipv6", "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned", }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ @@ -803,35 +700,16 @@ func TestPublicIPSpecs(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.azureCluster.Name, Namespace: "default", }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, tc.azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: tc.azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } if got := clusterScope.PublicIPSpecs(); !reflect.DeepEqual(got, tc.expectedPublicIPSpec) { t.Errorf("PublicIPSpecs() diff between expected result and actual result (%v): %s", got, cmp.Diff(tc.expectedPublicIPSpec, got)) @@ -872,9 +750,6 @@ func TestRouteTableSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Vnet: infrav1.VnetSpec{ @@ -975,9 +850,6 @@ func TestNatGatewaySpecs(t *testing.T) { ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ @@ -1052,9 +924,6 @@ func TestNatGatewaySpecs(t *testing.T) { ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ @@ -1147,9 +1016,6 @@ func TestNatGatewaySpecs(t *testing.T) { ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ @@ -1354,9 +1220,6 @@ func TestNSGSpecs(t *testing.T) { Spec: infrav1.AzureClusterSpec{ AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Vnet: infrav1.VnetSpec{ @@ -1456,9 +1319,6 @@ func TestSubnetSpecs(t *testing.T) { ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Vnet: infrav1.VnetSpec{ @@ -1566,9 +1426,6 @@ func TestSubnetSpecs(t *testing.T) { ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Vnet: infrav1.VnetSpec{ @@ -1870,9 +1727,6 @@ func TestAzureBastionSpec(t *testing.T) { ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, NetworkSpec: infrav1.NetworkSpec{ Vnet: infrav1.VnetSpec{ @@ -1986,56 +1840,19 @@ func TestSubnet(t *testing.T) { for _, tc := range tests { t.Run(tc.clusterName, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ NetworkSpec: tc.azureClusterNetworkSpec, - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, - }, - } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, }, } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.Subnet(tc.subnetName) g.Expect(tc.expectSubnet).Should(Equal(got)) }) @@ -2095,56 +1912,19 @@ func TestControlPlaneRouteTable(t *testing.T) { for _, tc := range tests { t.Run(tc.clusterName, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ NetworkSpec: tc.azureClusterNetworkSpec, - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, - }, - } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, }, } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.ControlPlaneRouteTable() g.Expect(tc.expectRouteTable).Should(Equal(got)) }) @@ -2174,10 +1954,6 @@ func TestGetPrivateDNSZoneName(t *testing.T) { for _, tc := range tests { t.Run(tc.clusterName, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -2188,42 +1964,16 @@ func TestGetPrivateDNSZoneName(t *testing.T) { azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ NetworkSpec: tc.azureClusterNetworkSpec, - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, - }, - } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, }, } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.GetPrivateDNSZoneName() g.Expect(tc.expectPrivateDNSZoneName).Should(Equal(got)) }) @@ -2250,27 +2000,10 @@ func TestAPIServerLBPoolName(t *testing.T) { for _, tc := range tests { t.Run(tc.lbName, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ NetworkSpec: infrav1.NetworkSpec{ @@ -2278,33 +2011,13 @@ func TestAPIServerLBPoolName(t *testing.T) { Name: tc.lbName, }, }, - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, - }, - } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, }, } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) + } clusterScope.AzureCluster.SetBackendPoolNameDefault() - g.Expect(err).NotTo(HaveOccurred()) got := clusterScope.APIServerLBPoolName() g.Expect(tc.expectLBpoolName).Should(Equal(got)) }) @@ -2380,36 +2093,12 @@ func TestOutboundLBName(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ { @@ -2437,25 +2126,10 @@ func TestOutboundLBName(t *testing.T) { azureCluster.Default() - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) + } clusterScope.AzureCluster.SetBackendPoolNameDefault() - g.Expect(err).NotTo(HaveOccurred()) got := clusterScope.OutboundLBName(tc.role) g.Expect(tc.expected).Should(Equal(got)) }) @@ -2510,10 +2184,6 @@ func TestBackendPoolName(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -2525,21 +2195,8 @@ func TestBackendPoolName(t *testing.T) { azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: tc.clusterName, - }, - }, }, Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, NetworkSpec: infrav1.NetworkSpec{ Subnets: infrav1.Subnets{ { @@ -2564,15 +2221,6 @@ func TestBackendPoolName(t *testing.T) { azureCluster.Default() - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - if tc.customAPIServerBackendPoolName != "" { azureCluster.Spec.NetworkSpec.APIServerLB.BackendPool.Name = tc.customAPIServerBackendPoolName } @@ -2585,16 +2233,11 @@ func TestBackendPoolName(t *testing.T) { azureCluster.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name = tc.customControlPlaneBackendPoolName } - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: azureCluster, - Client: fakeClient, - }) + } clusterScope.AzureCluster.SetBackendPoolNameDefault() - g.Expect(err).NotTo(HaveOccurred()) got := clusterScope.LBSpecs() g.Expect(got).To(HaveLen(3)) @@ -2639,45 +2282,12 @@ func TestOutboundPoolName(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, - }, - Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, - }, - } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, }, } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} if tc.loadBalancerName != "" { azureCluster.Spec.NetworkSpec.NodeOutboundLB = &infrav1.LoadBalancerSpec{ @@ -2685,18 +2295,12 @@ func TestOutboundPoolName(t *testing.T) { } } - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} azureCluster.Default() - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) + } clusterScope.AzureCluster.SetBackendPoolNameDefault() - g.Expect(err).NotTo(HaveOccurred()) got := clusterScope.OutboundPoolName(infrav1.Node) g.Expect(tc.expectOutboundPoolName).Should(Equal(got)) }) @@ -2737,10 +2341,6 @@ func TestGenerateFQDN(t *testing.T) { for _, tc := range tests { t.Run(tc.clusterName, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -2751,43 +2351,19 @@ func TestGenerateFQDN(t *testing.T) { azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - Location: tc.location, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, + Location: tc.location, }, ResourceGroup: tc.resourceGroup, }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.GenerateFQDN(tc.ipName) g.Expect(got).Should(ContainSubstring(tc.clusterName)) g.Expect(got).Should(ContainSubstring(tc.location)) @@ -2836,56 +2412,21 @@ func TestAdditionalTags(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", AdditionalTags: tc.azureClusterAdditionalTags, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.AdditionalTags() g.Expect(tc.expectTags).Should(Equal(got)) }) @@ -2923,10 +2464,6 @@ func TestAPIServerPort(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -2940,41 +2477,13 @@ func TestAPIServerPort(t *testing.T) { azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, - }, - Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.APIServerPort() g.Expect(tc.expectAPIServerPort).Should(Equal(got)) }) @@ -3020,56 +2529,17 @@ func TestFailureDomains(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, - }, - Spec: infrav1.AzureClusterSpec{ - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, - }, }, Status: tc.azureClusterStatus, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + } got := clusterScope.FailureDomains() g.Expect(tc.expectFailureDomains).Should(ConsistOf(got)) }) @@ -3095,9 +2565,6 @@ func TestClusterScope_LBSpecs(t *testing.T) { }, SubscriptionID: "123", Location: "westus2", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, ResourceGroup: "my-rg", NetworkSpec: infrav1.NetworkSpec{ @@ -3269,9 +2736,6 @@ func TestClusterScope_LBSpecs(t *testing.T) { AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ SubscriptionID: "123", Location: "westus2", - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, ResourceGroup: "my-rg", NetworkSpec: infrav1.NetworkSpec{ @@ -3332,11 +2796,6 @@ func TestClusterScope_LBSpecs(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() - g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -3344,24 +2803,18 @@ func TestClusterScope_LBSpecs(t *testing.T) { Namespace: "default", }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{cluster, tc.azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: tc.azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + AzureClients: AzureClients{ + EnvironmentSettings: auth.EnvironmentSettings{ + Values: map[string]string{ + auth.SubscriptionID: tc.azureCluster.Spec.SubscriptionID, + }, + }, + }, + } if got := clusterScope.LBSpecs(); !reflect.DeepEqual(got, tc.want) { t.Errorf("LBSpecs() diff between expected result and actual result (%v): %s", got, cmp.Diff(tc.want, got)) } @@ -3395,61 +2848,25 @@ func TestExtendedLocationName(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", ExtendedLocation: &infrav1.ExtendedLocationSpec{ Name: tc.extendedLocation.Name, Type: tc.extendedLocation.Type, }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) + } - g.Expect(err).NotTo(HaveOccurred()) got := clusterScope.ExtendedLocationName() g.Expect(tc.extendedLocation.Name).Should(Equal(got)) }) @@ -3482,61 +2899,25 @@ func TestExtendedLocationType(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - - cluster := &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: tc.clusterName, - Namespace: "default", - }, - } azureCluster := &infrav1.AzureCluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.clusterName, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: "my-cluster", - }, - }, }, Spec: infrav1.AzureClusterSpec{ AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: "123", ExtendedLocation: &infrav1.ExtendedLocationSpec{ Name: tc.extendedLocation.Name, Type: tc.extendedLocation.Type, }, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - }, }, }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ - Cluster: cluster, + clusterScope := &ClusterScope{ AzureCluster: azureCluster, - Client: fakeClient, - }) + } - g.Expect(err).NotTo(HaveOccurred()) got := clusterScope.ExtendedLocationType() g.Expect(tc.extendedLocation.Type).Should(Equal(got)) }) @@ -3722,10 +3103,6 @@ func TestVNetPeerings(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) clusterName := "my-cluster" clusterNamespace := "default" @@ -3740,49 +3117,26 @@ func TestVNetPeerings(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: clusterName, Namespace: clusterNamespace, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "cluster.x-k8s.io/v1beta1", - Kind: "Cluster", - Name: clusterName, - }, - }, }, Spec: infrav1.AzureClusterSpec{ ResourceGroup: "rg1", - AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ - SubscriptionID: tc.subscriptionID, - IdentityRef: &corev1.ObjectReference{ - Kind: infrav1.AzureClusterIdentityKind, - Namespace: clusterNamespace, - }, - }, NetworkSpec: infrav1.NetworkSpec{ Vnet: tc.azureClusterVNetSpec, }, }, } - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: clusterNamespace, - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - - initObjects := []runtime.Object{cluster, azureCluster, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - clusterScope, err := NewClusterScope(context.TODO(), ClusterScopeParams{ + clusterScope := &ClusterScope{ Cluster: cluster, AzureCluster: azureCluster, - Client: fakeClient, - }) - g.Expect(err).NotTo(HaveOccurred()) + AzureClients: AzureClients{ + EnvironmentSettings: auth.EnvironmentSettings{ + Values: map[string]string{ + auth.SubscriptionID: tc.subscriptionID, + }, + }, + }, + } got := clusterScope.VnetPeeringSpecs() g.Expect(tc.want).To(Equal(got)) }) diff --git a/azure/scope/managedcontrolplane_test.go b/azure/scope/managedcontrolplane_test.go index a0c9a77c79f..b14a4168b20 100644 --- a/azure/scope/managedcontrolplane_test.go +++ b/azure/scope/managedcontrolplane_test.go @@ -42,20 +42,64 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" ) -func TestManagedControlPlaneScope_OutboundType(t *testing.T) { +func TestNewManagedControlPlaneScope(t *testing.T) { + g := NewWithT(t) + scheme := runtime.NewScheme() _ = expv1.AddToScheme(scheme) _ = infrav1.AddToScheme(scheme) _ = corev1.AddToScheme(scheme) + + input := ManagedControlPlaneScopeParams{ + Cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster1", + Namespace: "default", + }, + }, + ControlPlane: &infrav1.AzureManagedControlPlane{ + Spec: infrav1.AzureManagedControlPlaneSpec{ + AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ + SubscriptionID: "00000000-0000-0000-0000-000000000000", + IdentityRef: &corev1.ObjectReference{ + Name: "fake-identity", + Namespace: "default", + Kind: "AzureClusterIdentity", + }, + }, + }, + }, + } + fakeIdentity := &infrav1.AzureClusterIdentity{ + ObjectMeta: metav1.ObjectMeta{ + Name: "fake-identity", + Namespace: "default", + }, + Spec: infrav1.AzureClusterIdentitySpec{ + Type: infrav1.ServicePrincipal, + ClientID: fakeClientID, + TenantID: fakeTenantID, + }, + } + fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} + initObjects := []runtime.Object{input.ControlPlane, fakeIdentity, fakeSecret} + fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() + + input.Client = fakeClient + _, err := NewManagedControlPlaneScope(context.TODO(), input) + g.Expect(err).NotTo(HaveOccurred()) +} + +func TestManagedControlPlaneScope_OutboundType(t *testing.T) { explicitOutboundType := infrav1.ManagedControlPlaneOutboundTypeUserDefinedRouting cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected bool }{ { Name: "With Explicit OutboundType defined", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -65,12 +109,6 @@ func TestManagedControlPlaneScope_OutboundType(t *testing.T) { ControlPlane: &infrav1.AzureManagedControlPlane{ Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, OutboundType: &explicitOutboundType, }, }, @@ -80,7 +118,7 @@ func TestManagedControlPlaneScope_OutboundType(t *testing.T) { }, { Name: "Without OutboundType defined", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -89,14 +127,7 @@ func TestManagedControlPlaneScope_OutboundType(t *testing.T) { }, ControlPlane: &infrav1.AzureManagedControlPlane{ Spec: infrav1.AzureManagedControlPlaneSpec{ - AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - }, + AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{}, }, }, }, @@ -107,25 +138,8 @@ func TestManagedControlPlaneScope_OutboundType(t *testing.T) { c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - managedCluster := s.ManagedClusterSpec() + managedCluster := c.Scope.ManagedClusterSpec() result := managedCluster.(*managedclusters.ManagedClusterSpec).OutboundType == nil g.Expect(result).To(Equal(c.Expected)) }) @@ -133,20 +147,15 @@ func TestManagedControlPlaneScope_OutboundType(t *testing.T) { } func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected []azure.ASOResourceSpecGetter[genruntime.MetaObject] Err string }{ { Name: "Without Version", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -161,11 +170,6 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, }, }, }, @@ -190,7 +194,7 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { }, { Name: "With Version", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -206,11 +210,6 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ Version: "v1.22.0", SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, }, }, }, @@ -236,7 +235,7 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { }, { Name: "With bad version", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -250,13 +249,7 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - Version: "v1.20.1", - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, + Version: "v1.20.1", }, }, }, @@ -272,28 +265,10 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPools, err := s.GetAllAgentPoolSpecs() + agentPools, err := c.Scope.GetAllAgentPoolSpecs() if err != nil { g.Expect(err.Error()).To(Equal(c.Err)) } else { @@ -304,19 +279,14 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) { } func TestManagedControlPlaneScope_AddonProfiles(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected []managedclusters.AddonProfile }{ { Name: "Without add-ons", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -328,16 +298,7 @@ func TestManagedControlPlaneScope_AddonProfiles(t *testing.T) { Name: "cluster1", Namespace: "default", }, - Spec: infrav1.AzureManagedControlPlaneSpec{ - AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - }, - }, + Spec: infrav1.AzureManagedControlPlaneSpec{}, }, ManagedMachinePools: []ManagedMachinePool{ { @@ -350,7 +311,7 @@ func TestManagedControlPlaneScope_AddonProfiles(t *testing.T) { }, { Name: "With add-ons", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -364,12 +325,6 @@ func TestManagedControlPlaneScope_AddonProfiles(t *testing.T) { }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, AddonProfiles: []infrav1.AddonProfile{ {Name: "addon1", Config: nil, Enabled: false}, {Name: "addon2", Config: map[string]string{"k1": "v1", "k2": "v2"}, Enabled: true}, @@ -395,45 +350,22 @@ func TestManagedControlPlaneScope_AddonProfiles(t *testing.T) { c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - managedCluster := s.ManagedClusterSpec() + managedCluster := c.Scope.ManagedClusterSpec() g.Expect(managedCluster.(*managedclusters.ManagedClusterSpec).AddonProfiles).To(Equal(c.Expected)) }) } } func TestManagedControlPlaneScope_OSType(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected []azure.ASOResourceSpecGetter[genruntime.MetaObject] Err string }{ { Name: "with Linux and Windows pools", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -449,11 +381,6 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) { AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ Version: "v1.20.1", SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, }, }, }, @@ -506,7 +433,7 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) { }, { Name: "system pool required", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -522,11 +449,6 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) { AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ Version: "v1.20.1", SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, }, }, }, @@ -549,25 +471,7 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) { c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPools, err := s.GetAllAgentPoolSpecs() + agentPools, err := c.Scope.GetAllAgentPoolSpecs() if err != nil { g.Expect(err.Error()).To(Equal(c.Err)) } else { @@ -585,12 +489,12 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected bool }{ { Name: "no Cache value", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -624,12 +528,15 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { InfraMachinePool: getLinuxAzureMachinePool("pool1"), }, }, + cache: &ManagedControlPlaneCache{ + isVnetManaged: nil, + }, }, Expected: false, }, { Name: "with Cache value of true", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -663,7 +570,7 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { InfraMachinePool: getLinuxAzureMachinePool("pool1"), }, }, - Cache: &ManagedControlPlaneCache{ + cache: &ManagedControlPlaneCache{ isVnetManaged: ptr.To(true), }, }, @@ -671,7 +578,7 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { }, { Name: "with Cache value of false", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -705,7 +612,7 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { InfraMachinePool: getLinuxAzureMachinePool("pool1"), }, }, - Cache: &ManagedControlPlaneCache{ + cache: &ManagedControlPlaneCache{ isVnetManaged: ptr.To(false), }, }, @@ -717,43 +624,25 @@ func TestManagedControlPlaneScope_IsVnetManagedCache(t *testing.T) { c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} + initObjects := []runtime.Object{c.Scope.ControlPlane} fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - isVnetManaged := s.IsVnetManaged() + c.Scope.Client = fakeClient + isVnetManaged := c.Scope.IsVnetManaged() g.Expect(isVnetManaged).To(Equal(c.Expected)) }) } } func TestManagedControlPlaneScope_AADProfile(t *testing.T) { - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected *managedclusters.AADProfile }{ { Name: "Without AADProfile", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -765,16 +654,7 @@ func TestManagedControlPlaneScope_AADProfile(t *testing.T) { Name: "cluster1", Namespace: "default", }, - Spec: infrav1.AzureManagedControlPlaneSpec{ - AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - }, - }, + Spec: infrav1.AzureManagedControlPlaneSpec{}, }, ManagedMachinePools: []ManagedMachinePool{ { @@ -787,7 +667,7 @@ func TestManagedControlPlaneScope_AADProfile(t *testing.T) { }, { Name: "With AADProfile", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -801,12 +681,6 @@ func TestManagedControlPlaneScope_AADProfile(t *testing.T) { }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, AADProfile: &infrav1.AADProfile{ Managed: true, AdminGroupObjectIDs: []string{"00000000-0000-0000-0000-000000000000"}, @@ -829,28 +703,9 @@ func TestManagedControlPlaneScope_AADProfile(t *testing.T) { }, } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - managedClusterGetter := s.ManagedClusterSpec() + managedClusterGetter := c.Scope.ManagedClusterSpec() managedCluster, ok := managedClusterGetter.(*managedclusters.ManagedClusterSpec) g.Expect(ok).To(BeTrue()) g.Expect(managedCluster.AADProfile).To(Equal(c.Expected)) @@ -859,18 +714,14 @@ func TestManagedControlPlaneScope_AADProfile(t *testing.T) { } func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected *bool }{ { Name: "Without DisableLocalAccounts", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -882,16 +733,7 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { Name: "cluster1", Namespace: "default", }, - Spec: infrav1.AzureManagedControlPlaneSpec{ - AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - }, - }, + Spec: infrav1.AzureManagedControlPlaneSpec{}, }, ManagedMachinePools: []ManagedMachinePool{ { @@ -904,7 +746,7 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { }, { Name: "Without AAdProfile and With DisableLocalAccounts", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -918,13 +760,7 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - DisableLocalAccounts: ptr.To[bool](true), + DisableLocalAccounts: ptr.To(true), }, }, }, @@ -939,7 +775,7 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { }, { Name: "With AAdProfile and With DisableLocalAccounts", - Input: ManagedControlPlaneScopeParams{ + Scope: &ManagedControlPlaneScope{ Cluster: &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -953,17 +789,11 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, AADProfile: &infrav1.AADProfile{ Managed: true, AdminGroupObjectIDs: []string{"00000000-0000-0000-0000-000000000000"}, }, - DisableLocalAccounts: ptr.To[bool](true), + DisableLocalAccounts: ptr.To(true), }, }, }, @@ -974,32 +804,13 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { }, }, }, - Expected: ptr.To[bool](true), + Expected: ptr.To(true), }, } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - managedClusterGetter := s.ManagedClusterSpec() + managedClusterGetter := c.Scope.ManagedClusterSpec() managedCluster, ok := managedClusterGetter.(*managedclusters.ManagedClusterSpec) g.Expect(ok).To(BeTrue()) g.Expect(managedCluster.DisableLocalAccounts).To(Equal(c.Expected)) @@ -1008,262 +819,96 @@ func TestManagedControlPlaneScope_DisableLocalAccounts(t *testing.T) { } func TestIsAADEnabled(t *testing.T) { - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected bool }{ { Name: "AAD is not enabled", - Input: ManagedControlPlaneScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedControlPlaneScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - Spec: infrav1.AzureManagedControlPlaneSpec{ - AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - }, - }, - }, - ManagedMachinePools: []ManagedMachinePool{ - { - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + Spec: infrav1.AzureManagedControlPlaneSpec{}, }, }, Expected: false, }, { - Name: "AAdProfile and With DisableLocalAccounts", - Input: ManagedControlPlaneScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Name: "AAdProfile is enabled", + Scope: &ManagedControlPlaneScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, AADProfile: &infrav1.AADProfile{ - Managed: true, - AdminGroupObjectIDs: []string{"00000000-0000-0000-0000-000000000000"}, + Managed: true, }, - DisableLocalAccounts: ptr.To[bool](true), }, }, }, - ManagedMachinePools: []ManagedMachinePool{ - { - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, - }, }, Expected: true, }, } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - aadEnabled := s.IsAADEnabled() + aadEnabled := c.Scope.IsAADEnabled() g.Expect(aadEnabled).To(Equal(c.Expected)) }) } } func TestAreLocalAccountsDisabled(t *testing.T) { - scheme := runtime.NewScheme() - _ = infrav1.AddToScheme(scheme) - _ = corev1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedControlPlaneScopeParams + Scope *ManagedControlPlaneScope Expected bool }{ { Name: "DisbaleLocalAccount is not enabled", - Input: ManagedControlPlaneScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedControlPlaneScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - Spec: infrav1.AzureManagedControlPlaneSpec{ - AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, - }, - }, - }, - ManagedMachinePools: []ManagedMachinePool{ - { - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + Spec: infrav1.AzureManagedControlPlaneSpec{}, }, }, Expected: false, }, { Name: "With AAdProfile and Without DisableLocalAccounts", - Input: ManagedControlPlaneScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedControlPlaneScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, AADProfile: &infrav1.AADProfile{ - Managed: true, - AdminGroupObjectIDs: []string{"00000000-0000-0000-0000-000000000000"}, + Managed: true, }, }, }, }, - ManagedMachinePools: []ManagedMachinePool{ - { - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, - }, }, Expected: false, }, { Name: "With AAdProfile and With DisableLocalAccounts", - Input: ManagedControlPlaneScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedControlPlaneScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, Spec: infrav1.AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ - SubscriptionID: "00000000-0000-0000-0000-000000000000", - IdentityRef: &corev1.ObjectReference{ - Name: "fake-identity", - Namespace: "default", - Kind: "AzureClusterIdentity", - }, AADProfile: &infrav1.AADProfile{ - Managed: true, - AdminGroupObjectIDs: []string{"00000000-0000-0000-0000-000000000000"}, + Managed: true, }, - DisableLocalAccounts: ptr.To[bool](true), + DisableLocalAccounts: ptr.To(true), }, }, }, - ManagedMachinePools: []ManagedMachinePool{ - { - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, - }, }, Expected: true, }, } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { g := NewWithT(t) - fakeIdentity := &infrav1.AzureClusterIdentity{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fake-identity", - Namespace: "default", - }, - Spec: infrav1.AzureClusterIdentitySpec{ - Type: infrav1.ServicePrincipal, - ClientID: fakeClientID, - TenantID: fakeTenantID, - }, - } - fakeSecret := &corev1.Secret{Data: map[string][]byte{"clientSecret": []byte("fooSecret")}} - initObjects := []runtime.Object{c.Input.ControlPlane, fakeIdentity, fakeSecret} - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjects...).Build() - - c.Input.Client = fakeClient - s, err := NewManagedControlPlaneScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - localAccountsDisabled := s.AreLocalAccountsDisabled() + localAccountsDisabled := c.Scope.AreLocalAccountsDisabled() g.Expect(localAccountsDisabled).To(Equal(c.Expected)) }) } diff --git a/azure/scope/managedmachinepool_test.go b/azure/scope/managedmachinepool_test.go index f89527f2731..44ccba9aa6b 100644 --- a/azure/scope/managedmachinepool_test.go +++ b/azure/scope/managedmachinepool_test.go @@ -36,25 +36,51 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" ) -func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { +func TestNewManagedMachinePoolScope(t *testing.T) { scheme := runtime.NewScheme() _ = expv1.AddToScheme(scheme) _ = infrav1.AddToScheme(scheme) + input := ManagedMachinePoolScopeParams{ + Cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster1", + Namespace: "default", + }, + }, + ControlPlane: &infrav1.AzureManagedControlPlane{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster1", + Namespace: "default", + }, + Spec: infrav1.AzureManagedControlPlaneSpec{ + AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{ + SubscriptionID: "00000000-0000-0000-0000-000000000000", + }, + }, + }, + ManagedMachinePool: ManagedMachinePool{ + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), + }, + } + + g := NewWithT(t) + fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(input.MachinePool, input.InfraMachinePool, input.ControlPlane).Build() + input.Client = fakeClient + _, err := NewManagedMachinePoolScope(context.TODO(), input) + g.Expect(err).To(Succeed()) +} + +func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without Autoscaling", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -66,10 +92,8 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ @@ -84,13 +108,7 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { }, { Name: "With Autoscaling", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -102,10 +120,8 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithScaling("pool1", 2, 10), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithScaling("pool1", 2, 10), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -123,14 +139,8 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -139,24 +149,14 @@ func TestManagedMachinePoolScope_Autoscaling(t *testing.T) { } func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without node labels", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -168,10 +168,8 @@ func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool0", @@ -185,13 +183,7 @@ func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { }, { Name: "With node labels", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -203,12 +195,10 @@ func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithLabels("pool1", map[string]string{ - "custom": "default", - }), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithLabels("pool1", map[string]string{ + "custom": "default", + }), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -226,14 +216,8 @@ func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -242,24 +226,14 @@ func TestManagedMachinePoolScope_NodeLabels(t *testing.T) { } func TestManagedMachinePoolScope_AdditionalTags(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without additional tags", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -271,10 +245,8 @@ func TestManagedMachinePoolScope_AdditionalTags(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool0", @@ -288,13 +260,7 @@ func TestManagedMachinePoolScope_AdditionalTags(t *testing.T) { }, { Name: "With additional tags", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -306,12 +272,10 @@ func TestManagedMachinePoolScope_AdditionalTags(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithAdditionalTags("pool1", map[string]string{ - "environment": "production", - }), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithAdditionalTags("pool1", map[string]string{ + "environment": "production", + }), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -329,14 +293,8 @@ func TestManagedMachinePoolScope_AdditionalTags(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -345,24 +303,14 @@ func TestManagedMachinePoolScope_AdditionalTags(t *testing.T) { } func TestManagedMachinePoolScope_MaxPods(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without MaxPods", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -374,10 +322,8 @@ func TestManagedMachinePoolScope_MaxPods(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool0", @@ -391,13 +337,7 @@ func TestManagedMachinePoolScope_MaxPods(t *testing.T) { }, { Name: "With MaxPods", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -409,10 +349,8 @@ func TestManagedMachinePoolScope_MaxPods(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithMaxPods("pool1", 12), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithMaxPods("pool1", 12), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -428,14 +366,8 @@ func TestManagedMachinePoolScope_MaxPods(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -444,24 +376,14 @@ func TestManagedMachinePoolScope_MaxPods(t *testing.T) { } func TestManagedMachinePoolScope_Taints(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without taints", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -473,10 +395,8 @@ func TestManagedMachinePoolScope_Taints(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ @@ -491,13 +411,7 @@ func TestManagedMachinePoolScope_Taints(t *testing.T) { }, { Name: "With taints", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -509,16 +423,14 @@ func TestManagedMachinePoolScope_Taints(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithTaints("pool1", infrav1.Taints{ - infrav1.Taint{ - Key: "key1", - Value: "value1", - Effect: "NoSchedule", - }, - }), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithTaints("pool1", infrav1.Taints{ + infrav1.Taint{ + Key: "key1", + Value: "value1", + Effect: "NoSchedule", + }, + }), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -534,14 +446,8 @@ func TestManagedMachinePoolScope_Taints(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -550,24 +456,14 @@ func TestManagedMachinePoolScope_Taints(t *testing.T) { } func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without OsDiskType", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -579,10 +475,8 @@ func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool0", @@ -596,13 +490,7 @@ func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { }, { Name: "With OsDiskType", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -614,10 +502,8 @@ func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithOsDiskType("pool1", string(asocontainerservicev1.OSDiskType_Ephemeral)), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithOsDiskType("pool1", string(asocontainerservicev1.OSDiskType_Ephemeral)), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -633,14 +519,8 @@ func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -649,24 +529,14 @@ func TestManagedMachinePoolScope_OSDiskType(t *testing.T) { } func TestManagedMachinePoolScope_SubnetName(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without Vnet and SubnetName", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -678,10 +548,8 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool0", @@ -695,13 +563,7 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { }, { Name: "With Vnet and Without SubnetName", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -722,10 +584,8 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePool("pool1", infrav1.NodePoolModeUser), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePool("pool1", infrav1.NodePoolModeUser), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -739,13 +599,7 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { }, { Name: "With Vnet and With SubnetName", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -766,10 +620,8 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithSubnetName("pool1", ptr.To("my-subnet")), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithSubnetName("pool1", ptr.To("my-subnet")), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -784,15 +636,9 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - s.SetSubnetName() - agentPool := s.AgentPoolSpec() + c.Scope.SetSubnetName() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) } @@ -801,24 +647,14 @@ func TestManagedMachinePoolScope_SubnetName(t *testing.T) { } func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { - scheme := runtime.NewScheme() - _ = expv1.AddToScheme(scheme) - _ = infrav1.AddToScheme(scheme) - cases := []struct { Name string - Input ManagedMachinePoolScopeParams + Scope *ManagedMachinePoolScope Expected azure.ASOResourceSpecGetter[genruntime.MetaObject] }{ { Name: "Without KubeletDiskType", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -830,10 +666,8 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool0"), - InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), - }, + MachinePool: getMachinePool("pool0"), + InfraMachinePool: getAzureMachinePool("pool0", infrav1.NodePoolModeSystem), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool0", @@ -847,13 +681,7 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { }, { Name: "With KubeletDiskType", - Input: ManagedMachinePoolScopeParams{ - Cluster: &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - Namespace: "default", - }, - }, + Scope: &ManagedMachinePoolScope{ ControlPlane: &infrav1.AzureManagedControlPlane{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -865,10 +693,8 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { }, }, }, - ManagedMachinePool: ManagedMachinePool{ - MachinePool: getMachinePool("pool1"), - InfraMachinePool: getAzureMachinePoolWithKubeletDiskType("pool1", (*infrav1.KubeletDiskType)(ptr.To("Temporary"))), - }, + MachinePool: getMachinePool("pool1"), + InfraMachinePool: getAzureMachinePoolWithKubeletDiskType("pool1", (*infrav1.KubeletDiskType)(ptr.To("Temporary"))), }, Expected: &agentpools.AgentPoolSpec{ Name: "pool1", @@ -884,14 +710,8 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) { } for _, c := range cases { - c := c t.Run(c.Name, func(t *testing.T) { - g := NewWithT(t) - fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build() - c.Input.Client = fakeClient - s, err := NewManagedMachinePoolScope(context.TODO(), c.Input) - g.Expect(err).To(Succeed()) - agentPool := s.AgentPoolSpec() + agentPool := c.Scope.AgentPoolSpec() if !reflect.DeepEqual(c.Expected, agentPool) { t.Errorf("Got difference between expected result and result:\n%s", cmp.Diff(c.Expected, agentPool)) }