@@ -669,6 +669,153 @@ func TestParameters(t *testing.T) {
669669 },
670670 expectedError : "" ,
671671 },
672+ {
673+ name : "recreate parameters for network interface when Azure provisioning state is Failed" ,
674+ spec : func () * NICSpec {
675+ s := fakeStaticPrivateIPNICSpec // value‑copy
676+ return & s // pointer to the copy, not the global
677+ }(),
678+ existing : armnetwork.Interface {
679+ ID : ptr .To ("" ),
680+ Name : ptr .To ("my-net-interface" ),
681+ Location : ptr .To ("fake-location" ),
682+ Type : ptr .To ("Microsoft.Network/networkInterfaces" ),
683+ Properties : & armnetwork.InterfacePropertiesFormat {
684+ ProvisioningState : ptr .To (armnetwork .ProvisioningStateFailed ),
685+ },
686+ },
687+ expect : func (g * WithT , result interface {}) {
688+ g .Expect (result ).To (BeAssignableToTypeOf (armnetwork.Interface {}))
689+ g .Expect (result .(armnetwork.Interface )).To (Equal (armnetwork.Interface {
690+ Tags : map [string ]* string {
691+ "Name" : ptr .To ("my-net-interface" ),
692+ "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : ptr .To ("owned" ),
693+ },
694+ Location : ptr .To ("fake-location" ),
695+ Properties : & armnetwork.InterfacePropertiesFormat {
696+ Primary : nil ,
697+ EnableAcceleratedNetworking : ptr .To (true ),
698+ EnableIPForwarding : ptr .To (false ),
699+ DNSSettings : & armnetwork.InterfaceDNSSettings {},
700+ IPConfigurations : []* armnetwork.InterfaceIPConfiguration {
701+ {
702+ Name : ptr .To ("pipConfig" ),
703+ Properties : & armnetwork.InterfaceIPConfigurationPropertiesFormat {
704+ Primary : ptr .To (true ),
705+ LoadBalancerBackendAddressPools : []* armnetwork.BackendAddressPool {{ID : ptr .To ("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool" )}},
706+ PrivateIPAllocationMethod : ptr .To (armnetwork .IPAllocationMethodStatic ),
707+ PrivateIPAddress : ptr .To ("fake.static.ip" ),
708+ Subnet : & armnetwork.Subnet {ID : ptr .To ("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet" )},
709+ },
710+ },
711+ },
712+ },
713+ }))
714+ },
715+ expectedError : "" ,
716+ },
717+ {
718+ name : "do not recreate parameters for network interface when Azure provisioning state is Deleting" ,
719+ spec : func () * NICSpec {
720+ s := fakeStaticPrivateIPNICSpec // value‑copy
721+ return & s // pointer to the copy, not the global
722+ }(),
723+ existing : armnetwork.Interface {
724+ ID : ptr .To ("" ),
725+ Name : ptr .To ("my-net-interface" ),
726+ Location : ptr .To ("fake-location" ),
727+ Type : ptr .To ("Microsoft.Network/networkInterfaces" ),
728+ Properties : & armnetwork.InterfacePropertiesFormat {
729+ ProvisioningState : ptr .To (armnetwork .ProvisioningStateDeleting ),
730+ },
731+ },
732+ expect : func (g * WithT , result interface {}) {
733+ g .Expect (result ).To (BeNil ())
734+ },
735+ expectedError : "" ,
736+ },
737+ {
738+ name : "do not recreate parameters for network interface when Azure provisioning state is Succeeded" ,
739+ spec : func () * NICSpec {
740+ s := fakeStaticPrivateIPNICSpec // value‑copy
741+ return & s // pointer to the copy, not the global
742+ }(),
743+ existing : armnetwork.Interface {
744+ ID : ptr .To ("" ),
745+ Name : ptr .To ("my-net-interface" ),
746+ Location : ptr .To ("fake-location" ),
747+ Type : ptr .To ("Microsoft.Network/networkInterfaces" ),
748+ Properties : & armnetwork.InterfacePropertiesFormat {
749+ ProvisioningState : ptr .To (armnetwork .ProvisioningStateSucceeded ),
750+ },
751+ },
752+ expect : func (g * WithT , result interface {}) {
753+ g .Expect (result ).To (BeNil ())
754+ },
755+ expectedError : "" ,
756+ },
757+ {
758+ name : "do not recreate parameters for network interface when Azure provisioning state is Updating" ,
759+ spec : func () * NICSpec {
760+ s := fakeStaticPrivateIPNICSpec // value‑copy
761+ return & s // pointer to the copy, not the global
762+ }(),
763+ existing : armnetwork.Interface {
764+ ID : ptr .To ("" ),
765+ Name : ptr .To ("my-net-interface" ),
766+ Location : ptr .To ("fake-location" ),
767+ Type : ptr .To ("Microsoft.Network/networkInterfaces" ),
768+ Properties : & armnetwork.InterfacePropertiesFormat {
769+ ProvisioningState : ptr .To (armnetwork .ProvisioningStateUpdating ),
770+ },
771+ },
772+ expect : func (g * WithT , result interface {}) {
773+ g .Expect (result ).To (BeNil ())
774+ },
775+ expectedError : "" ,
776+ },
777+ {
778+ name : "recreate parameters for network interface when Azure provisioning state nil" ,
779+ spec : func () * NICSpec {
780+ s := fakeStaticPrivateIPNICSpec // value‑copy
781+ return & s // pointer to the copy, not the global
782+ }(),
783+ existing : armnetwork.Interface {
784+ ID : ptr .To ("" ),
785+ Name : ptr .To ("my-net-interface" ),
786+ Location : ptr .To ("fake-location" ),
787+ Type : ptr .To ("Microsoft.Network/networkInterfaces" ),
788+ },
789+ expect : func (g * WithT , result interface {}) {
790+ g .Expect (result ).To (BeAssignableToTypeOf (armnetwork.Interface {}))
791+ g .Expect (result .(armnetwork.Interface )).To (Equal (armnetwork.Interface {
792+ Tags : map [string ]* string {
793+ "Name" : ptr .To ("my-net-interface" ),
794+ "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : ptr .To ("owned" ),
795+ },
796+ Location : ptr .To ("fake-location" ),
797+ Properties : & armnetwork.InterfacePropertiesFormat {
798+ Primary : nil ,
799+ EnableAcceleratedNetworking : ptr .To (true ),
800+ EnableIPForwarding : ptr .To (false ),
801+ DNSSettings : & armnetwork.InterfaceDNSSettings {},
802+ IPConfigurations : []* armnetwork.InterfaceIPConfiguration {
803+ {
804+ Name : ptr .To ("pipConfig" ),
805+ Properties : & armnetwork.InterfaceIPConfigurationPropertiesFormat {
806+ Primary : ptr .To (true ),
807+ LoadBalancerBackendAddressPools : []* armnetwork.BackendAddressPool {{ID : ptr .To ("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool" )}},
808+ PrivateIPAllocationMethod : ptr .To (armnetwork .IPAllocationMethodStatic ),
809+ PrivateIPAddress : ptr .To ("fake.static.ip" ),
810+ Subnet : & armnetwork.Subnet {ID : ptr .To ("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet" )},
811+ },
812+ },
813+ },
814+ },
815+ }))
816+ },
817+ expectedError : "" ,
818+ },
672819 }
673820 format .MaxLength = 10000
674821 for _ , tc := range testcases {
0 commit comments