sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/managedagentpool_test.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package converters
    18  
    19  import (
    20  	"testing"
    21  
    22  	asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
    23  	asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
    24  	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
    25  	. "github.com/onsi/gomega"
    26  	"k8s.io/utils/ptr"
    27  )
    28  
    29  func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
    30  	cases := []struct {
    31  		name   string
    32  		pool   *asocontainerservicev1.ManagedClustersAgentPool
    33  		expect func(*GomegaWithT, asocontainerservicev1.ManagedClusterAgentPoolProfile)
    34  	}{
    35  		{
    36  			name: "Should set all values correctly",
    37  			pool: &asocontainerservicev1.ManagedClustersAgentPool{
    38  				Spec: asocontainerservicev1.ManagedClusters_AgentPool_Spec{
    39  					AzureName:           "agentpool1",
    40  					VmSize:              ptr.To("Standard_D2s_v3"),
    41  					OsType:              ptr.To(asocontainerservicev1.OSType_Linux),
    42  					OsDiskSizeGB:        ptr.To[asocontainerservicev1.ContainerServiceOSDisk](100),
    43  					Count:               ptr.To(2),
    44  					Type:                ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets),
    45  					OrchestratorVersion: ptr.To("1.22.6"),
    46  					VnetSubnetReference: &genruntime.ResourceReference{
    47  						ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
    48  					},
    49  					Mode:              ptr.To(asocontainerservicev1.AgentPoolMode_User),
    50  					EnableAutoScaling: ptr.To(true),
    51  					MaxCount:          ptr.To(5),
    52  					MinCount:          ptr.To(2),
    53  					NodeTaints:        []string{"key1=value1:NoSchedule"},
    54  					AvailabilityZones: []string{"zone1"},
    55  					MaxPods:           ptr.To(60),
    56  					OsDiskType:        ptr.To(asocontainerservicev1.OSDiskType_Managed),
    57  					NodeLabels: map[string]string{
    58  						"custom": "default",
    59  					},
    60  					Tags: map[string]string{
    61  						"custom": "default",
    62  					},
    63  					EnableFIPS:             ptr.To(true),
    64  					EnableEncryptionAtHost: ptr.To(true),
    65  				},
    66  			},
    67  
    68  			expect: func(g *GomegaWithT, result asocontainerservicev1.ManagedClusterAgentPoolProfile) {
    69  				g.Expect(result).To(Equal(asocontainerservicev1.ManagedClusterAgentPoolProfile{
    70  					Name:                ptr.To("agentpool1"),
    71  					VmSize:              ptr.To("Standard_D2s_v3"),
    72  					OsType:              ptr.To(asocontainerservicev1.OSType_Linux),
    73  					OsDiskSizeGB:        ptr.To[asocontainerservicev1.ContainerServiceOSDisk](100),
    74  					Count:               ptr.To(2),
    75  					Type:                ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets),
    76  					OrchestratorVersion: ptr.To("1.22.6"),
    77  					VnetSubnetReference: &genruntime.ResourceReference{
    78  						ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
    79  					},
    80  					Mode:              ptr.To(asocontainerservicev1.AgentPoolMode_User),
    81  					EnableAutoScaling: ptr.To(true),
    82  					MaxCount:          ptr.To(5),
    83  					MinCount:          ptr.To(2),
    84  					NodeTaints:        []string{"key1=value1:NoSchedule"},
    85  					AvailabilityZones: []string{"zone1"},
    86  					MaxPods:           ptr.To(60),
    87  					OsDiskType:        ptr.To(asocontainerservicev1.OSDiskType_Managed),
    88  					NodeLabels: map[string]string{
    89  						"custom": "default",
    90  					},
    91  					Tags: map[string]string{
    92  						"custom": "default",
    93  					},
    94  					EnableFIPS:             ptr.To(true),
    95  					EnableEncryptionAtHost: ptr.To(true),
    96  				}))
    97  			},
    98  		},
    99  	}
   100  
   101  	for _, c := range cases {
   102  		c := c
   103  		t.Run(c.name, func(t *testing.T) {
   104  			t.Parallel()
   105  			g := NewGomegaWithT(t)
   106  			result := AgentPoolToManagedClusterAgentPoolProfile(c.pool)
   107  			c.expect(g, result)
   108  		})
   109  	}
   110  }
   111  
   112  func Test_AgentPoolToManagedClusterAgentPoolPreviewProfile(t *testing.T) {
   113  	cases := []struct {
   114  		name   string
   115  		pool   *asocontainerservicev1preview.ManagedClustersAgentPool
   116  		expect func(*GomegaWithT, asocontainerservicev1preview.ManagedClusterAgentPoolProfile)
   117  	}{
   118  		{
   119  			name: "Should set all values correctly",
   120  			pool: &asocontainerservicev1preview.ManagedClustersAgentPool{
   121  				Spec: asocontainerservicev1preview.ManagedClusters_AgentPool_Spec{
   122  					AzureName:           "agentpool1",
   123  					VmSize:              ptr.To("Standard_D2s_v3"),
   124  					OsType:              ptr.To(asocontainerservicev1preview.OSType_Linux),
   125  					OsDiskSizeGB:        ptr.To[asocontainerservicev1preview.ContainerServiceOSDisk](100),
   126  					Count:               ptr.To(2),
   127  					Type:                ptr.To(asocontainerservicev1preview.AgentPoolType_VirtualMachineScaleSets),
   128  					OrchestratorVersion: ptr.To("1.22.6"),
   129  					VnetSubnetReference: &genruntime.ResourceReference{
   130  						ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
   131  					},
   132  					Mode:              ptr.To(asocontainerservicev1preview.AgentPoolMode_User),
   133  					EnableAutoScaling: ptr.To(true),
   134  					MaxCount:          ptr.To(5),
   135  					MinCount:          ptr.To(2),
   136  					NodeTaints:        []string{"key1=value1:NoSchedule"},
   137  					AvailabilityZones: []string{"zone1"},
   138  					MaxPods:           ptr.To(60),
   139  					OsDiskType:        ptr.To(asocontainerservicev1preview.OSDiskType_Managed),
   140  					NodeLabels: map[string]string{
   141  						"custom": "default",
   142  					},
   143  					Tags: map[string]string{
   144  						"custom": "default",
   145  					},
   146  					EnableFIPS:             ptr.To(true),
   147  					EnableEncryptionAtHost: ptr.To(true),
   148  				},
   149  			},
   150  
   151  			expect: func(g *GomegaWithT, result asocontainerservicev1preview.ManagedClusterAgentPoolProfile) {
   152  				g.Expect(result).To(Equal(asocontainerservicev1preview.ManagedClusterAgentPoolProfile{
   153  					Name:                ptr.To("agentpool1"),
   154  					VmSize:              ptr.To("Standard_D2s_v3"),
   155  					OsType:              ptr.To(asocontainerservicev1preview.OSType_Linux),
   156  					OsDiskSizeGB:        ptr.To[asocontainerservicev1preview.ContainerServiceOSDisk](100),
   157  					Count:               ptr.To(2),
   158  					Type:                ptr.To(asocontainerservicev1preview.AgentPoolType_VirtualMachineScaleSets),
   159  					OrchestratorVersion: ptr.To("1.22.6"),
   160  					VnetSubnetReference: &genruntime.ResourceReference{
   161  						ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
   162  					},
   163  					Mode:              ptr.To(asocontainerservicev1preview.AgentPoolMode_User),
   164  					EnableAutoScaling: ptr.To(true),
   165  					MaxCount:          ptr.To(5),
   166  					MinCount:          ptr.To(2),
   167  					NodeTaints:        []string{"key1=value1:NoSchedule"},
   168  					AvailabilityZones: []string{"zone1"},
   169  					MaxPods:           ptr.To(60),
   170  					OsDiskType:        ptr.To(asocontainerservicev1preview.OSDiskType_Managed),
   171  					NodeLabels: map[string]string{
   172  						"custom": "default",
   173  					},
   174  					Tags: map[string]string{
   175  						"custom": "default",
   176  					},
   177  					EnableFIPS:             ptr.To(true),
   178  					EnableEncryptionAtHost: ptr.To(true),
   179  				}))
   180  			},
   181  		},
   182  	}
   183  
   184  	for _, c := range cases {
   185  		c := c
   186  		t.Run(c.name, func(t *testing.T) {
   187  			t.Parallel()
   188  			g := NewGomegaWithT(t)
   189  			result := AgentPoolToManagedClusterAgentPoolPreviewProfile(c.pool)
   190  			c.expect(g, result)
   191  		})
   192  	}
   193  }