Skip to content

Commit

Permalink
Support init containers
Browse files Browse the repository at this point in the history
fixes #14
  • Loading branch information
davidreuss authored and boz committed Nov 28, 2017
1 parent dab2d1e commit 67ab5fd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
45 changes: 45 additions & 0 deletions _example/init-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: init-container
---
apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
namespace: init-container
name: workers
spec:
selector:
matchLabels:
app: api
tier: backend
component: worker
template:
metadata:
name: workers
labels:
app: api
tier: backend
component: worker
spec:
initContainers:
- name: init
image: busybox
command:
- /bin/sh
- "-c"
- i=0; while [ $i -lt 10 ]; do echo "INIT $i"; sleep 1; i=$((i + 1)); done
containers:
- name: statistics
image: busybox
command:
- /bin/sh
- "-c"
- i=0; while true; do echo "processing user $1 stats..."; sleep 1; i=$((i + 1)); done
- name: thumbnails
image: busybox
command:
- /bin/sh
- "-c"
- i=0; while true; do echo "creating user $1 thumbnail..."; sleep 2; i=$((i + 1)); done
9 changes: 8 additions & 1 deletion filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewContainerFilter(names []string) ContainerFilter {
type containerFilter []string

func (cf containerFilter) Accept(cs v1.ContainerStatus) bool {
if !cs.Ready {
if cs.State.Running == nil {
return false
}
if len(cf) == 0 {
Expand All @@ -43,6 +43,13 @@ func sourcesForPod(filter ContainerFilter, pod *v1.Pod) (nsname.NSName, map[even
}
}

for _, cstatus := range pod.Status.InitContainerStatuses {
if filter.Accept(cstatus) {
source := eventSource{id, cstatus.Name, pod.Spec.NodeName}
sources[source] = true
}
}

return id, sources
}

Expand Down

0 comments on commit 67ab5fd

Please sign in to comment.