Skip to content

Commit 935a9c0

Browse files
authored
Merge pull request #175 from flant/fix_replace_zombie_reaper_with_tini
fix: use tini for zombie reaping
2 parents aee0f00 + 5711069 commit 935a9c0

File tree

9 files changed

+16
-370
lines changed

9 files changed

+16
-370
lines changed

.github/workflows/dev-build.yaml

+2-10
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ jobs:
4343
matrix:
4444
flavour:
4545
- ubuntu
46-
- alpine3.9
47-
- alpine3.10
48-
- alpine3.11
46+
- alpine
4947
runs-on: ubuntu-latest
5048
if: github.event_name == 'pull_request' && github.event.label.id == 1838515600 # ':robot: build dev images' label
5149
steps:
@@ -63,13 +61,7 @@ jobs:
6361
dockerFile=Dockerfile
6462
6563
case $FLAVOUR in
66-
alpine3.9)
67-
dockerFile="Dockerfile-alpine3.9"
68-
;;
69-
alpine3.10)
70-
dockerFile="Dockerfile-alpine3.10"
71-
;;
72-
alpine3.11)
64+
alpine)
7365
dockerFile="Dockerfile-alpine3.11"
7466
;;
7567
esac

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ RUN CGO_ENABLED=1 \
3434
-o shell-operator \
3535
./cmd/shell-operator
3636

37+
FROM krallin/ubuntu-tini:bionic AS tini
3738

3839
# build final image
3940
FROM ubuntu:18.04
@@ -44,9 +45,10 @@ RUN apt-get update && \
4445
chmod +x /bin/kubectl && \
4546
mkdir /hooks
4647
ADD frameworks /
48+
COPY --from=tini /usr/local/bin/tini /sbin/tini
4749
COPY --from=shell-operator /src/shell-operator /
4850
WORKDIR /
4951
ENV SHELL_OPERATOR_HOOKS_DIR /hooks
5052
ENV LOG_TYPE json
51-
ENTRYPOINT ["/shell-operator"]
53+
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
5254
CMD ["start"]

Dockerfile-alpine3.10

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN CGO_ENABLED=1 \
3232

3333
# build final image
3434
FROM alpine:3.10
35-
RUN apk --no-cache add ca-certificates jq bash sed && \
35+
RUN apk --no-cache add ca-certificates jq bash sed tini && \
3636
wget https://storage.googleapis.com/kubernetes-release/release/v1.17.4/bin/linux/amd64/kubectl -O /bin/kubectl && \
3737
chmod +x /bin/kubectl && \
3838
mkdir /hooks
@@ -41,5 +41,5 @@ COPY --from=shell-operator /src/shell-operator /
4141
WORKDIR /
4242
ENV SHELL_OPERATOR_HOOKS_DIR /hooks
4343
ENV LOG_TYPE json
44-
ENTRYPOINT ["/shell-operator"]
44+
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
4545
CMD ["start"]

Dockerfile-alpine3.11

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN CGO_ENABLED=1 \
3232

3333
# build final image
3434
FROM alpine:3.11
35-
RUN apk --no-cache add ca-certificates jq bash sed && \
35+
RUN apk --no-cache add ca-certificates jq bash sed tini && \
3636
wget https://storage.googleapis.com/kubernetes-release/release/v1.17.4/bin/linux/amd64/kubectl -O /bin/kubectl && \
3737
chmod +x /bin/kubectl && \
3838
mkdir /hooks
@@ -41,5 +41,5 @@ COPY --from=shell-operator /src/shell-operator /
4141
WORKDIR /
4242
ENV SHELL_OPERATOR_HOOKS_DIR /hooks
4343
ENV LOG_TYPE json
44-
ENTRYPOINT ["/shell-operator"]
44+
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
4545
CMD ["start"]

Dockerfile-alpine3.9

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN CGO_ENABLED=1 \
3232

3333
# build final image
3434
FROM alpine:3.9
35-
RUN apk --no-cache add ca-certificates jq bash sed && \
35+
RUN apk --no-cache add ca-certificates jq bash sed tini && \
3636
wget https://storage.googleapis.com/kubernetes-release/release/v1.17.4/bin/linux/amd64/kubectl -O /bin/kubectl && \
3737
chmod +x /bin/kubectl && \
3838
mkdir /hooks
@@ -41,5 +41,5 @@ COPY --from=shell-operator /src/shell-operator /
4141
WORKDIR /
4242
ENV SHELL_OPERATOR_HOOKS_DIR /hooks
4343
ENV LOG_TYPE json
44-
ENTRYPOINT ["/shell-operator"]
44+
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
4545
CMD ["start"]

cmd/shell-operator/main.go

-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"gopkg.in/alecthomas/kingpin.v2"
1010

1111
"github.com/flant/shell-operator/pkg/app"
12-
"github.com/flant/shell-operator/pkg/executor"
1312
shell_operator "github.com/flant/shell-operator/pkg/shell-operator"
1413
utils_signal "github.com/flant/shell-operator/pkg/utils/signal"
1514
)
@@ -33,11 +32,6 @@ func main() {
3332
app.SetupLogging()
3433
log.Infof("%s %s", app.AppName, app.Version)
3534

36-
// Be a good parent - clean up after the child processes
37-
// in case if shell-operator is a PID1.
38-
executor.ReapLocked = false
39-
go executor.Reap()
40-
4135
defaultOperator := shell_operator.DefaultOperator()
4236
err := shell_operator.InitAndStart(defaultOperator)
4337
if err != nil {

pkg/executor/executor.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,16 @@ import (
1111
utils "github.com/flant/shell-operator/pkg/utils/labels"
1212
)
1313

14-
var ExecutorLock = &sync.RWMutex{}
15-
16-
// This family of methods use ExecutorLock to not be interfered by zombie reaper.
17-
1814
func Run(cmd *exec.Cmd) error {
19-
ExecutorLock.RLock()
20-
defer ExecutorLock.RUnlock()
21-
2215
// TODO context: hook name, hook phase, hook binding
16+
// TODO observability
2317
log.Debugf("Executing command '%s' in '%s' dir", strings.Join(cmd.Args, " "), cmd.Dir)
2418

2519
return cmd.Run()
2620
}
2721

2822
func RunAndLogLines(cmd *exec.Cmd, logLabels map[string]string) error {
29-
ExecutorLock.RLock()
30-
defer ExecutorLock.RUnlock()
31-
23+
// TODO observability
3224
logEntry := log.WithFields(utils.LabelsToLogFields(logLabels))
3325
stdoutLogEntry := logEntry.WithField("output", "stdout")
3426
stderrLogEntry := logEntry.WithField("output", "stderr")
@@ -83,9 +75,9 @@ func RunAndLogLines(cmd *exec.Cmd, logLabels map[string]string) error {
8375
}
8476

8577
func Output(cmd *exec.Cmd) (output []byte, err error) {
86-
ExecutorLock.RLock()
87-
defer ExecutorLock.RUnlock()
88-
78+
// TODO context: hook name, hook phase, hook binding
79+
// TODO observability
80+
log.Debugf("Executing command '%s' in '%s' dir", strings.Join(cmd.Args, " "), cmd.Dir)
8981
output, err = cmd.Output()
9082
return
9183
}

pkg/executor/executor_test.go

-169
This file was deleted.

0 commit comments

Comments
 (0)