diff --git a/internal/cluster/providers/k3d/manager.go b/internal/cluster/providers/k3d/manager.go index aae32f40..3302d2db 100644 --- a/internal/cluster/providers/k3d/manager.go +++ b/internal/cluster/providers/k3d/manager.go @@ -12,6 +12,7 @@ import ( "github.com/flamingo-stack/openframe-cli/internal/cluster/models" "github.com/flamingo-stack/openframe-cli/internal/shared/executor" + "github.com/pterm/pterm" "k8s.io/client-go/rest" ) @@ -68,7 +69,7 @@ func (m *K3dManager) CreateCluster(ctx context.Context, config models.ClusterCon // This must be done before cluster creation as it affects the Docker/WSL host if err := m.increaseInotifyLimits(ctx); err != nil { if m.verbose { - fmt.Printf("Warning: Could not increase inotify limits: %v\n", err) + pterm.Warning.Printf("Could not increase inotify limits: %v\n", err) } // Don't fail - cluster might still work if limits are already sufficient } @@ -82,14 +83,14 @@ func (m *K3dManager) CreateCluster(ctx context.Context, config models.ClusterCon if m.verbose { if configContent, err := os.ReadFile(configFile); err == nil { // #nosec G304 -- reads a temp config file this process just created - fmt.Printf("DEBUG: Config file content for %s:\n%s\n", config.Name, string(configContent)) + pterm.Debug.Printf("Config file content for %s:\n%s\n", config.Name, string(configContent)) } } // Prepare kubeconfig directory before k3d operations (Windows/WSL and Linux CI) if err := m.prepareKubeconfigDirectory(ctx); err != nil { if m.verbose { - fmt.Printf("Warning: Could not prepare kubeconfig directory: %v\n", err) + pterm.Warning.Printf("Could not prepare kubeconfig directory: %v\n", err) } // Don't fail - k3d will create it, but log the warning } @@ -97,7 +98,7 @@ func (m *K3dManager) CreateCluster(ctx context.Context, config models.ClusterCon // Clean up any stale lock files that might prevent k3d from updating kubeconfig if err := m.cleanupStaleLockFiles(ctx); err != nil { if m.verbose { - fmt.Printf("Warning: Could not cleanup stale lock files: %v\n", err) + pterm.Warning.Printf("Could not cleanup stale lock files: %v\n", err) } // Don't fail - this is not critical } @@ -122,7 +123,7 @@ func (m *K3dManager) CreateCluster(ctx context.Context, config models.ClusterCon // This is necessary because k3d creates ~/.kube/config with root ownership when run with sudo if err := m.fixKubeconfigPermissions(ctx); err != nil { if m.verbose { - fmt.Printf("Warning: Could not fix kubeconfig permissions: %v\n", err) + pterm.Warning.Printf("Could not fix kubeconfig permissions: %v\n", err) } // Don't fail - this is not critical, just log the warning } @@ -131,7 +132,7 @@ func (m *K3dManager) CreateCluster(ctx context.Context, config models.ClusterCon // This is critical because lock files may have been created with root ownership if err := m.cleanupStaleLockFiles(ctx); err != nil { if m.verbose { - fmt.Printf("Warning: Could not cleanup lock files after permission fix: %v\n", err) + pterm.Warning.Printf("Could not cleanup lock files after permission fix: %v\n", err) } // Don't fail - this is not critical } @@ -188,7 +189,7 @@ func (m *K3dManager) DeleteCluster(ctx context.Context, name string, clusterType // No Windows branch: the CLI forwards into WSL and runs as linux (see wsllauncher). if force { if m.verbose { - fmt.Printf("k3d delete failed, attempting direct Docker cleanup for cluster %s: %v\n", name, err) + pterm.Warning.Printf("k3d delete failed, attempting direct Docker cleanup for cluster %s: %v\n", name, err) } if cleanupErr := m.forceCleanupDockerContainers(ctx, name); cleanupErr != nil { // Return original error if cleanup also fails @@ -196,7 +197,7 @@ func (m *K3dManager) DeleteCluster(ctx context.Context, name string, clusterType } // Cleanup succeeded, cluster is removed if m.verbose { - fmt.Printf("✓ Cluster %s removed via direct Docker cleanup\n", name) + pterm.Success.Printf("Cluster %s removed via direct Docker cleanup\n", name) } return nil } @@ -233,7 +234,7 @@ func (m *K3dManager) forceCleanupDockerContainers(ctx context.Context, clusterNa id = strings.TrimSpace(id) if id != "" { if _, rerr := m.executor.Execute(ctx, "docker", "rm", "-f", id); rerr != nil && m.verbose { - fmt.Printf("Warning: failed to remove container %s: %v\n", id, rerr) + pterm.Warning.Printf("failed to remove container %s: %v\n", id, rerr) } } } @@ -241,7 +242,7 @@ func (m *K3dManager) forceCleanupDockerContainers(ctx context.Context, clusterNa // Also remove the network if _, nerr := m.executor.Execute(ctx, "docker", "network", "rm", fmt.Sprintf("k3d-%s", clusterName)); nerr != nil && m.verbose { - fmt.Printf("Warning: failed to remove k3d network for %s: %v\n", clusterName, nerr) + pterm.Warning.Printf("failed to remove k3d network for %s: %v\n", clusterName, nerr) } return nil @@ -523,14 +524,14 @@ func (m *K3dManager) increaseInotifyLimitsFor(ctx context.Context, goos string) } if m.verbose { - fmt.Printf("✓ Increased inotify limits in WSL (max_user_watches=%d, max_user_instances=%d)\n", + pterm.Success.Printf("Increased inotify limits in WSL (max_user_watches=%d, max_user_instances=%d)\n", maxUserWatches, maxUserInstances) } default: // linux // Skip the privileged write when the current limits already suffice. if m.inotifyLimitsSufficient(ctx, maxUserWatches, maxUserInstances) { if m.verbose { - fmt.Println("✓ inotify limits already sufficient") + pterm.Success.Println("inotify limits already sufficient") } return nil } @@ -548,7 +549,7 @@ func (m *K3dManager) increaseInotifyLimitsFor(ctx context.Context, goos string) } if m.verbose { - fmt.Printf("✓ Increased inotify limits (max_user_watches=%d, max_user_instances=%d)\n", + pterm.Success.Printf("Increased inotify limits (max_user_watches=%d, max_user_instances=%d)\n", maxUserWatches, maxUserInstances) } }