Skip to content

Commit

Permalink
Add sub reaper to wait for stunnel processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng Pan committed Dec 16, 2019
1 parent fe561fc commit 90014ea
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM amazonlinux:2
RUN yum install util-linux amazon-efs-utils -y
COPY bin/aws-efs-csi-driver /bin/aws-efs-csi-driver
COPY THIRD-PARTY /

ENTRYPOINT ["/bin/aws-efs-csi-driver"]
4 changes: 4 additions & 0 deletions examples/kubernetes/volume_path/specs/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spec:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
mountOptions:
- tls
csi:
driver: efs.csi.aws.com
volumeHandle: fs-e8a95a42:/dir1
Expand Down Expand Up @@ -44,6 +46,8 @@ spec:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
mountOptions:
- tls
csi:
driver: efs.csi.aws.com
volumeHandle: fs-e8a95a42:/dir2
Expand Down
4 changes: 4 additions & 0 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (d *Driver) Run() error {
klog.Info("Starting watch dog")
watchDog.start()

reaper := newReaper()
klog.Info("Staring subreaper")
reaper.start()

klog.Infof("Listening for connections on address: %#v", listener.Addr())
return d.srv.Serve(listener)
}
71 changes: 71 additions & 0 deletions pkg/driver/reaper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package driver

import (
"os"
"os/signal"
"syscall"

"k8s.io/klog"
)

type reaper struct {
sigs chan os.Signal
stopCh chan struct{}
}

func newReaper() *reaper {
sigs := make(chan os.Signal, 1)
stopCh := make(chan struct{})

signal.Notify(sigs, syscall.SIGCHLD)
return &reaper{
sigs: sigs,
stopCh: stopCh,
}
}

// start starts the reaper
func (r *reaper) start() {
go r.runLoop()
}

func (r *reaper) runLoop() {
for {
select {
case <-r.sigs:
var (
status syscall.WaitStatus
rusage syscall.Rusage
)
childPid, err := syscall.Wait4(-1, &status, syscall.WNOHANG, &rusage)
if err != nil {
klog.Warningf("Failed to wait for child proces %s", err)
} else {
klog.V(4).Infof("Waited for child process %d", childPid)
}
case <-r.stopCh:
break
}
}
}

// stop stops the reaper
func (r *reaper) stop() {
r.stopCh <- struct{}{}
}

0 comments on commit 90014ea

Please sign in to comment.