Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support List based resources in the KindSortOrder. #12915

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 27 additions & 45 deletions pkg/releaseutil/kind_sorter.go
Expand Up @@ -25,10 +25,10 @@ import (
// KindSortOrder is an ordering of Kinds.
type KindSortOrder []string

// InstallOrder is the order in which manifests should be installed (by Kind).
// ResourceDependencyOrder 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 KindSortOrder = []string{
var ResourceDependencyOrder KindSortOrder = []string{
"PriorityClass",
"Namespace",
"NetworkPolicy",
Expand All @@ -38,20 +38,15 @@ var InstallOrder KindSortOrder = []string{
"PodDisruptionBudget",
"ServiceAccount",
"Secret",
"SecretList",
"ConfigMap",
"StorageClass",
"PersistentVolume",
"PersistentVolumeClaim",
"CustomResourceDefinition",
"ClusterRole",
"ClusterRoleList",
"ClusterRoleBinding",
"ClusterRoleBindingList",
"Role",
"RoleList",
"RoleBinding",
"RoleBindingList",
"Service",
"DaemonSet",
"Pod",
Expand All @@ -67,47 +62,34 @@ var InstallOrder KindSortOrder = []string{
"APIService",
}

// addListKind adds the List equivalent for each resource kind in the list.
func addListKind(resources KindSortOrder) KindSortOrder {
output := make(KindSortOrder, 0, 2*len(resources))
for _, resource := range resources {
output = append(output, resource)
output = append(output, resource+"List")
}
return output
}

// reverseKindOrder reverses the order of the KindSortOrder.
func reverseKindOrder(resources KindSortOrder) KindSortOrder {
for i := 0; i < len(resources)/2; i++ {
j := len(resources) - i - 1
resources[i], resources[j] = resources[j], resources[i]
}
return resources
}

// 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 = addListKind(ResourceDependencyOrder)

// 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 KindSortOrder = []string{
"APIService",
"Ingress",
"IngressClass",
"Service",
"CronJob",
"Job",
"StatefulSet",
"HorizontalPodAutoscaler",
"Deployment",
"ReplicaSet",
"ReplicationController",
"Pod",
"DaemonSet",
"RoleBindingList",
"RoleBinding",
"RoleList",
"Role",
"ClusterRoleBindingList",
"ClusterRoleBinding",
"ClusterRoleList",
"ClusterRole",
"CustomResourceDefinition",
"PersistentVolumeClaim",
"PersistentVolume",
"StorageClass",
"ConfigMap",
"SecretList",
"Secret",
"ServiceAccount",
"PodDisruptionBudget",
"PodSecurityPolicy",
"LimitRange",
"ResourceQuota",
"NetworkPolicy",
"Namespace",
"PriorityClass",
}
var UninstallOrder = reverseKindOrder(addListKind(ResourceDependencyOrder))

// sort manifests by kind.
//
Expand Down
2 changes: 1 addition & 1 deletion pkg/releaseutil/kind_sorter_test.go
Expand Up @@ -181,7 +181,7 @@ func TestKindSorter(t *testing.T) {
expected string
}{
{"install", InstallOrder, "FaAbcC3deEf1gh2iIjJkKlLmnopqrxstuUvw!"},
{"uninstall", UninstallOrder, "wvUmutsxrqponLlKkJjIi2hg1fEed3CcbAaF!"},
{"uninstall", UninstallOrder, "wvUutsxrqponmLlKkJjIi2hg1fEed3CcbAaF!"},
} {
var buf bytes.Buffer
t.Run(test.description, func(t *testing.T) {
Expand Down