feat: add --context flag to scheduler-k3s:preview

Users can override the default 3-line surrounding context per change. Pass
`--context -1` to render the full resource around every change, matching
upstream `helm diff upgrade` behavior.
This commit is contained in:
Jose Diaz-Gonzalez
2026-06-02 21:02:43 -04:00
parent 496ede44b7
commit e8671790b5
4 changed files with 16 additions and 5 deletions

View File

@@ -21,7 +21,10 @@ import (
// in the live Helm release for an app and the manifests that the next deploy
// would roll out. Only the main app helm release is compared; the auxiliary
// config-secret, image-pull-secret, and TLS-secret releases are out of scope.
func CommandPreview(appName string, showSecrets bool, showSecretsDecoded bool) error {
//
// diffContext controls the number of unchanged lines shown around each change;
// pass -1 to print the full resource.
func CommandPreview(appName string, diffContext int, showSecrets bool, showSecretsDecoded bool) error {
if err := common.VerifyAppName(appName); err != nil {
return err
}
@@ -80,7 +83,7 @@ func CommandPreview(appName string, showSecrets bool, showSecretsDecoded bool) e
options := &helmdiff.Options{
OutputFormat: "diff",
OutputContext: 3,
OutputContext: diffContext,
ShowSecrets: showSecrets,
ShowSecretsDecoded: showSecretsDecoded,
}

View File

@@ -29,7 +29,7 @@ Additional commands:`
scheduler-k3s:initialize [--server-ip SERVER_IP] [--taint-scheduling], Initializes a cluster
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: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:preview <app> [--show-secrets] [--show-secrets-decoded], Displays a diff between the current and next deployment for an app
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
scheduler-k3s:profiles:list [--format json|stdout], Lists all node profiles in the k3s cluster
scheduler-k3s:profiles:remove <profile>, Removes a node profile from the k3s cluster

View File

@@ -160,11 +160,12 @@ func main() {
err = scheduler_k3s.CommandLabelsReport(appName, *format, *processType, *resourceType, infoFlag)
case "preview":
args := flag.NewFlagSet("scheduler-k3s:preview", flag.ExitOnError)
context := args.Int("context", 3, "--context: number of unchanged lines of context around each change (-1 for full output)")
showSecrets := args.Bool("show-secrets", false, "--show-secrets: do not redact secret values in the output")
showSecretsDecoded := args.Bool("show-secrets-decoded", false, "--show-secrets-decoded: render secret values base64-decoded")
args.Parse(os.Args[2:])
appName := args.Arg(0)
err = scheduler_k3s.CommandPreview(appName, *showSecrets, *showSecretsDecoded)
err = scheduler_k3s.CommandPreview(appName, *context, *showSecrets, *showSecretsDecoded)
case "profiles:add":
args := flag.NewFlagSet("scheduler-k3s:profiles:add", flag.ExitOnError)
role := args.String("role", "worker", "role: [ server | worker ]")