Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deployments command failing #144

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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