Skip to content

Commit ce1aba4

Browse files
authored
Merge pull request kubernetes-retired#302 from mochizuki875/fix_quickstart_allowCascadingDeletion
Fix Quickstart Document about allowCascadingDeletion
2 parents d9887e2 + f3c6706 commit ce1aba4

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

docs/user-guide/quickstart.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ subnamespaces by default.
633633

634634
HNC will only allow recursive deletion of subnamespaces if those subnamespaces,
635635
or any of their ancestors, have cascading deletion explicitly set. For example,
636-
to delete `service-1`, we first enable cascading deletion and then remove it:
636+
to delete `service-1`, you first enable cascading deletion and then remove it:
637637

638638
```bash
639639
kubectl hns set service-1 --allowCascadingDeletion
@@ -642,12 +642,39 @@ kubectl hns set service-1 --allowCascadingDeletion
642642
kubectl hns set service-1 -a
643643
```
644644

645+
You can check if the `service-1` cascading deletion is enabled from its `.spec.allowCascadingDeletion` field of `HierarchyConfiguration`. If the value is `true`, it's enabled.
646+
647+
```bash
648+
kubectl get hierarchyconfiguration hierarchy -o jsonpath='{.spec}' -n service-1
649+
```
650+
651+
Expected output:
652+
653+
```bash
654+
{"allowCascadingDeletion":true,"parent":"team-a"}
655+
```
656+
645657
Now you can (unsafely!) delete `service-1`:
646658

647659
```bash
648660
kubectl delete subns service-1 -n team-a
649661
```
650662

663+
You can see `service-1` and `dev` subnamespace under `service-1` are deleted.
664+
665+
```bash
666+
kubectl hns tree team-a
667+
```
668+
669+
Expected output:
670+
671+
```bash
672+
team-a
673+
└── [s] service-2
674+
675+
[s] indicates subnamespaces
676+
```
677+
651678
There's an important difference between subnamespaces and regular child
652679
namespace, also known as a full namespace. A subnamespace is created by HNC due
653680
to an anchor being created in the parent; when that anchor is deleted, the
@@ -661,6 +688,8 @@ full namespace itself will _not_ be deleted. However, HNC will mark is as being
661688
in the `ActivitiesHalted (ParentMissing)` condition, as you can see by calling
662689
`kubectl hns describe regular-child`.
663690

691+
_Caution: Any propagated objects inside descendant namespaces will be deleted by deleting a parent namespace._
692+
664693
Let's see this in action. Create another subnamespace `service-4`:
665694

666695
```bash
@@ -678,28 +707,63 @@ kubectl hns tree team-a
678707

679708
Expected output:
680709

681-
```
710+
```bash
682711
team-a
683712
├── [s] service-2
684713
└── [s] service-4
685714
└── staging
686715
```
687716

688-
Now, even if you delete `service-4`, the new `staging` namespace will _not_ be
689-
deleted.
717+
718+
As the same of `service-1`, you can't delete `service-4` subnamespace which is
719+
a parent of `staging` full namespace.
720+
721+
This is both to be consistent with how subnamespaces are treated,
722+
and also because deleting `service-4` will delete any propagated objects
723+
inside `staging`.
724+
725+
```bash
726+
kubectl delete subns service-4 -n team-a
727+
# forbidden
728+
```
729+
730+
So you need to make `service-4` subnamespace `"allowCascadingDeletion":true` to
731+
delete it.
732+
733+
```bash
734+
kubectl hns set service-4 --allowCascadingDeletion
735+
kubectl get hierarchyconfiguration hierarchy -o jsonpath='{.spec}' -n service-4
736+
```
737+
738+
Expected output:
739+
740+
```bash
741+
{"allowCascadingDeletion":true,"parent":"team-a"}
742+
```
743+
744+
Now, you can delete `service-4`.
690745

691746
```bash
692747
kubectl delete subns service-4 -n team-a
693748
kubectl hns tree team-a
694749
```
750+
695751
Output:
696752
```
697753
team-a
698754
└── [s] service-2
699755
```
700756

701757
The `staging` namespace no longer shows up, because it's no longer a descendant
702-
of `team-a`. However, if you look at it directly, you'll see a warning that it's
758+
of `team-a`.
759+
However, unlike the previous example of `service-1` and `dev`, `staging` namespace will _not_ be deleted alogn with its parent `service-4`.
760+
761+
```bash
762+
$ kubectl get namespace staging
763+
# staging namespace will be listed
764+
```
765+
766+
If you look at it directly, you'll see a warning that it's
703767
in a bad state:
704768

705769
```bash

0 commit comments

Comments
 (0)