Skip to content

Instantly share code, notes, and snippets.

@dreverri
Created March 27, 2019 17:51
Show Gist options
  • Save dreverri/75e848099cbbccc7cdc22ac350c81fdc to your computer and use it in GitHub Desktop.
Save dreverri/75e848099cbbccc7cdc22ac350c81fdc to your computer and use it in GitHub Desktop.
local safeGet = function(name) function(o, default={}) if std.objectHas(o, name) then o[name] else default;
local metadata = safeGet("metadata");
local name = safeGet("name");
local namespace = safeGet("namespace");
local kind = safeGet("kind");
local kindPriority = std.foldl(function(o, k) o { [k]: std.length(o) }, [
"Namespace",
"ResourceQuota",
"LimitRange",
"PodSecurityPolicy",
"PodDisruptionBudget",
"Secret",
"ConfigMap",
"StorageClass",
"PersistentVolume",
"PersistentVolumeClaim",
"ServiceAccount",
"CustomResourceDefinition",
"ClusterRole",
"ClusterRoleBinding",
"Role",
"RoleBinding",
"Service",
"DaemonSet",
"Pod",
"ReplicationController",
"ReplicaSet",
"Deployment",
"StatefulSet",
"Job",
"CronJob",
"Ingress",
"APIService",
], {});
local priority = function(kind) if std.objectHas(kindPriority, kind) then kindPriority[kind] else std.length(kindPriority);
local keyF = function(o) std.format("%02d/%s/%s/%s", [priority(kind(o, "")), namespace(metadata(o), ""), kind(o, ""), name(metadata(o), "")]);
keyF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment