Skip to content

Commit

Permalink
fix deployments cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
colesnodgrass committed Oct 31, 2024
1 parent 2cde3ab commit 8ef1e95
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
21 changes: 21 additions & 0 deletions internal/cmd/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
21 changes: 0 additions & 21 deletions internal/cmd/local/local_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion internal/cmd/local/local_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ef1e95

Please sign in to comment.