@@ -1902,6 +1902,104 @@ func TestFirewallNeedsUpdate(t *testing.T) {
19021902 }
19031903}
19041904
1905+ func TestDisabledFirewallOperations (t * testing.T ) {
1906+ vals := DefaultTestClusterValues ()
1907+ vals .FirewallRulesManagement = firewallRulesManagementDisabled
1908+ gce , err := fakeGCECloud (vals )
1909+ require .NoError (t , err )
1910+
1911+ fw , err := gce .GetFirewall (MakeFirewallName ("test" ))
1912+ assert .NoError (t , err )
1913+ assert .Nil (t , fw )
1914+
1915+ ipnet , err := utilnet .ParseIPNets ("0.0.0.0/0" )
1916+ require .NoError (t , err )
1917+
1918+ ports := []v1.ServicePort {
1919+ {Name : "port1" , Protocol : v1 .ProtocolTCP , Port : int32 (80 ), TargetPort : intstr .FromInt (80 )},
1920+ {Name : "port2" , Protocol : v1 .ProtocolTCP , Port : int32 (81 ), TargetPort : intstr .FromInt (81 )},
1921+ {Name : "port3" , Protocol : v1 .ProtocolTCP , Port : int32 (82 ), TargetPort : intstr .FromInt (82 )},
1922+ {Name : "port4" , Protocol : v1 .ProtocolTCP , Port : int32 (84 ), TargetPort : intstr .FromInt (84 )},
1923+ {Name : "port5" , Protocol : v1 .ProtocolTCP , Port : int32 (85 ), TargetPort : intstr .FromInt (85 )},
1924+ {Name : "port6" , Protocol : v1 .ProtocolTCP , Port : int32 (86 ), TargetPort : intstr .FromInt (86 )},
1925+ {Name : "port7" , Protocol : v1 .ProtocolTCP , Port : int32 (88 ), TargetPort : intstr .FromInt (87 )},
1926+ }
1927+
1928+ firewall , err := gce .firewallObject (MakeFirewallName ("test" ), "Test Description" , "0.0.0.0/0" , ipnet , ports , nil )
1929+
1930+ err = gce .CreateFirewall (firewall )
1931+ assert .NoError (t , err )
1932+
1933+ err = gce .UpdateFirewall (firewall )
1934+ assert .NoError (t , err )
1935+
1936+ err = gce .PatchFirewall (firewall )
1937+ assert .NoError (t , err )
1938+
1939+ err = gce .DeleteFirewall (MakeFirewallName ("test" ))
1940+ assert .NoError (t , err )
1941+ }
1942+
1943+ func TestDisabledFirewallNeedsUpdate (t * testing.T ) {
1944+ t .Parallel ()
1945+
1946+ vals := DefaultTestClusterValues ()
1947+ vals .FirewallRulesManagement = firewallRulesManagementDisabled
1948+ gce , err := fakeGCECloud (vals )
1949+ require .NoError (t , err )
1950+ svc := fakeLoadbalancerService ("" )
1951+
1952+ svc , err = gce .client .CoreV1 ().Services (svc .Namespace ).Create (context .TODO (), svc , metav1.CreateOptions {})
1953+ require .NoError (t , err )
1954+
1955+ svc .Spec .Ports = []v1.ServicePort {
1956+ {Name : "port1" , Protocol : v1 .ProtocolTCP , Port : int32 (80 ), TargetPort : intstr .FromInt (80 )},
1957+ {Name : "port2" , Protocol : v1 .ProtocolTCP , Port : int32 (81 ), TargetPort : intstr .FromInt (81 )},
1958+ {Name : "port3" , Protocol : v1 .ProtocolTCP , Port : int32 (82 ), TargetPort : intstr .FromInt (82 )},
1959+ {Name : "port4" , Protocol : v1 .ProtocolTCP , Port : int32 (84 ), TargetPort : intstr .FromInt (84 )},
1960+ {Name : "port5" , Protocol : v1 .ProtocolTCP , Port : int32 (85 ), TargetPort : intstr .FromInt (85 )},
1961+ {Name : "port6" , Protocol : v1 .ProtocolTCP , Port : int32 (86 ), TargetPort : intstr .FromInt (86 )},
1962+ {Name : "port7" , Protocol : v1 .ProtocolTCP , Port : int32 (88 ), TargetPort : intstr .FromInt (87 )},
1963+ }
1964+
1965+ status , err := createExternalLoadBalancer (gce , svc , []string {"test-node-1" }, vals .ClusterName , vals .ClusterID , vals .ZoneName )
1966+ require .NotNil (t , status )
1967+ require .NoError (t , err )
1968+ svcName := "/" + svc .ObjectMeta .Name
1969+
1970+ ipAddr := status .Ingress [0 ].IP
1971+ lbName := gce .GetLoadBalancerName (context .TODO (), "" , svc )
1972+
1973+ ipnet , err := utilnet .ParseIPNets ("0.0.0.0/0" )
1974+ require .NoError (t , err )
1975+
1976+ fw , err := gce .GetFirewall (MakeFirewallName (lbName ))
1977+ require .NoError (t , err )
1978+
1979+ for desc := range map [string ]struct {
1980+ hasErr bool
1981+ }{
1982+ "need to update port-ranges " : {},
1983+ } {
1984+ t .Run (desc , func (t * testing.T ) {
1985+ fw , err = gce .GetFirewall (MakeFirewallName (lbName ))
1986+ assert .NoError (t , err )
1987+ assert .Nil (t , fw )
1988+
1989+ exists , needsUpdate , err := gce .firewallNeedsUpdate (
1990+ lbName ,
1991+ svcName ,
1992+ ipAddr ,
1993+ svc .Spec .Ports ,
1994+ ipnet )
1995+
1996+ assert .Equal (t , false , exists , "firewall should not exist" )
1997+ assert .Equal (t , false , needsUpdate , "firewall should not exist, no update needed" )
1998+ assert .NoError (t , err )
1999+ })
2000+ }
2001+ }
2002+
19052003func TestDeleteWrongNetworkTieredResourcesSucceedsWhenNotFound (t * testing.T ) {
19062004 t .Parallel ()
19072005
0 commit comments