Skip to content

Commit

Permalink
Merge pull request #2058 from panslava/release-1.22
Browse files Browse the repository at this point in the history
[Cherry-Pick 1.22] Add comparing PortRange in forwarding rules Equal function
  • Loading branch information
k8s-ci-robot authored Apr 4, 2023
2 parents c49e853 + c1bb86a commit a567694
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/loadbalancers/forwarding_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func Equal(fr1, fr2 *composite.ForwardingRule) (bool, error) {
fr1.IPProtocol == fr2.IPProtocol &&
fr1.LoadBalancingScheme == fr2.LoadBalancingScheme &&
utils.EqualStringSets(fr1.Ports, fr2.Ports) &&
fr1.PortRange == fr2.PortRange &&
id1.Equal(id2) &&
fr1.AllowGlobalAccess == fr2.AllowGlobalAccess &&
fr1.AllPorts == fr2.AllPorts &&
Expand Down
23 changes: 23 additions & 0 deletions pkg/loadbalancers/forwarding_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ func TestForwardingRulesEqual(t *testing.T) {
},
}

frPortRange1 := &composite.ForwardingRule{
Name: "tcp-fwd-rule",
IPAddress: "10.0.0.0",
PortRange: "2-3",
IPProtocol: "TCP",
LoadBalancingScheme: string(cloud.SchemeInternal),
BackendService: "http://www.googleapis.com/projects/test/regions/us-central1/backendServices/bs1",
}
frPortRange2 := &composite.ForwardingRule{
Name: "tcp-fwd-rule",
IPAddress: "10.0.0.0",
PortRange: "1-2",
IPProtocol: "TCP",
LoadBalancingScheme: string(cloud.SchemeInternal),
BackendService: "http://www.googleapis.com/projects/test/regions/us-central1/backendServices/bs1",
}

for _, tc := range []struct {
desc string
oldFwdRule *composite.ForwardingRule
Expand Down Expand Up @@ -227,6 +244,12 @@ func TestForwardingRulesEqual(t *testing.T) {
newFwdRule: fwdRules[7],
expect: false,
},
{
desc: "same forwarding rule, different port ranges",
oldFwdRule: frPortRange1,
newFwdRule: frPortRange2,
expect: false,
},
} {
t.Run(tc.desc, func(t *testing.T) {
got, err := Equal(tc.oldFwdRule, tc.newFwdRule)
Expand Down

0 comments on commit a567694

Please sign in to comment.