Skip to content

Commit 7137f8b

Browse files
Add deployment status command to inspect Helm release and pod state
1 parent f18f8cd commit 7137f8b

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

pkg/deploy/status.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package deploy
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
"strings"
7+
)
8+
9+
func Status(envName string) error {
10+
11+
environment, err := LoadEnvironment(envName)
12+
if err != nil {
13+
return err
14+
}
15+
16+
ns := environment.K8s.Namespace
17+
ctx := environment.K8s.Context
18+
release := environment.Helm.Release
19+
20+
fmt.Println("Deployment Status")
21+
fmt.Println("-----------------")
22+
fmt.Println("Environment:", envName)
23+
fmt.Println("Namespace:", ns)
24+
fmt.Println("Release:", release)
25+
fmt.Println()
26+
27+
// Helm Status
28+
args := []string{
29+
"status",
30+
release,
31+
"-n",
32+
ns,
33+
}
34+
35+
if ctx != "" {
36+
args = append(args, "--kube-context", ctx)
37+
}
38+
39+
cmd := exec.Command("helm", args...)
40+
out, err := cmd.CombinedOutput()
41+
if err != nil {
42+
fmt.Println("Helm status not available")
43+
} else {
44+
fmt.Println(string(out))
45+
}
46+
47+
// Pods
48+
fmt.Println("Pods:")
49+
podArgs := []string{
50+
"get",
51+
"pods",
52+
"-n",
53+
ns,
54+
"-o",
55+
"wide",
56+
}
57+
58+
if ctx != "" {
59+
podArgs = append(podArgs, "--context", ctx)
60+
}
61+
62+
podCmd := exec.Command("kubectl", podArgs...)
63+
podsOut, err := podCmd.CombinedOutput()
64+
if err != nil {
65+
fmt.Println("Unable to fetch pods")
66+
} else {
67+
fmt.Println(strings.TrimSpace(string(podsOut)))
68+
}
69+
70+
return nil
71+
}

0 commit comments

Comments
 (0)