File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
.PHONY : docker-build
2
2
docker-build :
3
- docker build -t k8s-pod-cpu-stressor:1.0.0 .
3
+ docker build -t k8s-pod-cpu-stressor:latest .
4
4
5
5
.PHONY : build
6
6
build :
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package main
3
3
import (
4
4
"flag"
5
5
"fmt"
6
+ "os"
7
+ "os/signal"
6
8
"runtime"
7
9
"time"
8
10
)
@@ -19,7 +21,11 @@ func main() {
19
21
20
22
fmt .Printf ("Starting CPU stress with %d goroutines...\n " , numGoroutines )
21
23
22
- done := make (chan bool )
24
+ done := make (chan struct {})
25
+
26
+ // Capture termination signals
27
+ quit := make (chan os.Signal , 1 )
28
+ signal .Notify (quit , os .Interrupt , os .Kill )
23
29
24
30
for i := 0 ; i < numGoroutines ; i ++ {
25
31
go func () {
@@ -33,8 +39,16 @@ func main() {
33
39
}()
34
40
}
35
41
42
+ go func () {
43
+ // Wait for termination signal
44
+ <- quit
45
+ fmt .Println ("Termination signal received. Stopping CPU stress..." )
46
+ close (done )
47
+ }()
48
+
36
49
time .Sleep (* durationPtr )
37
- close (done )
38
50
51
+ // Exit the program gracefully
39
52
fmt .Println ("CPU stress completed." )
53
+ os .Exit (0 )
40
54
}
You can’t perform that action at this time.
0 commit comments