From 0ee592c2b51044e0b5728f225466720ccc752ca7 Mon Sep 17 00:00:00 2001 From: Shufang Date: Wed, 21 Oct 2020 09:56:09 -0700 Subject: [PATCH 1/2] Add a function to handle updating pending programming IPs. --- cns/restserver/ipam.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cns/restserver/ipam.go b/cns/restserver/ipam.go index abed5ac304..805e2800e4 100644 --- a/cns/restserver/ipam.go +++ b/cns/restserver/ipam.go @@ -112,6 +112,25 @@ 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 uuidFromNCRq, secondaryIPConfigs := range containerstatus.CreateNetworkContainerRequest.SecondaryIPConfigs { + // Change cns.Available to cns.PendingProgramming. Change IPAddress to NCVersion + if ipConfigurationStatus.State == cns.Available && uuid == uuidFromNCRq && secondaryIPConfigs.IPAddress <= nmagentNCVersion { + ipConfigurationStatus.State = cns.Available + logger.Printf("Change ip %s with uuid %s from pending programming to %s", ipConfigurationStatus.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() From b5b3fbf6f08deadb1aa2f232c69fba334b3364a0 Mon Sep 17 00:00:00 2001 From: Shufang Date: Wed, 21 Oct 2020 18:24:06 -0700 Subject: [PATCH 2/2] Simplify the logic. --- cns/restserver/ipam.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cns/restserver/ipam.go b/cns/restserver/ipam.go index 805e2800e4..36244698b0 100644 --- a/cns/restserver/ipam.go +++ b/cns/restserver/ipam.go @@ -117,13 +117,16 @@ func (service *HTTPRestService) MarkIPsAsPending(numberToMark int) (map[string]c 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 uuidFromNCRq, secondaryIPConfigs := range containerstatus.CreateNetworkContainerRequest.SecondaryIPConfigs { - // Change cns.Available to cns.PendingProgramming. Change IPAddress to NCVersion - if ipConfigurationStatus.State == cns.Available && uuid == uuidFromNCRq && secondaryIPConfigs.IPAddress <= nmagentNCVersion { - ipConfigurationStatus.State = cns.Available - logger.Printf("Change ip %s with uuid %s from pending programming to %s", ipConfigurationStatus.IPAddress, uuid, cns.Available) + //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) } } }