-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wcow: support graceful termination of servercore containers (#1416)
* This commit includes the changes to enable graceful termination of WCOW containers Signed-off-by: Kirtana Ashok <[email protected]> * Added regression tests for nanoserver and servercore base images Signed-off-by: Kirtana Ashok <[email protected]> * Worked on Kevin's review comments Signed-off-by: Kirtana Ashok <[email protected]> * Fixed lint failures Fixed lint errors caused by spelling mistakes in hcsdoc_wcow.go and stopcontainer_test.go Signed-off-by: Kirtana Ashok <[email protected]> * Addresses Kevin's review comments Signed-off-by: Kirtana Ashok <[email protected]> Signed-off-by: Kirtana Ashok <[email protected]> Signed-off-by: Kirtana Ashok <[email protected]> Co-authored-by: Kirtana Ashok <[email protected]>
- Loading branch information
Showing
9 changed files
with
316 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/cri-containerd/test-images/nanoserver-gracefultermination-repro/latest/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:latest as build | ||
ENV GOOS=windows | ||
ENV GOARCH=amd64 | ||
ENV GO111MODULE=off | ||
WORKDIR /app | ||
COPY ./delayed-shutdown.go ./ | ||
RUN go build -o delayed-shutdown.exe | ||
|
||
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 | ||
WORKDIR /app | ||
COPY --from=build /app/delayed-shutdown.exe . | ||
ENTRYPOINT ["delayed-shutdown.exe"] |
45 changes: 45 additions & 0 deletions
45
...ri-containerd/test-images/nanoserver-gracefultermination-repro/latest/delayed-shutdown.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Waiting for OS signal...") | ||
|
||
signalChannel := make(chan os.Signal) | ||
wait := make(chan int, 1) | ||
|
||
signal.Notify(signalChannel, syscall.SIGHUP) | ||
signal.Notify(signalChannel, syscall.SIGINT) | ||
signal.Notify(signalChannel, syscall.SIGTERM) | ||
|
||
go func() { | ||
sig := <-signalChannel | ||
switch sig { | ||
case syscall.SIGHUP: | ||
fmt.Println("SIGHUP") | ||
wait <- 1 | ||
case syscall.SIGTERM: | ||
fmt.Println("SIGTERM") | ||
wait <- 1 | ||
case syscall.SIGINT: | ||
fmt.Println("SIGINT") | ||
wait <- 1 | ||
} | ||
}() | ||
|
||
<-wait | ||
|
||
fmt.Println("Exiting in 60 seconds...") | ||
for i := 60; i > 0; i-- { | ||
fmt.Printf("%d\n", i) | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
fmt.Println("Goodbye") | ||
} |
12 changes: 12 additions & 0 deletions
12
test/cri-containerd/test-images/servercore-gracefultermination-repro/latest/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:latest as build | ||
ENV GOOS=windows | ||
ENV GOARCH=amd64 | ||
ENV GO111MODULE=off | ||
WORKDIR /app | ||
COPY ./delayed-shutdown.go ./ | ||
RUN go build -o delayed-shutdown.exe | ||
|
||
FROM mcr.microsoft.com/windows/servercore:ltsc2022 | ||
WORKDIR /app | ||
COPY --from=build /app/delayed-shutdown.exe . | ||
ENTRYPOINT ["delayed-shutdown.exe"] |
Oops, something went wrong.