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
(cherry picked from commit db3b9f7)
  • Loading branch information
chestack authored and oilbeater committed Jul 12, 2022
1 parent 02e8973 commit 7699a34
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,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 @@ -1342,6 +1343,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 @@ -1358,6 +1360,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 @@ -1379,6 +1382,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 7699a34

Please sign in to comment.