Skip to content

Commit c990e03

Browse files
Add deployment rollout monitoring after release
1 parent a4c464d commit c990e03

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

pkg/deploy/deploy.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,21 @@ func Run(envName string, dryRun bool) error {
3636

3737
fmt.Println("Starting deployment...")
3838

39-
return executor.Run(command.Name, command.Args...)
39+
if err := executor.Run(command.Name, command.Args...); err != nil {
40+
return err
41+
}
42+
43+
////////////////////////////////////
44+
// SKIP ROLLOUT FOR DRY RUN
45+
////////////////////////////////////
46+
47+
if dryRun {
48+
return nil
49+
}
50+
51+
////////////////////////////////////
52+
// MONITOR ROLLOUT
53+
////////////////////////////////////
54+
55+
return MonitorRollout(environment)
4056
}

pkg/deploy/rollout.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package deploy
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
"time"
7+
8+
"github.com/aryansharma9917/codewise-cli/pkg/env"
9+
)
10+
11+
func MonitorRollout(environment *env.Env) error {
12+
13+
release := environment.Helm.Release
14+
namespace := environment.K8s.Namespace
15+
context := environment.K8s.Context
16+
17+
fmt.Println("Waiting for deployment rollout...")
18+
19+
// We assume Helm creates a Deployment with the release name.
20+
// This is standard Helm behavior unless overridden.
21+
22+
args := []string{
23+
"rollout",
24+
"status",
25+
"deployment/" + release,
26+
"-n",
27+
namespace,
28+
}
29+
30+
if context != "" {
31+
args = append(args, "--context", context)
32+
}
33+
34+
cmd := exec.Command("kubectl", args...)
35+
36+
// Stream output live
37+
cmd.Stdout = nil
38+
cmd.Stderr = nil
39+
40+
err := cmd.Run()
41+
if err != nil {
42+
return fmt.Errorf("deployment failed to roll out")
43+
}
44+
45+
time.Sleep(1 * time.Second)
46+
47+
fmt.Println("Deployment successfully rolled out.")
48+
return nil
49+
}

0 commit comments

Comments
 (0)