@@ -895,6 +895,156 @@ func TestService_Reconcile(t *testing.T) {
895895 g .Expect (err ).To (gomega .MatchError ("vm memory should be bigger or equal to at least 2Gi" ))
896896 },
897897 },
898+ {
899+ Name : "WithTerminateNotificationTimeout" ,
900+ SpecFactory : func (g * gomega.GomegaWithT , scope * scope.ClusterScope , mpScope * scope.MachinePoolScope ) interface {} {
901+ return & Spec {
902+ Name : mpScope .Name (),
903+ ResourceGroup : scope .AzureCluster .Spec .ResourceGroup ,
904+ Location : scope .AzureCluster .Spec .Location ,
905+ ClusterName : scope .Cluster .Name ,
906+ SubnetID : scope .AzureCluster .Spec .NetworkSpec .Subnets [0 ].ID ,
907+ PublicLoadBalancerName : scope .Cluster .Name ,
908+ MachinePoolName : mpScope .Name (),
909+ Sku : "skuName" ,
910+ Capacity : 2 ,
911+ SSHKeyData : "sshKeyData" ,
912+ OSDisk : infrav1.OSDisk {
913+ OSType : "Linux" ,
914+ DiskSizeGB : 120 ,
915+ ManagedDisk : infrav1.ManagedDisk {
916+ StorageAccountType : "accountType" ,
917+ },
918+ },
919+ Image : & infrav1.Image {
920+ ID : to .StringPtr ("image" ),
921+ },
922+ CustomData : "customData" ,
923+ TerminateNotificationTimeout : to .IntPtr (7 ),
924+ }
925+ },
926+ Setup : func (ctx context.Context , g * gomega.GomegaWithT , svc * Service , scope * scope.ClusterScope , mpScope * scope.MachinePoolScope , spec * Spec ) * gomock.Controller {
927+ mockCtrl := gomock .NewController (t )
928+ vmssMock := mock_scalesets .NewMockClient (mockCtrl )
929+ svc .Client = vmssMock
930+ skus := []compute.ResourceSku {
931+ {
932+ Name : to .StringPtr ("skuName" ),
933+ Kind : to .StringPtr (string (resourceskus .VirtualMachines )),
934+ Locations : & []string {
935+ "fake-location" ,
936+ },
937+ LocationInfo : & []compute.ResourceSkuLocationInfo {
938+ {
939+ Location : to .StringPtr ("fake-location" ),
940+ Zones : & []string {"1" },
941+ },
942+ },
943+ Capabilities : & []compute.ResourceSkuCapabilities {
944+ {
945+ Name : to .StringPtr (resourceskus .VCPUs ),
946+ Value : to .StringPtr ("4" ),
947+ },
948+ {
949+ Name : to .StringPtr (resourceskus .MemoryGB ),
950+ Value : to .StringPtr ("8" ),
951+ },
952+ {
953+ Name : to .StringPtr (resourceskus .AcceleratedNetworking ),
954+ Value : to .StringPtr (string (resourceskus .CapabilitySupported )),
955+ },
956+ },
957+ },
958+ }
959+ resourceSkusCache := resourceskus .NewStaticCache (skus )
960+
961+ svc .ResourceSKUCache = resourceSkusCache
962+ lbMock := mock_loadbalancers .NewMockClient (mockCtrl )
963+ svc .LoadBalancersClient = lbMock
964+
965+ storageProfile , err := svc .generateStorageProfile (ctx , * spec , resourceskus .SKU (skus [0 ]))
966+ g .Expect (err ).ToNot (gomega .HaveOccurred ())
967+
968+ vmss := compute.VirtualMachineScaleSet {
969+ Location : to .StringPtr (scope .Location ()),
970+ Tags : map [string ]* string {
971+ "Name" : to .StringPtr ("capz-mp-0" ),
972+ "kubernetes.io_cluster_capz-mp-0" : to .StringPtr ("owned" ),
973+ "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster" : to .StringPtr ("owned" ),
974+ "sigs.k8s.io_cluster-api-provider-azure_role" : to .StringPtr ("node" ),
975+ },
976+ Sku : & compute.Sku {
977+ Name : to .StringPtr (spec .Sku ),
978+ Tier : to .StringPtr ("Standard" ),
979+ Capacity : to .Int64Ptr (spec .Capacity ),
980+ },
981+ VirtualMachineScaleSetProperties : & compute.VirtualMachineScaleSetProperties {
982+ UpgradePolicy : & compute.UpgradePolicy {
983+ Mode : compute .UpgradeModeRolling ,
984+ },
985+ VirtualMachineProfile : & compute.VirtualMachineScaleSetVMProfile {
986+ OsProfile : & compute.VirtualMachineScaleSetOSProfile {
987+ ComputerNamePrefix : to .StringPtr (spec .Name ),
988+ AdminUsername : to .StringPtr (azure .DefaultUserName ),
989+ CustomData : to .StringPtr (spec .CustomData ),
990+ LinuxConfiguration : & compute.LinuxConfiguration {
991+ SSH : & compute.SSHConfiguration {
992+ PublicKeys : & []compute.SSHPublicKey {
993+ {
994+ Path : to .StringPtr (fmt .Sprintf ("/home/%s/.ssh/authorized_keys" , azure .DefaultUserName )),
995+ KeyData : to .StringPtr (spec .SSHKeyData ),
996+ },
997+ },
998+ },
999+ DisablePasswordAuthentication : to .BoolPtr (true ),
1000+ },
1001+ },
1002+ StorageProfile : storageProfile ,
1003+ NetworkProfile : & compute.VirtualMachineScaleSetNetworkProfile {
1004+ NetworkInterfaceConfigurations : & []compute.VirtualMachineScaleSetNetworkConfiguration {
1005+ {
1006+ Name : to .StringPtr (spec .Name + "-netconfig" ),
1007+ VirtualMachineScaleSetNetworkConfigurationProperties : & compute.VirtualMachineScaleSetNetworkConfigurationProperties {
1008+ Primary : to .BoolPtr (true ),
1009+ EnableAcceleratedNetworking : to .BoolPtr (true ),
1010+ EnableIPForwarding : to .BoolPtr (true ),
1011+ IPConfigurations : & []compute.VirtualMachineScaleSetIPConfiguration {
1012+ {
1013+ Name : to .StringPtr (spec .Name + "-ipconfig" ),
1014+ VirtualMachineScaleSetIPConfigurationProperties : & compute.VirtualMachineScaleSetIPConfigurationProperties {
1015+ Subnet : & compute.APIEntityReference {
1016+ ID : to .StringPtr (scope .AzureCluster .Spec .NetworkSpec .Subnets [0 ].ID ),
1017+ },
1018+ Primary : to .BoolPtr (true ),
1019+ PrivateIPAddressVersion : compute .IPv4 ,
1020+ LoadBalancerBackendAddressPools : & []compute.SubResource {{ID : to .StringPtr ("cluster-name-outboundBackendPool" )}},
1021+ },
1022+ },
1023+ },
1024+ },
1025+ },
1026+ },
1027+ },
1028+ ScheduledEventsProfile : & compute.ScheduledEventsProfile {
1029+ TerminateNotificationProfile : & compute.TerminateNotificationProfile {
1030+ Enable : to .BoolPtr (true ),
1031+ NotBeforeTimeout : to .StringPtr ("PT7M" ),
1032+ },
1033+ },
1034+ },
1035+ },
1036+ }
1037+
1038+ lbMock .EXPECT ().Get (gomock .Any (), scope .AzureCluster .Spec .ResourceGroup , spec .ClusterName ).Return (getFakeNodeOutboundLoadBalancer (), nil )
1039+ vmssMock .EXPECT ().Get (gomock .Any (), scope .AzureCluster .Spec .ResourceGroup , spec .Name ).Return (compute.VirtualMachineScaleSet {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" ))
1040+ vmssMock .EXPECT ().CreateOrUpdate (gomock .Any (), scope .AzureCluster .Spec .ResourceGroup , spec .Name , gomockinternal .DiffEq (vmss )).Return (nil )
1041+
1042+ return mockCtrl
1043+ },
1044+ Expect : func (ctx context.Context , g * gomega.GomegaWithT , err error ) {
1045+ g .Expect (err ).ToNot (gomega .HaveOccurred ())
1046+ },
1047+ },
8981048 }
8991049
9001050 for _ , c := range cases {
0 commit comments