Skip to content

Commit

Permalink
fix repeat delete service and pod (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
wackxu authored and k8s-ci-robot committed May 15, 2019
1 parent 7432acb commit 63de5cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/control/pod_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -154,6 +155,17 @@ func (r RealPodControl) DeletePod(namespace string, podID string, object runtime
if err != nil {
return fmt.Errorf("object does not have ObjectMeta, %v", err)
}
pod, err := r.KubeClient.CoreV1().Pods(namespace).Get(podID, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
}
return err
}
if pod.DeletionTimestamp != nil {
glog.V(3).Infof("pod %s/%s is terminating, skip deleting", pod.Namespace, pod.Name)
return nil
}
glog.V(2).Infof("Controller %v deleting pod %v/%v", accessor.GetName(), namespace, podID)
if err := r.KubeClient.CoreV1().Pods(namespace).Delete(podID, nil); err != nil {
r.Recorder.Eventf(object, v1.EventTypeWarning, FailedDeletePodReason, "Error deleting: %v", err)
Expand Down
12 changes: 12 additions & 0 deletions pkg/control/service_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -123,6 +124,17 @@ func (r RealServiceControl) DeleteService(namespace, serviceID string, object ru
if err != nil {
return fmt.Errorf("object does not have ObjectMeta, %v", err)
}
service, err := r.KubeClient.CoreV1().Services(namespace).Get(serviceID, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
}
return err
}
if service.DeletionTimestamp != nil {
log.Infof("service %s/%s is terminating, skip deleting", service.Namespace, service.Name)
return nil
}
log.Infof("Controller %v deleting service %v/%v", accessor.GetName(), namespace, serviceID)
if err := r.KubeClient.CoreV1().Services(namespace).Delete(serviceID, nil); err != nil {
r.Recorder.Eventf(object, v1.EventTypeWarning, FailedDeleteServiceReason, "Error deleting: %v", err)
Expand Down

0 comments on commit 63de5cb

Please sign in to comment.