@@ -18,8 +18,8 @@ import (
18
18
)
19
19
20
20
var (
21
- errStoreEmpty = errors .New ("empty endpoint state store" )
22
- errParsePodIPFailed = errors .New ("failed to parse pod's ip" )
21
+ ErrStoreEmpty = errors .New ("empty endpoint state store" )
22
+ ErrParsePodIPFailed = errors .New ("failed to parse pod's ip" )
23
23
)
24
24
25
25
// requestIPConfigHandlerHelper validates the request, assigns IPs, and returns a response
@@ -103,24 +103,16 @@ func (service *HTTPRestService) requestIPConfigHandler(w http.ResponseWriter, r
103
103
return
104
104
}
105
105
106
- var ipconfigsRequest cns.IPConfigsRequest
107
106
// doesn't fill in DesiredIPAddresses if it is empty in the original request
107
+ ipconfigsRequest := cns.IPConfigsRequest {
108
+ PodInterfaceID : ipconfigRequest .PodInterfaceID ,
109
+ InfraContainerID : ipconfigRequest .InfraContainerID ,
110
+ OrchestratorContext : ipconfigRequest .OrchestratorContext ,
111
+ Ifname : ipconfigRequest .Ifname ,
112
+ }
108
113
if ipconfigRequest .DesiredIPAddress != "" {
109
- ipconfigsRequest = cns.IPConfigsRequest {
110
- DesiredIPAddresses : []string {
111
- ipconfigRequest .DesiredIPAddress ,
112
- },
113
- PodInterfaceID : ipconfigRequest .PodInterfaceID ,
114
- InfraContainerID : ipconfigRequest .InfraContainerID ,
115
- OrchestratorContext : ipconfigRequest .OrchestratorContext ,
116
- Ifname : ipconfigRequest .Ifname ,
117
- }
118
- } else {
119
- ipconfigsRequest = cns.IPConfigsRequest {
120
- PodInterfaceID : ipconfigRequest .PodInterfaceID ,
121
- InfraContainerID : ipconfigRequest .InfraContainerID ,
122
- OrchestratorContext : ipconfigRequest .OrchestratorContext ,
123
- Ifname : ipconfigRequest .Ifname ,
114
+ ipconfigsRequest .DesiredIPAddresses = []string {
115
+ ipconfigRequest .DesiredIPAddress ,
124
116
}
125
117
}
126
118
@@ -171,7 +163,7 @@ func (service *HTTPRestService) requestIPConfigsHandler(w http.ResponseWriter, r
171
163
172
164
func (service * HTTPRestService ) updateEndpointState (ipconfigsRequest cns.IPConfigsRequest , podInfo cns.PodInfo , podIPInfo []cns.PodIpInfo ) error {
173
165
if service .EndpointStateStore == nil {
174
- return errStoreEmpty
166
+ return ErrStoreEmpty
175
167
}
176
168
service .Lock ()
177
169
defer service .Unlock ()
@@ -182,7 +174,7 @@ func (service *HTTPRestService) updateEndpointState(ipconfigsRequest cns.IPConfi
182
174
ip := net .ParseIP (podIPInfo [i ].PodIPConfig .IPAddress )
183
175
if ip == nil {
184
176
logger .Errorf ("failed to parse pod ip address %s" , podIPInfo [i ].PodIPConfig .IPAddress )
185
- return errParsePodIPFailed
177
+ return ErrParsePodIPFailed
186
178
}
187
179
if ip .To4 () == nil { // is an ipv6 address
188
180
ipconfig := net.IPNet {IP : ip , Mask : net .CIDRMask (int (podIPInfo [i ].PodIPConfig .PrefixLength ), 128 )} // nolint
@@ -209,7 +201,7 @@ func (service *HTTPRestService) updateEndpointState(ipconfigsRequest cns.IPConfi
209
201
ip := net .ParseIP (podIPInfo [i ].PodIPConfig .IPAddress )
210
202
if ip == nil {
211
203
logger .Errorf ("failed to parse pod ip address %s" , podIPInfo [i ].PodIPConfig .IPAddress )
212
- return errParsePodIPFailed
204
+ return ErrParsePodIPFailed
213
205
}
214
206
ipInfo := & IPInfo {}
215
207
if ip .To4 () == nil { // is an ipv6 address
@@ -348,7 +340,7 @@ func (service *HTTPRestService) releaseIPConfigsHandler(w http.ResponseWriter, r
348
340
349
341
func (service * HTTPRestService ) removeEndpointState (podInfo cns.PodInfo ) error {
350
342
if service .EndpointStateStore == nil {
351
- return errStoreEmpty
343
+ return ErrStoreEmpty
352
344
}
353
345
service .Lock ()
354
346
defer service .Unlock ()
@@ -775,9 +767,11 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
775
767
// Searches for available IPs in the pool
776
768
for _ , ipState := range service .PodIPConfigState {
777
769
// check if an IP from this NC is already set side for assignment.
778
- _ , ncAlreadyMarkedForAssignment := ipsToAssign [ipState .NCID ]
779
- // Checks if we haven't already found an IP from that NC and checks if the current IP is available
780
- if ncAlreadyMarkedForAssignment || ipState .GetState () != types .Available {
770
+ if _ , ncAlreadyMarkedForAssignment := ipsToAssign [ipState .NCID ]; ncAlreadyMarkedForAssignment {
771
+ continue
772
+ }
773
+ // Checks if the current IP is available
774
+ if ipState .GetState () != types .Available {
781
775
continue
782
776
}
783
777
ipsToAssign [ipState .NCID ] = ipState
0 commit comments