From 8ef1e95fa7f915dd1cba34d68ab42212389a0327 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Thu, 31 Oct 2024 14:30:25 -0700 Subject: [PATCH] fix deployments cmd --- internal/cmd/local/local.go | 21 +++++++++++++++++++++ internal/cmd/local/local_credentials.go | 21 --------------------- internal/cmd/local/local_deployments.go | 7 ++++++- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/internal/cmd/local/local.go b/internal/cmd/local/local.go index 597a0dc..1fbf503 100644 --- a/internal/cmd/local/local.go +++ b/internal/cmd/local/local.go @@ -10,6 +10,8 @@ import ( "github.com/airbytehq/abctl/internal/cmd/local/localerr" "github.com/airbytehq/abctl/internal/cmd/local/paths" "github.com/pterm/pterm" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/clientcmd" ) type Cmd struct { @@ -72,3 +74,22 @@ func checkAirbyteDir() error { return nil } + +// defaultK8s returns the default k8s client for the provided kubecfg and kubectx. +func defaultK8s(kubecfg, kubectx string) (k8s.Client, error) { + k8sCfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( + &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubecfg}, + &clientcmd.ConfigOverrides{CurrentContext: kubectx}, + ) + + restCfg, err := k8sCfg.ClientConfig() + if err != nil { + return nil, fmt.Errorf("%w: could not create rest config: %w", localerr.ErrKubernetes, err) + } + k8sClient, err := kubernetes.NewForConfig(restCfg) + if err != nil { + return nil, fmt.Errorf("%w: could not create clientset: %w", localerr.ErrKubernetes, err) + } + + return &k8s.DefaultK8sClient{ClientSet: k8sClient}, nil +} diff --git a/internal/cmd/local/local_credentials.go b/internal/cmd/local/local_credentials.go index 8e2642d..743e71b 100644 --- a/internal/cmd/local/local_credentials.go +++ b/internal/cmd/local/local_credentials.go @@ -6,12 +6,9 @@ import ( "github.com/airbytehq/abctl/internal/cmd/local/airbyte" "github.com/airbytehq/abctl/internal/cmd/local/k8s" - "github.com/airbytehq/abctl/internal/cmd/local/localerr" "github.com/airbytehq/abctl/internal/telemetry" "github.com/pterm/pterm" "go.opencensus.io/trace" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/clientcmd" ) const ( @@ -106,21 +103,3 @@ func (cc *CredentialsCmd) Run(ctx context.Context, provider k8s.Provider, telCli return nil }) } - -func defaultK8s(kubecfg, kubectx string) (k8s.Client, error) { - k8sCfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubecfg}, - &clientcmd.ConfigOverrides{CurrentContext: kubectx}, - ) - - restCfg, err := k8sCfg.ClientConfig() - if err != nil { - return nil, fmt.Errorf("%w: could not create rest config: %w", localerr.ErrKubernetes, err) - } - k8sClient, err := kubernetes.NewForConfig(restCfg) - if err != nil { - return nil, fmt.Errorf("%w: could not create clientset: %w", localerr.ErrKubernetes, err) - } - - return &k8s.DefaultK8sClient{ClientSet: k8sClient}, nil -} diff --git a/internal/cmd/local/local_deployments.go b/internal/cmd/local/local_deployments.go index 2e70585..268c35d 100644 --- a/internal/cmd/local/local_deployments.go +++ b/internal/cmd/local/local_deployments.go @@ -14,10 +14,15 @@ type DeploymentsCmd struct { Restart string `help:"Deployment to restart."` } -func (d *DeploymentsCmd) Run(ctx context.Context, telClient telemetry.Client, k8sClient k8s.Client) error { +func (d *DeploymentsCmd) Run(ctx context.Context, telClient telemetry.Client, provider k8s.Provider) error { ctx, span := trace.StartSpan(ctx, "local deployments") defer span.End() + k8sClient, err := defaultK8s(provider.Kubeconfig, provider.Context) + if err != nil { + return err + } + spinner := &pterm.DefaultSpinner if err := checkDocker(ctx, telClient, spinner); err != nil { return err