Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve watcher when waiting for IP deletion #114

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions plugins/ipam/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func (k K8sClient) prepareCreateIpamIP(subnetName string, ipaddr net.IP, mac net
}

k.EventRecorder.Eventf(existingIpamIP, corev1.EventTypeNormal, "Deleted", "Deleted old IPAM IP")
log.Infof("Old IP %s/%s deleted from subnet %s/%s", existingIpamIP.Namespace, existingIpamIP.Name, k.Namespace, subnetName)
log.Infof("Old IP %s/%s deleted from subnet %s", existingIpamIP.Namespace, existingIpamIP.Name, existingIpamIP.Spec.Subnet.Name)
} else {
log.Infof("IP %s/%s already exists in subnet %s/%s, nothing to do", existingIpamIP.Namespace, existingIpamIP.Name, k.Namespace, subnetName)
log.Infof("IP %s/%s already exists in subnet %s, nothing to do", existingIpamIP.Namespace, existingIpamIP.Name, existingIpamIP.Spec.Subnet.Name)
return nil, nil
}
}
Expand Down Expand Up @@ -230,8 +230,9 @@ func (k K8sClient) waitForDeletion(ipamIP *ipamv1alpha1.IP) error {

for event := range watcher.ResultChan() {
log.Debugf("Type: %s, Object: %v\n", event.Type, event.Object)
if event.Type == watch.Deleted {
log.Debug("IP deleted")
foundIpamIP := event.Object.(*ipamv1alpha1.IP)
if event.Type == watch.Deleted && reflect.DeepEqual(ipamIP.Spec, foundIpamIP.Spec) {
log.Infof("IP %s/%s deleted", foundIpamIP.Namespace, foundIpamIP.Name)
return nil
}
}
Expand All @@ -248,7 +249,7 @@ func (k K8sClient) doCreateIpamIP(ipamIP *ipamv1alpha1.IP, subnetName string) er
// do not create IP, because the deletion is not yet ready
noop()
} else {
log.Infof("New IP %s/%s created in subnet %s/%s", ipamIP.Namespace, ipamIP.Name, k.Namespace, subnetName)
log.Infof("New IP %s/%s created in subnet %s", ipamIP.Namespace, ipamIP.Name, ipamIP.Spec.Subnet.Name)
k.EventRecorder.Eventf(ipamIP, corev1.EventTypeNormal, "Created", "Created IPAM IP")
}

Expand Down
Loading