From c9088a58cafd5bdfa7fae6b19ca6c75f3fdcbbb9 Mon Sep 17 00:00:00 2001 From: Sunil Shivanand Date: Thu, 4 Apr 2024 00:15:31 +0200 Subject: [PATCH] Add --context option to crossplane cli beta trace command Allows the user to run trace command without switching Kubernetes context. Signed-off-by: Sunil Shivanand --- cmd/crank/beta/trace/trace.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/crank/beta/trace/trace.go b/cmd/crank/beta/trace/trace.go index b113aeb41d4..35fc770725e 100644 --- a/cmd/crank/beta/trace/trace.go +++ b/cmd/crank/beta/trace/trace.go @@ -28,8 +28,8 @@ import ( "k8s.io/client-go/discovery/cached/memory" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/restmapper" - ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/config" "github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/logging" @@ -62,6 +62,7 @@ type Cmd struct { // TODO(phisco): add support for all the usual kubectl flags; configFlags := genericclioptions.NewConfigFlags(true).AddFlags(...) // TODO(phisco): move to namespace defaulting to "" and use the current context's namespace + Context string `default:"" help:"Kubernetes context." name:"context" short:"c"` Namespace string `default:"default" help:"Namespace of the resource." name:"namespace" short:"n"` Output string `default:"default" enum:"default,wide,json,dot" help:"Output format. One of: default, wide, json, dot." name:"output" short:"o"` ShowConnectionSecrets bool `help:"Show connection secrets in the output." name:"show-connection-secrets" short:"s"` @@ -113,7 +114,7 @@ func (c *Cmd) Run(k *kong.Context, logger logging.Logger) error { } logger.Debug("Built printer", "output", c.Output) - kubeconfig, err := ctrl.GetConfig() + kubeconfig, err := config.GetConfigWithContext(c.Context) if err != nil { return errors.Wrap(err, errKubeConfig) }