Skip to content

Commit

Permalink
Merge pull request kubernetes#45661 from deads2k/cli-11-delete
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

orphan when kubectl delete --cascade=false

The default for new objects is to propagate deletes (use GC) when no deleteoptions are passed.  In addition, the vast majority of kube objects use this default.  Only a few controllers resources (sts, rc, deploy, jobs, rs) orphan by default.  This means that when you do `kubectl delete sa/foo --cascade=false` you do *not* orphan.  That doesn't fulfill the intent of the command.  This explicitly orphans when `--cascade=false` so we don't use GC.

@fabianofranz 
@jwforres I liked this easter egg :)

@kubernetes/sig-cli-bugs we should backport this to 1.6
  • Loading branch information
Kubernetes Submit Queue authored May 12, 2017
2 parents 86eb189 + e91716a commit 7408f6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/kubectl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ func DeleteResult(r *resource.Result, out io.Writer, ignoreNotFound bool, shortO
return err
}
found++
return deleteResource(info, out, shortOutput, mapper, nil)

// if we're here, it means that cascade=false (not the default), so we should orphan as requested
orphan := true
return deleteResource(info, out, shortOutput, mapper, &metav1.DeleteOptions{OrphanDependents: &orphan})
})
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubectl/cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) {
t.Errorf("unexpected output: %s", buf.String())
}

// Test that delete options should be nil when cascade is false.
expectedOrphanDependents = nil
// Test that delete options should be set to orphan when cascade is false.
trueVar := true
expectedOrphanDependents = &trueVar
buf, errBuf = bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{})
cmd = NewCmdDelete(f, buf, errBuf)
cmd.Flags().Set("namespace", "test")
Expand Down

0 comments on commit 7408f6b

Please sign in to comment.