Skip to content

Commit d122fcb

Browse files
authored
[CNS] Overlay Expansion Subnet Update Job Bug Fix (#4103)
hot fix
1 parent 53289b6 commit d122fcb

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

cns/restserver/internalapi.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ func (service *HTTPRestService) CreateOrUpdateNetworkContainerInternal(req *cns.
632632
existingReq := existingNCInfo.CreateNetworkContainerRequest
633633
if !reflect.DeepEqual(existingReq.IPConfiguration.IPSubnet, req.IPConfiguration.IPSubnet) {
634634
// check for potential overlay subnet expansion - checking if new subnet is a superset of old subnet
635-
isCIDRSuperset := validateCIDRSuperset(req.IPConfiguration.IPSubnet.IPAddress, existingReq.IPConfiguration.IPSubnet.IPAddress)
635+
isCIDRSuperset := validateCIDRSuperset(
636+
fmt.Sprintf("%s/%d", req.IPConfiguration.IPSubnet.IPAddress, req.IPConfiguration.IPSubnet.PrefixLength),
637+
fmt.Sprintf("%s/%d", existingReq.IPConfiguration.IPSubnet.IPAddress, existingReq.IPConfiguration.IPSubnet.PrefixLength))
636638
if !isCIDRSuperset {
637639
logger.Errorf("[Azure CNS] Error. PrimaryCA is not same, NCId %s, old CA %s/%d, new CA %s/%d", //nolint:staticcheck // Suppress SA1019: logger.Errorf is deprecated
638640
req.NetworkContainerid,

cns/restserver/internalapi_test.go

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ func TestReconcileNCStatePrimaryIPChangeShouldFail(t *testing.T) {
6767
svc.state.ContainerStatus = make(map[string]containerstatus)
6868

6969
testCases := []struct {
70-
existingIPAddress string
71-
requestIPAddress string
70+
reqIPAddress string
71+
reqPrefixLength uint8
72+
existingIPAddress string
73+
existingPrefixLength uint8
7274
}{
73-
{"", "10.240.0.0/16"},
74-
{"10.240.0.0", "2001:db8::/64"},
75-
{"2001:db8::/64", "10.240.0.0/16"},
76-
{"10.0.1.0/22", "10.0.2.0/24"},
77-
{"10.0.1.0/21", "10.0.1.0/23"},
78-
{"10.0.1.0", "10.0.0.0/15"},
79-
{"10.0.1.0/15", "10.0.0.0"},
75+
{"10.240.1.0", 16, "10.240.0.0", 16},
76+
{"10.240.0.0", 64, "2001:db8::", 64},
77+
{"2001:db8::", 64, "10.240.0.0", 16},
78+
{"10.0.1.0", 24, "10.0.2.0", 22},
79+
{"10.0.1.0", 23, "10.0.1.0", 21},
8080
}
8181

8282
// Run test cases
@@ -92,7 +92,7 @@ func TestReconcileNCStatePrimaryIPChangeShouldFail(t *testing.T) {
9292
IPConfiguration: cns.IPConfiguration{
9393
IPSubnet: cns.IPSubnet{
9494
IPAddress: tc.existingIPAddress,
95-
PrefixLength: 24,
95+
PrefixLength: tc.existingPrefixLength,
9696
},
9797
},
9898
},
@@ -103,8 +103,8 @@ func TestReconcileNCStatePrimaryIPChangeShouldFail(t *testing.T) {
103103
NetworkContainerid: ncID,
104104
IPConfiguration: cns.IPConfiguration{
105105
IPSubnet: cns.IPSubnet{
106-
IPAddress: tc.requestIPAddress,
107-
PrefixLength: 24,
106+
IPAddress: tc.reqIPAddress,
107+
PrefixLength: tc.reqPrefixLength,
108108
},
109109
},
110110
},
@@ -127,13 +127,17 @@ func TestReconcileNCStatePrimaryIPChangeShouldNotFail(t *testing.T) {
127127
svc.state.ContainerStatus = make(map[string]containerstatus)
128128

129129
testCases := []struct {
130-
existingIPAddress string
131-
requestIPAddress string
130+
reqIPAddress string
131+
reqPrefixLength uint8
132+
existingIPAddress string
133+
existingPrefixLength uint8
132134
}{
133-
{"10.0.1.0/24", "10.0.2.0/22"},
134-
{"10.0.1.0/20", "10.0.1.0/18"},
135-
{"10.0.1.0/19", "10.0.0.0/15"},
136-
{"10.0.1.0/18", "10.0.1.0/18"},
135+
{"10.240.0.0", 20, "10.240.0.0", 24},
136+
137+
{"10.0.1.0", 22, "10.0.2.0", 24},
138+
{"10.0.1.0", 18, "10.0.1.0", 20},
139+
{"10.0.1.0", 15, "10.0.0.0", 19},
140+
{"10.0.1.0", 18, "10.0.1.0", 18},
137141
}
138142

139143
// Run test cases
@@ -149,7 +153,7 @@ func TestReconcileNCStatePrimaryIPChangeShouldNotFail(t *testing.T) {
149153
IPConfiguration: cns.IPConfiguration{
150154
IPSubnet: cns.IPSubnet{
151155
IPAddress: tc.existingIPAddress,
152-
PrefixLength: 24,
156+
PrefixLength: tc.existingPrefixLength,
153157
},
154158
},
155159
},
@@ -160,8 +164,8 @@ func TestReconcileNCStatePrimaryIPChangeShouldNotFail(t *testing.T) {
160164
NetworkContainerid: ncID,
161165
IPConfiguration: cns.IPConfiguration{
162166
IPSubnet: cns.IPSubnet{
163-
IPAddress: tc.requestIPAddress,
164-
PrefixLength: 24,
167+
IPAddress: tc.reqIPAddress,
168+
PrefixLength: tc.reqPrefixLength,
165169
},
166170
},
167171
NetworkContainerType: cns.Kubernetes,

0 commit comments

Comments
 (0)