Skip to content

Promote kubeconfig flags (--kubeconfig/--context/--namespace) to persistent on root #3

Description

@saadqbal

Problem

Today tracebloc cluster info redeclares --kubeconfig, --context, and --namespace as local flags. As we add more cluster-talking subcommands (dataset push, dataset list, future ingest status), each one will need the same three flags. Redeclaring per-command means:

  • The same flag-declaration code gets copy-pasted 4+ times
  • Help text drifts as docs are tweaked per command instead of in one place
  • Default values can silently diverge

Fix

Promote --kubeconfig, --context, --namespace to persistent flags on either the root command or a clusterFlags middleware. Subcommands inherit them automatically.

Implementation sketch (internal/cli/root.go):

typeGlobalFlagsstruct {
KubeconfigstringContextstringNamespacestring
}
funcNewRootCmd(infoBuildInfo) (*cobra.Command, *GlobalFlags) {
flags:=&GlobalFlags{}
root:=&cobra.Command{...}
root.PersistentFlags().StringVar(&flags.Kubeconfig, "kubeconfig", "", "...")
root.PersistentFlags().StringVar(&flags.Context, "context", "", "...")
root.PersistentFlags().StringVarP(&flags.Namespace, "namespace", "n", "", "...")
// Subcommands read flags via the struct rather than redeclaring.root.AddCommand(newClusterCmd(flags))
...returnroot, flags
}

Pass the flags struct through subcommand constructors so each can call cluster.Load(cluster.KubeconfigOptions{Path: flags.Kubeconfig, ...}) consistently.

Acceptance criteria

  • tracebloc --kubeconfig X cluster info and tracebloc cluster info --kubeconfig X both work
  • Same for --context and --namespace / -n
  • Adding a new subcommand that talks to the cluster (Phase 3's dataset push) requires zero per-command flag-declaration
  • Existing cluster info unit tests still pass

Found by

Self-review of PR #2 (Phase 2 cluster discovery). Filed as v0.2 polish so it doesn't gate the v0.1 push-only MVP.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions