From 2195ddb26452c72949e2389a4635251be0df6b72 Mon Sep 17 00:00:00 2001 From: aryansharma9917 Date: Sun, 15 Feb 2026 23:27:01 +0530 Subject: [PATCH 1/4] Add deployment failure diagnostics to capture pod details --- pkg/deploy/diagnostics.go | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 pkg/deploy/diagnostics.go diff --git a/pkg/deploy/diagnostics.go b/pkg/deploy/diagnostics.go new file mode 100644 index 0000000..8a45011 --- /dev/null +++ b/pkg/deploy/diagnostics.go @@ -0,0 +1,87 @@ +package deploy + +import ( + "fmt" + "os/exec" + "strings" + + "github.com/aryansharma9917/codewise-cli/pkg/env" +) + +func getPods(namespace string, context string) ([]string, error) { + + args := []string{ + "get", + "pods", + "-n", + namespace, + "-o", + "name", + } + + if context != "" { + args = append(args, "--context", context) + } + + cmd := exec.Command("kubectl", args...) + + out, err := cmd.Output() + if err != nil { + return nil, fmt.Errorf("failed to list pods") + } + + lines := strings.Split(strings.TrimSpace(string(out)), "\n") + + var pods []string + for _, line := range lines { + if strings.TrimSpace(line) != "" { + pods = append(pods, line) + } + } + + return pods, nil +} + +func describePod(pod string, namespace string, context string) { + + fmt.Printf("\nDiagnostics for %s:\n", pod) + + args := []string{ + "describe", + pod, + "-n", + namespace, + } + + if context != "" { + args = append(args, "--context", context) + } + + cmd := exec.Command("kubectl", args...) + out, err := cmd.CombinedOutput() + + if err != nil { + fmt.Println("failed to describe pod") + return + } + + fmt.Println(string(out)) +} + +func FetchDiagnostics(environment *env.Env) { + + ns := environment.K8s.Namespace + ctx := environment.K8s.Context + + fmt.Println("\nFetching failure diagnostics...") + + pods, err := getPods(ns, ctx) + if err != nil || len(pods) == 0 { + fmt.Println("No pods found for diagnostics.") + return + } + + for _, pod := range pods { + describePod(pod, ns, ctx) + } +} From e8bf0fd576cf0f67591e28ab8a9c9a6d53751462 Mon Sep 17 00:00:00 2001 From: aryansharma9917 Date: Sun, 15 Feb 2026 23:27:07 +0530 Subject: [PATCH 2/4] Trigger diagnostics automatically when rollout fails --- pkg/deploy/deploy.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pkg/deploy/deploy.go b/pkg/deploy/deploy.go index d4fc39c..af2e650 100644 --- a/pkg/deploy/deploy.go +++ b/pkg/deploy/deploy.go @@ -9,18 +9,12 @@ func Run(envName string, dryRun bool) error { return err } - //////////////////////////////////// // PREFLIGHT - //////////////////////////////////// - if err := Preflight(environment); err != nil { return err } - //////////////////////////////////// // ENSURE NAMESPACE - //////////////////////////////////// - if err := EnsureNamespace(environment); err != nil { return err } @@ -40,17 +34,18 @@ func Run(envName string, dryRun bool) error { return err } - //////////////////////////////////// - // SKIP ROLLOUT FOR DRY RUN - //////////////////////////////////// - if dryRun { return nil } - //////////////////////////////////// // MONITOR ROLLOUT - //////////////////////////////////// + if err := MonitorRollout(environment); err != nil { + + // fetch diagnostics on failure + FetchDiagnostics(environment) + + return err + } - return MonitorRollout(environment) + return nil } From 4352fe66bd40aef159ffbca7b22ca616d61acd10 Mon Sep 17 00:00:00 2001 From: aryansharma9917 Date: Sun, 15 Feb 2026 23:30:26 +0530 Subject: [PATCH 3/4] Use invalid image tag to test deployment failure diagnostics --- helm/chart/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/chart/templates/deployment.yaml b/helm/chart/templates/deployment.yaml index 03b19c0..319448f 100644 --- a/helm/chart/templates/deployment.yaml +++ b/helm/chart/templates/deployment.yaml @@ -20,6 +20,6 @@ spec: spec: containers: - name: app - image: nginx:latest + image: nginx:does-not-exist ports: - containerPort: 80 From f18f8cdde283de919735ace84518db8ce660cef6 Mon Sep 17 00:00:00 2001 From: aryansharma9917 Date: Sun, 15 Feb 2026 23:32:29 +0530 Subject: [PATCH 4/4] Revert test image and restore stable deployment configuration --- helm/chart/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/chart/templates/deployment.yaml b/helm/chart/templates/deployment.yaml index 319448f..03b19c0 100644 --- a/helm/chart/templates/deployment.yaml +++ b/helm/chart/templates/deployment.yaml @@ -20,6 +20,6 @@ spec: spec: containers: - name: app - image: nginx:does-not-exist + image: nginx:latest ports: - containerPort: 80