diff --git a/cns/restserver/ipam.go b/cns/restserver/ipam.go index abed5ac304..36244698b0 100644 --- a/cns/restserver/ipam.go +++ b/cns/restserver/ipam.go @@ -112,6 +112,28 @@ func (service *HTTPRestService) MarkIPsAsPending(numberToMark int) (map[string]c return nil, fmt.Errorf("Failed to mark %d IP's as pending, only marked %d IP's", numberToMark, len(pendingReleaseIPs)) } +// UpdatePendingProgrammingIPs will update pending programming IPs to available if +// NMAgent side's programmed NC version keep up with NC version attached with secondary IP. +func (service *HTTPRestService) UpdatePendingProgrammingIPs(nmagentNCVersion string) error { + service.Lock() + defer service.Unlock() + //for uuid, ipConfigurationStatus := range service.PodIPConfigState { + for _, containerstatus := range service.state.ContainerStatus { + for uuid, secondaryIPConfigs := range containerstatus.CreateNetworkContainerRequest.SecondaryIPConfigs { + ipConfigStatus, exist := service.PodIPConfigState[uuid] + if exist { + // TODO change cns.Available to cns.PendingProgrammiong when #690 merged. + // TODO change ipConfigStatus.IPAddress to ipConfigStatus.NCVersion when #697 merged. + if ipConfigStatus.State == cns.Available && secondaryIPConfigs.IPAddress <= nmagentNCVersion { + ipConfigStatus.State = cns.Available + logger.Printf("Change ip %s with uuid %s from pending programming to %s", ipConfigStatus.IPAddress, uuid, cns.Available) + } + } + } + } + return fmt.Errorf("Failed to mark IP's from pending programming to available") +} + func (service *HTTPRestService) GetPodIPConfigState() map[string]cns.IPConfigurationStatus { service.RLock() defer service.RUnlock()