Skip to content

Commit c1db1eb

Browse files
committed
fixes
1 parent 6091010 commit c1db1eb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: docker-build
22
docker-build:
3-
docker build -t k8s-pod-cpu-stressor:1.0.0 .
3+
docker build -t k8s-pod-cpu-stressor:latest .
44

55
.PHONY: build
66
build:

main.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"os"
7+
"os/signal"
68
"runtime"
79
"time"
810
)
@@ -19,7 +21,11 @@ func main() {
1921

2022
fmt.Printf("Starting CPU stress with %d goroutines...\n", numGoroutines)
2123

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)
2329

2430
for i := 0; i < numGoroutines; i++ {
2531
go func() {
@@ -33,8 +39,16 @@ func main() {
3339
}()
3440
}
3541

42+
go func() {
43+
// Wait for termination signal
44+
<-quit
45+
fmt.Println("Termination signal received. Stopping CPU stress...")
46+
close(done)
47+
}()
48+
3649
time.Sleep(*durationPtr)
37-
close(done)
3850

51+
// Exit the program gracefully
3952
fmt.Println("CPU stress completed.")
53+
os.Exit(0)
4054
}

0 commit comments

Comments
 (0)