Skip to content

Commit

Permalink
Make evacuate aware of replica set and daemon set
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Oct 11, 2016
1 parent 8f6030a commit 9c64fe4
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions pkg/cmd/admin/node/evacuate.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,65 @@ func (e *EvacuateOptions) RunEvacuate(node *kapi.Node) error {
return err
}

rss, err := e.Options.Kclient.ReplicaSets(kapi.NamespaceAll).List(kapi.ListOptions{})
if err != nil {
return err
}

dss, err := e.Options.Kclient.DaemonSets(kapi.NamespaceAll).List(kapi.ListOptions{})
if err != nil {
return err
}

jobs, err := e.Options.Kclient.Jobs(kapi.NamespaceAll).List(kapi.ListOptions{})
if err != nil {
return err
}

printer, err := e.Options.GetPrintersByResource(unversioned.GroupVersionResource{Resource: "pod"})
if err != nil {
return err
}

errList := []error{}
firstPod := true
numPodsWithNoRC := 0
numUnmanagedPods := 0

var deleteOptions *kapi.DeleteOptions
if e.GracePeriod >= 0 {
deleteOptions = e.makeDeleteOptions()
}

for _, pod := range pods.Items {
foundrc := false
isManaged := false
for _, rc := range rcs.Items {
selector := labels.SelectorFromSet(rc.Spec.Selector)
if selector.Matches(labels.Set(pod.Labels)) {
foundrc = true
isManaged = true
break
}
}

for _, rs := range rss.Items {
selector := labels.SelectorFromSet(rs.Spec.Selector.MatchLabels)
if selector.Matches(labels.Set(pod.Labels)) {
isManaged = true
break
}
}

for _, ds := range dss.Items {
selector := labels.SelectorFromSet(ds.Spec.Selector.MatchLabels)
if selector.Matches(labels.Set(pod.Labels)) {
isManaged = true
break
}
}

for _, job := range jobs.Items {
selector := labels.SelectorFromSet(job.Spec.Selector.MatchLabels)
if selector.Matches(labels.Set(pod.Labels)) {
isManaged = true
break
}
}
Expand All @@ -129,18 +168,18 @@ func (e *EvacuateOptions) RunEvacuate(node *kapi.Node) error {

printer.PrintObj(&pod, e.Options.Writer)

if foundrc || e.Force {
if isManaged || e.Force {
if err := e.Options.Kclient.Pods(pod.Namespace).Delete(pod.Name, deleteOptions); err != nil {
glog.Errorf("Unable to delete a pod: %+v, error: %v", pod, err)
errList = append(errList, err)
continue
}
} else { // Pods without replication controller and no --force option
numPodsWithNoRC++
numUnmanagedPods++
}
}
if numPodsWithNoRC > 0 {
err := fmt.Errorf(`Unable to evacuate some pods because they are not backed by replication controller.
if numUnmanagedPods > 0 {
err := fmt.Errorf(`Unable to evacuate some pods because they are not managed by replication controller or replica set or deaemon set.
Suggested options:
- You can list bare pods in json/yaml format using '--list-pods -o json|yaml'
- Force deletion of bare pods with --force option to --evacuate
Expand Down

0 comments on commit 9c64fe4

Please sign in to comment.