@@ -25,19 +25,39 @@ import (
2525var deleteCmd = & cobra.Command {
2626 Use : "delete -n PARENT CHILD" ,
2727 Short : "Deletes a subnamespace under the given parent." ,
28- Args : cobra .ExactArgs (1 ),
28+ Example : `# Delete the 'foo' anchor in the parent 'bar' namespace
29+ kubectl hns delete foo -n bar
30+
31+ # Allow 'foo' to be cascading deleted and delete it
32+ kubectl hns delete foo -n bar --allowCascadingDeletion` ,
33+ Args : cobra .ExactArgs (1 ),
2934 Run : func (cmd * cobra.Command , args []string ) {
35+ nnm := args [0 ]
36+
3037 parent , _ := cmd .Flags ().GetString ("namespace" )
3138 if parent == "" {
3239 fmt .Println ("Error: parent must be set via --namespace or -n" )
3340 os .Exit (1 )
3441 }
3542
36- client .deleteAnchor (parent , args [0 ])
43+ allowCD , _ := cmd .Flags ().GetBool ("allowCascadingDeletion" )
44+ if allowCD {
45+ hc := client .getHierarchy (nnm )
46+ if hc .Spec .AllowCascadingDeletion {
47+ fmt .Printf ("Cascading deletion for '%s' is already set to 'true'; unchanged\n " , nnm )
48+ } else {
49+ fmt .Printf ("Allowing cascading deletion on '%s'\n " , nnm )
50+ hc .Spec .AllowCascadingDeletion = true
51+ client .updateHierarchy (hc , fmt .Sprintf ("update the hierarchical configuration of %s" , nnm ))
52+ }
53+ }
54+
55+ client .deleteAnchor (parent , nnm )
3756 },
3857}
3958
4059func newDeleteCmd () * cobra.Command {
4160 deleteCmd .Flags ().StringP ("namespace" , "n" , "" , "The parent namespace for the new subnamespace" )
61+ deleteCmd .Flags ().BoolP ("allowCascadingDeletion" , "a" , false , "Allows cascading deletion of its subnamespaces." )
4262 return deleteCmd
4363}
0 commit comments