Repository: helm/helm
Pull request #6624 (2019-10-09 21:50:29)

Add missing k8s objects to InstallOrder
**What this PR does / why we need it:**
Added NetworkPolicy, PodDisruptionBudget, and PodSecurityPolicy to InstallOrder

**Special notes for your reviewer**:
This PR is a port of #6266 #4769 #3899 to Helm 3.

- [x] this PR contains unit tests


bacongobbler: Thanks @dmitrytokarev. It looks like the unit test for kind_sorter_test.go failed. Would you please look into that?

```
--- FAIL: TestKindSorter (0.00s)
    --- FAIL: TestKindSorter/uninstall (0.00s)
        kind_sorter_test.go:182: Expected "wvmutsxrqponLlKkJjIi2hgf1ed3CcbAa!", got "wvmutsxrqponLlKkJjIi2hgf1edcba!A3C"
```
dmitrytokarev: @bacongobbler  sorry for not running tests locally, fixed now. Tests passed locally.

Patch:
diff --git a/cmd/helm/flags.go b/cmd/helm/flags.go
index 09676e658..32d5b891b 100644
--- a/cmd/helm/flags.go
+++ b/cmd/helm/flags.go
@@ -52,6 +52,8 @@ func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) {
 // value to the given format pointer
 func bindOutputFlag(cmd *cobra.Command, varRef *output.Format) {
 	cmd.Flags().VarP(newOutputValue(output.Table, varRef), outputFlag, "o", fmt.Sprintf("prints the output in the specified format. Allowed values: %s, %s, %s", output.Table, output.JSON, output.YAML))
+	// Setup shell completion for the flag
+	cmd.MarkFlagCustom(outputFlag, "__helm_output_options")
 }
 
 type outputValue output.Format
diff --git a/cmd/helm/root.go b/cmd/helm/root.go
index eccb49fa0..e28e8bdfb 100644
--- a/cmd/helm/root.go
+++ b/cmd/helm/root.go
@@ -89,6 +89,12 @@ __helm_get_namespaces()
     fi
 }
 
+__helm_output_options()
+{
+    __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
+    COMPREPLY+=( $( compgen -W "table json yaml" -- "$cur" ) )
+}
+
 __helm_binary_name()
 {
     local helm_binary
diff --git a/pkg/releaseutil/kind_sorter.go b/pkg/releaseutil/kind_sorter.go
index b1b2c58db..a5110a100 100644
--- a/pkg/releaseutil/kind_sorter.go
+++ b/pkg/releaseutil/kind_sorter.go
@@ -26,8 +26,11 @@ type KindSortOrder []string
 // Those occurring earlier in the list get installed before those occurring later in the list.
 var InstallOrder KindSortOrder = []string{
 	"Namespace",
+	"NetworkPolicy",
 	"ResourceQuota",
 	"LimitRange",
+	"PodSecurityPolicy",
+	"PodDisruptionBudget",
 	"Secret",
 	"ConfigMap",
 	"StorageClass",
@@ -88,8 +91,11 @@ var UninstallOrder KindSortOrder = []string{
 	"StorageClass",
 	"ConfigMap",
 	"Secret",
+	"PodDisruptionBudget",
+	"PodSecurityPolicy",
 	"LimitRange",
 	"ResourceQuota",
+	"NetworkPolicy",
 	"Namespace",
 }
 


Test patch:
diff --git a/pkg/releaseutil/kind_sorter_test.go b/pkg/releaseutil/kind_sorter_test.go
index cfaa3a771..93d8ae782 100644
--- a/pkg/releaseutil/kind_sorter_test.go
+++ b/pkg/releaseutil/kind_sorter_test.go
@@ -79,6 +79,10 @@ func TestKindSorter(t *testing.T) {
 			Name: "a",
 			Head: &SimpleHead{Kind: "Namespace"},
 		},
+		{
+			Name: "A",
+			Head: &SimpleHead{Kind: "NetworkPolicy"},
+		},
 		{
 			Name: "f",
 			Head: &SimpleHead{Kind: "PersistentVolume"},
@@ -91,6 +95,14 @@ func TestKindSorter(t *testing.T) {
 			Name: "o",
 			Head: &SimpleHead{Kind: "Pod"},
 		},
+		{
+			Name: "3",
+			Head: &SimpleHead{Kind: "PodDisruptionBudget"},
+		},
+		{
+			Name: "C",
+			Head: &SimpleHead{Kind: "PodSecurityPolicy"},
+		},
 		{
 			Name: "q",
 			Head: &SimpleHead{Kind: "ReplicaSet"},
@@ -154,8 +166,8 @@ func TestKindSorter(t *testing.T) {
 		order       KindSortOrder
 		expected    string
 	}{
-		{"install", InstallOrder, "abcde1fgh2iIjJkKlLmnopqrxstuvw!"},
-		{"uninstall", UninstallOrder, "wvmutsxrqponLlKkJjIi2hgf1edcba!"},
+		{"install", InstallOrder, "aAbcC3de1fgh2iIjJkKlLmnopqrxstuvw!"},
+		{"uninstall", UninstallOrder, "wvmutsxrqponLlKkJjIi2hgf1ed3CcbAa!"},
 	} {
 		var buf bytes.Buffer
 		t.Run(test.description, func(t *testing.T) {