feat: add a whole-set form for scheduler-k3s metadata

The `scheduler-k3s` metadata commands were all per-key, so matching an app's stored annotations, labels or node sysctls to a declared set meant reading the report, computing the difference in both directions and issuing one command per added, changed and removed key, with a failure partway through leaving a mixture of the two sets. A `--replace` flag on `annotations:set`, `labels:set`, `node-sysctls:set` and `autoscaling-auth:set` now writes the declared map in a single call, taking trailing `key=value` pairs everywhere except `autoscaling-auth:set`, which keeps its repeatable `--metadata` flag. Every pair is parsed before anything is written, so a rejected pair leaves the stored map untouched, and a pair ending in `=` stores an empty value, which the per-key form cannot express. An empty pair list is rejected rather than treated as a request to remove everything, so a generated list that expands to nothing cannot silently drop an app's metadata; `annotations:clear`, `labels:clear` and `node-sysctls:clear` handle that case, taking the same optional filters as their report commands. The `--resource-type` flag and the app name are now validated on the set commands as well, where a typo previously exited zero and wrote a property that no report and no deploy ever read.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-18 05:14:51 -04:00
1 parent 55ffe6809b
commit c37a71b90b
12 files changed
+1271 -195

No files matched your search

@@ -17,9 +17,12 @@ Manage scheduler-k3s settings for an app
Additional commands:`
helpContent = `
scheduler-k3s:annotations:clear <app|--global> [--process-type PROCESS_TYPE] [--resource-type RESOURCE_TYPE], Clear all annotations for an app or a single process-type/resource-type scope
scheduler-k3s:annotations:set <app|--global> <property> (<value>) [--process-type PROCESS_TYPE] <--resource-type RESOURCE_TYPE>, Set or clear an annotation for a given app/process-type/resource-type combination
scheduler-k3s:annotations:set --replace <app|--global> <key=value> [<key=value> ...] [--process-type PROCESS_TYPE] <--resource-type RESOURCE_TYPE>, Replace the entire annotation map for a given app/process-type/resource-type combination
scheduler-k3s:annotations:report [<app>|--global] [--format stdout|json] [--process-type PROCESS_TYPE] [--resource-type RESOURCE_TYPE], Displays a scheduler-k3s annotations report for one or more apps
scheduler-k3s:autoscaling-auth:set <app|--global> <trigger> [<--metadata key=value>...], Set or clear a scheduler-k3s autoscaling keda trigger authentication resource for an app
scheduler-k3s:autoscaling-auth:set --replace <app|--global> <trigger> <--metadata key=value> [<--metadata key=value>...], Replace the entire metadata map for a scheduler-k3s autoscaling keda trigger authentication resource
scheduler-k3s:autoscaling-auth:report [<app>|--global] [--format stdout|json] [--include-metadata], Displays a scheduler-k3s autoscaling auth report for one or more apps
scheduler-k3s:charts:report [<chart>] [--format stdout|json], Displays a scheduler-k3s chart override report
scheduler-k3s:charts:set <chart-name.property> (<value>), Set or clear a chart-specific helm value
@@ -28,9 +31,13 @@ Additional commands:`
scheduler-k3s:cluster:remove [node-id], Removes client node to a Dokku-managed cluster
scheduler-k3s:ensure-charts, Ensures the k3s charts are installed
scheduler-k3s:initialize [--server-ip SERVER_IP] [--taint-scheduling] [--kubelet-args KUBELET_ARGS], Initializes a cluster
scheduler-k3s:labels:clear <app|--global> [--process-type PROCESS_TYPE] [--resource-type RESOURCE_TYPE], Clear all labels for an app or a single process-type/resource-type scope
scheduler-k3s:labels:set <app|--global> <property> (<value>) [--process-type PROCESS_TYPE] <--resource-type RESOURCE_TYPE>, Set or clear a label for a given app/process-type/resource-type combination
scheduler-k3s:labels:set --replace <app|--global> <key=value> [<key=value> ...] [--process-type PROCESS_TYPE] <--resource-type RESOURCE_TYPE>, Replace the entire label map for a given app/process-type/resource-type combination
scheduler-k3s:labels:report [<app>|--global] [--format stdout|json] [--process-type PROCESS_TYPE] [--resource-type RESOURCE_TYPE], Displays a scheduler-k3s labels report for one or more apps
scheduler-k3s:node-sysctls:clear [--global|--profile PROFILE], Clear all node-level kernel sysctls for unprofiled nodes or a single node profile
scheduler-k3s:node-sysctls:set <sysctl> (<value>) [--global|--profile PROFILE], Set or clear a node-level kernel sysctl for unprofiled nodes or a single node profile
scheduler-k3s:node-sysctls:set --replace <sysctl=value> [<sysctl=value> ...] [--global|--profile PROFILE], Replace the entire node-level kernel sysctl map for unprofiled nodes or a single node profile
scheduler-k3s:node-sysctls:report [--format stdout|json], Displays the node-level kernel sysctls applied to each scope
scheduler-k3s:preview <app> [--context N] [--show-secrets] [--show-secrets-decoded], Displays a diff between the current and next deployment for an app
scheduler-k3s:profiles:add <profile> [--role ROLE] [--insecure-allow-unknown-hosts] [--taint-scheduling] [--kubelet-args KUBELET_ARGS], Adds a node profile to the k3s cluster
@@ -18,22 +18,50 @@ func main() {
var err error
switch subcommand {
case "annotations:clear":
args := flag.NewFlagSet("scheduler-k3s:annotations:clear", flag.ExitOnError)
global := args.Bool("global", false, "--global: clear global annotations")
processType := args.String("process-type", "", "--process-type: filter by process-type")
resourceType := args.String("resource-type", "", "--resource-type: filter by resource-type")
args.Parse(os.Args[2:])
appName := args.Arg(0)
if *global {
appName = "--global"
}
err = scheduler_k3s.CommandAnnotationsClear(scheduler_k3s.MetadataClearInput{
AppName: appName,
ProcessType: *processType,
ResourceType: *resourceType,
})
case "annotations:set":
args := flag.NewFlagSet("scheduler-k3s:annotations:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: set a global property")
processType := args.String("process-type", "", "--process-type: scope to process-type")
resourceType := args.String("resource-type", "", "--resource-type: scope to resource-type")
replace := args.Bool("replace", false, "--replace: replace the entire annotation map for the scope")
args.Parse(os.Args[2:])
appName := args.Arg(0)
property := args.Arg(1)
value := args.Arg(2)
if *global {
appName = "--global"
property = args.Arg(0)
value = args.Arg(1)
input := scheduler_k3s.MetadataSetInput{
AppName: args.Arg(0),
ProcessType: *processType,
ResourceType: *resourceType,
Replace: *replace,
}
err = scheduler_k3s.CommandAnnotationsSet(appName, *processType, *resourceType, property, value)
skip := 1
if *global {
input.AppName = "--global"
skip = 0
}
if *replace {
input.Pairs = common.VarArgs(args.Args(), skip)
} else {
input.Key = args.Arg(skip)
input.Value = args.Arg(skip + 1)
}
err = scheduler_k3s.CommandAnnotationsSet(input)
case "annotations:report":
args := flag.NewFlagSet("scheduler-k3s:annotations:report", flag.ExitOnError)
global := args.Bool("global", false, "--global: show the global report")
@@ -55,6 +83,7 @@ func main() {
args := flag.NewFlagSet("scheduler-k3s:autoscaling-auth:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: set a global property")
metadata := args.StringToString("metadata", map[string]string{}, "--metadata: a key=value map of parameter metadata")
replace := args.Bool("replace", false, "--replace: replace the entire metadata map for the trigger")
args.Parse(os.Args[2:])
appName := args.Arg(0)
trigger := args.Arg(1)
@@ -62,7 +91,7 @@ func main() {
appName = "--global"
trigger = args.Arg(0)
}
err = scheduler_k3s.CommandAutoscalingAuthSet(appName, trigger, *metadata, *global)
err = scheduler_k3s.CommandAutoscalingAuthSet(appName, trigger, *metadata, *global, *replace)
case "autoscaling-auth:report":
args := flag.NewFlagSet("scheduler-k3s:autoscaling-auth:report", flag.ExitOnError)
global := args.Bool("global", false, "--global: show the global report")
@@ -131,22 +160,50 @@ func main() {
kubeletArgs := args.StringSlice("kubelet-args", []string{}, "kubelet-args: repeatable key=value kubelet arguments (e.g., --kubelet-args key=value)")
args.Parse(os.Args[2:])
err = scheduler_k3s.CommandInitialize(*ingressClass, *serverIP, *taintScheduling, *kubeletArgs)
case "labels:clear":
args := flag.NewFlagSet("scheduler-k3s:labels:clear", flag.ExitOnError)
global := args.Bool("global", false, "--global: clear global labels")
processType := args.String("process-type", "", "--process-type: filter by process-type")
resourceType := args.String("resource-type", "", "--resource-type: filter by resource-type")
args.Parse(os.Args[2:])
appName := args.Arg(0)
if *global {
appName = "--global"
}
err = scheduler_k3s.CommandLabelsClear(scheduler_k3s.MetadataClearInput{
AppName: appName,
ProcessType: *processType,
ResourceType: *resourceType,
})
case "labels:set":
args := flag.NewFlagSet("scheduler-k3s:labels:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: set a global property")
processType := args.String("process-type", "", "--process-type: scope to process-type")
resourceType := args.String("resource-type", "", "--resource-type: scope to resource-type")
replace := args.Bool("replace", false, "--replace: replace the entire label map for the scope")
args.Parse(os.Args[2:])
appName := args.Arg(0)
property := args.Arg(1)
value := args.Arg(2)
if *global {
appName = "--global"
property = args.Arg(0)
value = args.Arg(1)
input := scheduler_k3s.MetadataSetInput{
AppName: args.Arg(0),
ProcessType: *processType,
ResourceType: *resourceType,
Replace: *replace,
}
err = scheduler_k3s.CommandLabelsSet(appName, *processType, *resourceType, property, value)
skip := 1
if *global {
input.AppName = "--global"
skip = 0
}
if *replace {
input.Pairs = common.VarArgs(args.Args(), skip)
} else {
input.Key = args.Arg(skip)
input.Value = args.Arg(skip + 1)
}
err = scheduler_k3s.CommandLabelsSet(input)
case "labels:report":
args := flag.NewFlagSet("scheduler-k3s:labels:report", flag.ExitOnError)
global := args.Bool("global", false, "--global: show the global report")
@@ -164,18 +221,39 @@ func main() {
appName = "--global"
}
err = scheduler_k3s.CommandLabelsReport(appName, *format, *processType, *resourceType, infoFlag)
case "node-sysctls:set":
args := flag.NewFlagSet("scheduler-k3s:node-sysctls:set", flag.ExitOnError)
case "node-sysctls:clear":
args := flag.NewFlagSet("scheduler-k3s:node-sysctls:clear", flag.ExitOnError)
global := args.Bool("global", false, "--global: scope to all nodes without a node profile")
profileName := args.String("profile", "", "--profile: scope to a node profile instead of all unprofiled nodes")
args.Parse(os.Args[2:])
key := args.Arg(0)
value := args.Arg(1)
if *global && *profileName != "" {
err = fmt.Errorf("Only one of --global and --profile may be specified")
break
}
err = scheduler_k3s.CommandNodeSysctlsSet(*profileName, key, value)
err = scheduler_k3s.CommandNodeSysctlsClear(*profileName)
case "node-sysctls:set":
args := flag.NewFlagSet("scheduler-k3s:node-sysctls:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: scope to all nodes without a node profile")
profileName := args.String("profile", "", "--profile: scope to a node profile instead of all unprofiled nodes")
replace := args.Bool("replace", false, "--replace: replace the entire sysctl map for the scope")
args.Parse(os.Args[2:])
if *global && *profileName != "" {
err = fmt.Errorf("Only one of --global and --profile may be specified")
break
}
input := scheduler_k3s.NodeSysctlsSetInput{
ProfileName: *profileName,
Replace: *replace,
}
if *replace {
input.Pairs = args.Args()
} else {
input.Key = args.Arg(0)
input.Value = args.Arg(1)
}
err = scheduler_k3s.CommandNodeSysctlsSet(input)
case "node-sysctls:report":
args := flag.NewFlagSet("scheduler-k3s:node-sysctls:report", flag.ExitOnError)
format := args.String("format", "stdout", "format: [ stdout | json ]")