use Helm apply order when rendering manifest lists
see lillecarl/nix-csi#3
This commit is contained in:
parent
ee514e736b
commit
88a025fc04
1 changed files with 59 additions and 2 deletions
61
internal.nix
61
internal.nix
|
|
@ -9,6 +9,63 @@
|
|||
type = lib.types.anything;
|
||||
};
|
||||
config.internal = rec {
|
||||
# https://github.com/helm/helm/blob/4a91f3ad5cc0c1521f6d4dcb5681e2da4baaa157/pkg/release/v1/util/kind_sorter.go#L31
|
||||
helmOrder = [
|
||||
"PriorityClass"
|
||||
"Namespace"
|
||||
"NetworkPolicy"
|
||||
"ResourceQuota"
|
||||
"LimitRange"
|
||||
"PodSecurityPolicy"
|
||||
"PodDisruptionBudget"
|
||||
"ServiceAccount"
|
||||
"Secret"
|
||||
"SecretList"
|
||||
"ConfigMap"
|
||||
"StorageClass"
|
||||
"PersistentVolume"
|
||||
"PersistentVolumeClaim"
|
||||
"CustomResourceDefinition"
|
||||
"ClusterRole"
|
||||
"ClusterRoleList"
|
||||
"ClusterRoleBinding"
|
||||
"ClusterRoleBindingList"
|
||||
"Role"
|
||||
"RoleList"
|
||||
"RoleBinding"
|
||||
"RoleBindingList"
|
||||
"Service"
|
||||
"DaemonSet"
|
||||
"Pod"
|
||||
"ReplicationController"
|
||||
"ReplicaSet"
|
||||
"Deployment"
|
||||
"HorizontalPodAutoscaler"
|
||||
"StatefulSet"
|
||||
"Job"
|
||||
"CronJob"
|
||||
"IngressClass"
|
||||
"Ingress"
|
||||
"APIService"
|
||||
"MutatingWebhookConfiguration"
|
||||
"ValidatingWebhookConfiguration"
|
||||
];
|
||||
|
||||
# Map kind -> priority (index in helmOrder)
|
||||
applyPriorities = lib.listToAttrs (
|
||||
lib.imap0 (i: kind: {
|
||||
name = kind;
|
||||
value = i;
|
||||
}) helmOrder
|
||||
);
|
||||
|
||||
# Get priority for a kind, default to end if not in list
|
||||
getApplyPriority = kind: applyPriorities.${kind} or (lib.length helmOrder);
|
||||
|
||||
generatedOrdered = lib.sort (
|
||||
a: b: (getApplyPriority a.kind) < (getApplyPriority b.kind)
|
||||
) config.kubernetes.generated;
|
||||
|
||||
# Makes a valid YAML string, supports multiple documents or single attrsets,
|
||||
# documents will be JSON formatted since Nix can't render YAML.
|
||||
toYAMLStr =
|
||||
|
|
@ -40,7 +97,7 @@
|
|||
manifestAttrs = {
|
||||
apiVersion = "v1";
|
||||
kind = "List";
|
||||
items = config.kubernetes.generated;
|
||||
items = generatedOrdered;
|
||||
};
|
||||
manifestJSON = builtins.toJSON manifestAttrs;
|
||||
manifestJSONFile = pkgs.writeText "manifest.json" manifestJSON;
|
||||
|
|
@ -52,6 +109,6 @@
|
|||
${lib.getExe pkgs.yq} --yaml-output '.' ${manifestJSONFile} > $out
|
||||
'';
|
||||
manifestYAML = builtins.readFile manifestYAMLFile;
|
||||
manifestYAMLFile = toYAMLFile "manifest.yaml" config.kubernetes.generated;
|
||||
manifestYAMLFile = toYAMLFile "nix-csi.yaml" generatedOrdered;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue