@@ -1968,6 +1968,92 @@ var _ = Describe("machine-update", Ordered, Label("machine", "machine-update"),
19681968 Expect (err ).NotTo (HaveOccurred ())
19691969 }),
19701970 ),
1971+ Path (
1972+ Call ("machine firewall update applied when FirewallID is zero but FirewallRef is set" , func (ctx context.Context , mck Mock ) {
1973+ mck .LinodeClient .EXPECT ().GetInstance (ctx , 11111 ).Return (
1974+ & linodego.Instance {
1975+ ID : 11111 ,
1976+ IPv4 : []* net.IP {ptr .To (net .IPv4 (192 , 168 , 0 , 2 ))},
1977+ IPv6 : "fd00::" ,
1978+ Tags : []string {"test-cluster-2" },
1979+ Status : linodego .InstanceRunning ,
1980+ Updated : util .Pointer (time .Now ()),
1981+ }, nil )
1982+ mck .LinodeClient .EXPECT ().UpdateInstance (ctx , 11111 , gomock .Any ()).Return (
1983+ & linodego.Instance {
1984+ ID : 11111 ,
1985+ IPv4 : []* net.IP {ptr .To (net .IPv4 (192 , 168 , 0 , 2 ))},
1986+ IPv6 : "fd00::" ,
1987+ Tags : []string {"test-cluster-2" , "test-tag" },
1988+ Status : linodego .InstanceRunning ,
1989+ Updated : util .Pointer (time .Now ()),
1990+ }, nil )
1991+ mck .LinodeClient .EXPECT ().ListInstanceFirewalls (ctx , 11111 , nil ).Return (
1992+ []linodego.Firewall {}, nil )
1993+ mck .LinodeClient .EXPECT ().UpdateInstanceFirewalls (ctx , 11111 , linodego.InstanceFirewallUpdateOptions {
1994+ FirewallIDs : []int {20 }, // Update to firewall ID 20 from firewall ref
1995+ }).Return (nil , nil )
1996+ }),
1997+ Result ("machine firewall updates to FirewallID from FirewallRef" , func (ctx context.Context , mck Mock ) {
1998+ linodeFirewall := & infrav1alpha2.LinodeFirewall {
1999+ ObjectMeta : metav1.ObjectMeta {
2000+ Name : "test-firewall-ref" ,
2001+ Namespace : namespace ,
2002+ },
2003+ Spec : infrav1alpha2.LinodeFirewallSpec {
2004+ FirewallID : ptr .To (20 ),
2005+ Enabled : true ,
2006+ },
2007+ }
2008+ Expect (k8sClient .Create (ctx , linodeFirewall )).To (Succeed ())
2009+ linodeFirewall .Status .Ready = true
2010+ Expect (k8sClient .Status ().Update (ctx , linodeFirewall )).To (Succeed ())
2011+
2012+ linodeMachine .Spec .FirewallID = 0 // No firewall ID explicitly set
2013+ linodeMachine .Spec .FirewallRef = & corev1.ObjectReference {
2014+ Name : "test-firewall-ref" ,
2015+ Namespace : namespace ,
2016+ }
2017+ _ , err = reconciler .reconcile (ctx , logr.Logger {}, mScope )
2018+ Expect (err ).NotTo (HaveOccurred ())
2019+ Expect (k8sClient .Delete (ctx , linodeFirewall )).To (Succeed ())
2020+ }),
2021+ ),
2022+ Path (
2023+ Call ("machine firewall fails to get FirewallID from FirewallRef" , func (ctx context.Context , mck Mock ) {
2024+ mck .LinodeClient .EXPECT ().GetInstance (ctx , 11111 ).Return (
2025+ & linodego.Instance {
2026+ ID : 11111 ,
2027+ IPv4 : []* net.IP {ptr .To (net .IPv4 (192 , 168 , 0 , 2 ))},
2028+ IPv6 : "fd00::" ,
2029+ Tags : []string {"test-cluster-2" },
2030+ Status : linodego .InstanceRunning ,
2031+ Updated : util .Pointer (time .Now ()),
2032+ }, nil )
2033+ mck .LinodeClient .EXPECT ().UpdateInstance (ctx , 11111 , gomock .Any ()).Return (
2034+ & linodego.Instance {
2035+ ID : 11111 ,
2036+ IPv4 : []* net.IP {ptr .To (net .IPv4 (192 , 168 , 0 , 2 ))},
2037+ IPv6 : "fd00::" ,
2038+ Tags : []string {"test-cluster-2" , "test-tag" },
2039+ Status : linodego .InstanceRunning ,
2040+ Updated : util .Pointer (time .Now ()),
2041+ }, nil )
2042+ mck .LinodeClient .EXPECT ().ListInstanceFirewalls (ctx , 11111 , nil ).Return (
2043+ []linodego.Firewall {}, nil )
2044+ }),
2045+ Result ("machine firewall update error requeues" , func (ctx context.Context , mck Mock ) {
2046+ linodeMachine .Spec .FirewallID = 0 // No firewall ID explicitly set
2047+ linodeMachine .Spec .FirewallRef = & corev1.ObjectReference {
2048+ Name : "test-firewall-ref" ,
2049+ Namespace : namespace ,
2050+ } // this firewall does not exist
2051+ res , err := reconciler .reconcile (ctx , mck .Logger (), mScope )
2052+ Expect (err ).NotTo (HaveOccurred ())
2053+ Expect (res .RequeueAfter ).To (Equal (rutil .DefaultMachineControllerRetryDelay ))
2054+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to fetch LinodeFirewall" ))
2055+ }),
2056+ ),
19712057 OneOf (
19722058 Path (
19732059 Call ("machine firewall list fails" , func (ctx context.Context , mck Mock ) {
0 commit comments