Add more object kinds to sorted installation order

The following kinds are newly addressed:

  CronJob
  LimitRange
  ReplicaSet
  ResourceQuota
  StatefulSet

Furthermore, adjust the installation and uninstallation order to
better respect likely dependencies. Bare pods remain a difficult one
to place properly in both sequences.
pull/2203/head
Steven E. Harris 8 years ago
parent 890b6f5627
commit 4178ec08ac

@ -24,8 +24,12 @@ import (
type SortOrder []string type SortOrder []string
// InstallOrder is the order in which manifests should be installed (by Kind). // InstallOrder is the order in which manifests should be installed (by Kind).
//
// Those occurring earlier in the list get installed before those occurring later in the list.
var InstallOrder SortOrder = []string{ var InstallOrder SortOrder = []string{
"Namespace", "Namespace",
"ResourceQuota",
"LimitRange",
"Secret", "Secret",
"ConfigMap", "ConfigMap",
"PersistentVolume", "PersistentVolume",
@ -36,32 +40,42 @@ var InstallOrder SortOrder = []string{
"Role", "Role",
"RoleBinding", "RoleBinding",
"Service", "Service",
"DaemonSet",
"Pod", "Pod",
"ReplicationController", "ReplicationController",
"ReplicaSet",
"Deployment", "Deployment",
"DaemonSet", "StatefulSet",
"Ingress",
"Job", "Job",
"CronJob",
"Ingress",
} }
// UninstallOrder is the order in which manifests should be uninstalled (by Kind). // UninstallOrder is the order in which manifests should be uninstalled (by Kind).
//
// Those occurring earlier in the list get uninstalled before those occurring later in the list.
var UninstallOrder SortOrder = []string{ var UninstallOrder SortOrder = []string{
"Ingress",
"Service", "Service",
"Pod", "CronJob",
"ReplicationController", "Job",
"StatefulSet",
"Deployment", "Deployment",
"ReplicaSet",
"ReplicationController",
"Pod",
"DaemonSet", "DaemonSet",
"ConfigMap",
"Secret",
"PersistentVolumeClaim",
"PersistentVolume",
"RoleBinding", "RoleBinding",
"Role", "Role",
"ClusterRoleBinding", "ClusterRoleBinding",
"ClusterRole", "ClusterRole",
"ServiceAccount", "ServiceAccount",
"Ingress", "PersistentVolumeClaim",
"Job", "PersistentVolume",
"ConfigMap",
"Secret",
"LimitRange",
"ResourceQuota",
"Namespace", "Namespace",
} }

@ -26,12 +26,12 @@ import (
func TestKindSorter(t *testing.T) { func TestKindSorter(t *testing.T) {
manifests := []manifest{ manifests := []manifest{
{ {
name: "m", name: "i",
content: "", content: "",
head: &util.SimpleHead{Kind: "ClusterRole"}, head: &util.SimpleHead{Kind: "ClusterRole"},
}, },
{ {
name: " ", name: "j",
content: "", content: "",
head: &util.SimpleHead{Kind: "ClusterRoleBinding"}, head: &util.SimpleHead{Kind: "ClusterRoleBinding"},
}, },
@ -41,7 +41,17 @@ func TestKindSorter(t *testing.T) {
head: &util.SimpleHead{Kind: "ConfigMap"}, head: &util.SimpleHead{Kind: "ConfigMap"},
}, },
{ {
name: "k", name: "u",
content: "",
head: &util.SimpleHead{Kind: "CronJob"},
},
{
name: "n",
content: "",
head: &util.SimpleHead{Kind: "DaemonSet"},
},
{
name: "r",
content: "", content: "",
head: &util.SimpleHead{Kind: "Deployment"}, head: &util.SimpleHead{Kind: "Deployment"},
}, },
@ -51,35 +61,85 @@ func TestKindSorter(t *testing.T) {
head: &util.SimpleHead{Kind: "HonkyTonkSet"}, head: &util.SimpleHead{Kind: "HonkyTonkSet"},
}, },
{ {
name: "s", name: "v",
content: "",
head: &util.SimpleHead{Kind: "Ingress"},
},
{
name: "t",
content: "", content: "",
head: &util.SimpleHead{Kind: "Job"}, head: &util.SimpleHead{Kind: "Job"},
}, },
{ {
name: "h", name: "c",
content: "",
head: &util.SimpleHead{Kind: "LimitRange"},
},
{
name: "a",
content: "", content: "",
head: &util.SimpleHead{Kind: "Namespace"}, head: &util.SimpleHead{Kind: "Namespace"},
}, },
{ {
name: "w", name: "f",
content: "", content: "",
head: &util.SimpleHead{Kind: "Role"}, head: &util.SimpleHead{Kind: "PersistentVolume"},
},
{
name: "g",
content: "",
head: &util.SimpleHead{Kind: "PersistentVolumeClaim"},
}, },
{ {
name: "o", name: "o",
content: "", content: "",
head: &util.SimpleHead{Kind: "Pod"},
},
{
name: "q",
content: "",
head: &util.SimpleHead{Kind: "ReplicaSet"},
},
{
name: "p",
content: "",
head: &util.SimpleHead{Kind: "ReplicationController"},
},
{
name: "b",
content: "",
head: &util.SimpleHead{Kind: "ResourceQuota"},
},
{
name: "k",
content: "",
head: &util.SimpleHead{Kind: "Role"},
},
{
name: "l",
content: "",
head: &util.SimpleHead{Kind: "RoleBinding"}, head: &util.SimpleHead{Kind: "RoleBinding"},
}, },
{ {
name: "r", name: "d",
content: "",
head: &util.SimpleHead{Kind: "Secret"},
},
{
name: "m",
content: "", content: "",
head: &util.SimpleHead{Kind: "Service"}, head: &util.SimpleHead{Kind: "Service"},
}, },
{ {
name: "l", name: "h",
content: "", content: "",
head: &util.SimpleHead{Kind: "ServiceAccount"}, head: &util.SimpleHead{Kind: "ServiceAccount"},
}, },
{
name: "s",
content: "",
head: &util.SimpleHead{Kind: "StatefulSet"},
},
} }
for _, test := range []struct { for _, test := range []struct {
@ -87,11 +147,14 @@ func TestKindSorter(t *testing.T) {
order SortOrder order SortOrder
expected string expected string
}{ }{
{"install", InstallOrder, "helm works!"}, {"install", InstallOrder, "abcdefghijklmnopqrstuv!"},
{"uninstall", UninstallOrder, "rkeow mlsh!"}, {"uninstall", UninstallOrder, "vmutsrqponlkjihgfedcba!"},
} { } {
var buf bytes.Buffer var buf bytes.Buffer
t.Run(test.description, func(t *testing.T) { t.Run(test.description, func(t *testing.T) {
if got, want := len(test.expected), len(manifests); got != want {
t.Fatalf("Expected %d names in order, got %d", want, got)
}
defer buf.Reset() defer buf.Reset()
for _, r := range sortByKind(manifests, test.order) { for _, r := range sortByKind(manifests, test.order) {
buf.WriteString(r.name) buf.WriteString(r.name)

Loading…
Cancel
Save