Skip to content

Commit

Permalink
Delete pod if subnet of the pod's owner(sts/vm) updated (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
chestack committed Jul 12, 2022
1 parent 533859f commit db3b9f7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/pod.go
Expand Up @@ -1366,6 +1366,7 @@ func appendCheckPodToDel(c *Controller, pod *v1.Pod, ownerRefName, ownerRefKind

// check if subnet exist in OwnerReference
var ownerRefSubnetExist bool
var ownerRefSubnet string
switch ownerRefKind {
case "StatefulSet":
ss, err := c.config.KubeClient.AppsV1().StatefulSets(pod.Namespace).Get(context.Background(), ownerRefName, metav1.GetOptions{})
Expand All @@ -1378,6 +1379,7 @@ func appendCheckPodToDel(c *Controller, pod *v1.Pod, ownerRefName, ownerRefKind
}
if ss.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
ownerRefSubnetExist = true
ownerRefSubnet = ss.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation]
}

case util.VmInstance:
Expand All @@ -1394,6 +1396,7 @@ func appendCheckPodToDel(c *Controller, pod *v1.Pod, ownerRefName, ownerRefKind
vm.Spec.Template.ObjectMeta.Annotations != nil &&
vm.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
ownerRefSubnetExist = true
ownerRefSubnet = vm.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation]
}
}

Expand All @@ -1415,6 +1418,11 @@ func appendCheckPodToDel(c *Controller, pod *v1.Pod, ownerRefName, ownerRefKind
klog.Infof("pod's ip %s is not in the range of subnet %s, delete pod", pod.Annotations[util.IpAddressAnnotation], podSubnet.Name)
return true, nil
}
// subnet of ownerReference(sts/vm) has been changed, it needs to handle delete pod and create port on the new logical switch
if podSubnet != nil && ownerRefSubnet != "" && podSubnet.Name != ownerRefSubnet {
klog.Infof("Subnet of owner %s has been changed from %s to %s, delete pod %s/%s", ownerRefName, podSubnet.Name, ownerRefSubnet, pod.Namespace, pod.Name)
return true, nil
}

return false, nil
}
Expand Down

0 comments on commit db3b9f7

Please sign in to comment.