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: ensure kubeconfig exists #146

Merged
merged 2 commits into from
Nov 8, 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
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