Skip to content

Commit

Permalink
fix: delete pod panic when delete vm or statefulset. (#1565)
Browse files Browse the repository at this point in the history
when vm is deleted, get vm != nil; need use err == isNotFound.

add log for other errors when get vm or statefulset
  • Loading branch information
xujunjie-cover authored and hongzhen-ma committed May 30, 2022
1 parent 4c60872 commit f39ff7a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,28 @@ func appendCheckPodToDel(c *Controller, pod *v1.Pod, ownerRefName, ownerRefKind
var ownerRefSubnetExist bool
switch ownerRefKind {
case "StatefulSet":
ss, _ := c.config.KubeClient.AppsV1().StatefulSets(pod.Namespace).Get(context.Background(), ownerRefName, metav1.GetOptions{})
if ss != nil && ss.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
ss, err := c.config.KubeClient.AppsV1().StatefulSets(pod.Namespace).Get(context.Background(), ownerRefName, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return true, nil
} else {
klog.Errorf("failed to get StatefulSet %s, %v", ownerRefName, err)
}
}
if ss.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
ownerRefSubnetExist = true
}

case util.VmInstance:
vm, _ := c.config.KubevirtClient.VirtualMachine(pod.Namespace).Get(ownerRefName, &metav1.GetOptions{})
if vm != nil && vm.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
vm, err := c.config.KubevirtClient.VirtualMachine(pod.Namespace).Get(ownerRefName, &metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return true, nil
} else {
klog.Errorf("failed to get VirtualMachine %s, %v", ownerRefName, err)
}
}
if vm.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
ownerRefSubnetExist = true
}
}
Expand Down

0 comments on commit f39ff7a

Please sign in to comment.