Skip to content

Commit

Permalink
fix: ensure kubeconfig exists (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuchanan-airbyte authored Nov 8, 2024
1 parent 2eea739 commit 4016828
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/cmd/local/k8s/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ type Provider struct {
func (p Provider) Cluster(ctx context.Context) (Cluster, error) {
_, span := trace.NewSpan(ctx, "Provider.Cluster")
defer span.End()

if err := os.MkdirAll(filepath.Dir(p.Kubeconfig), 0766); err != nil {
return nil, fmt.Errorf("unable to create directory %s: %v", p.Kubeconfig, err)
}

kindProvider := cluster.NewProvider(cluster.ProviderWithLogger(&kindLogger{pterm: pterm.Debug}))
if err := kindProvider.ExportKubeConfig(p.ClusterName, p.Kubeconfig, false); err != nil {
pterm.Debug.Printfln("failed to export kube config: %s", err)
}

return &kindCluster{
p: cluster.NewProvider(cluster.ProviderWithLogger(&kindLogger{pterm: pterm.Debug})),
p: kindProvider,
kubeconfig: p.Kubeconfig,
clusterName: p.ClusterName,
}, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/local/local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (i *InstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient t
// existing cluster, validate it
pterm.Success.Printfln("Existing cluster '%s' found", provider.ClusterName)
spinner.UpdateText(fmt.Sprintf("Validating existing cluster '%s'", provider.ClusterName))
span.SetAttributes(attribute.Bool("cluster_exists", true))

// only for kind do we need to check the existing port
if provider.Name == k8s.Kind {
Expand All @@ -138,6 +139,7 @@ func (i *InstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient t
} else {
// no existing cluster, need to create one
pterm.Info.Println(fmt.Sprintf("No existing cluster found, cluster '%s' will be created", provider.ClusterName))
span.SetAttributes(attribute.Bool("cluster_exists", false))

spinner.UpdateText(fmt.Sprintf("Checking if port %d is available", i.Port))
if err := portAvailable(ctx, i.Port); err != nil {
Expand Down

0 comments on commit 4016828

Please sign in to comment.