Skip to content

Commit

Permalink
Fix for IPAM CR cleanup issue (#3409)
Browse files Browse the repository at this point in the history
  • Loading branch information
arzzon committed May 8, 2024
1 parent c8ff031 commit 482f1af
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/ipmanager/ipmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ func (h *IPAMHandler) RequestIP(ipamLabel string, host string, key string, ref R
if hst.IPAMLabel == ipamLabel {
if ip != "" {
// IP extracted from the corresponding status of the spec
if !h.IsHostSpecCached(hostSpec) {
// This scenario occurs when CIS is restarted after IP allocation.
h.AddHostSpec(hostSpec)
}
return ip, Allocated
}

Expand Down Expand Up @@ -312,6 +316,9 @@ func (h *IPAMHandler) RemoveUnusedIPAMEntries() {
}
h.ipamCache.RUnlock()
}
cisUsedIPAM.SetName(ipamCR.GetName())
cisUsedIPAM.SetNamespace(ipamCR.GetNamespace())
cisUsedIPAM.SetResourceVersion(ipamCR.GetResourceVersion())
if !reflect.DeepEqual(ipamCR.Spec, cisUsedIPAM.Spec) {
_, err := h.IpamCli.Update(cisUsedIPAM)
if err != nil {
Expand All @@ -336,6 +343,16 @@ func (h *IPAMHandler) AddHostSpec(key ficV1.HostSpec) {
h.ipamCache.ipamCacheMap[key] = ""
}

// IsHostSpecCached function to checks if IPAM HostSpec is cached
func (h *IPAMHandler) IsHostSpecCached(key ficV1.HostSpec) bool {
h.ipamCache.RLock()
defer h.ipamCache.RUnlock()
if _, ok := h.ipamCache.ipamCacheMap[key]; ok {
return true
}
return false
}

// function to add ipSpec to the ipam context
func (h *IPAMHandler) UpdateCacheWithIpAddress(key ficV1.HostSpec, ipAdd string) {
h.ipamCache.Lock()
Expand Down

0 comments on commit 482f1af

Please sign in to comment.