Sign inSign up

ylonkar/pod-dependency-init-container

By ylonkar

•Updated over 5 years ago

Container to define pod dependency on other pods

Image
0

50K+

ylonkar/pod-dependency-init-container repository overview

⁠Pod dependency init container

This container can be used as init container to specify dependency of other pod. It will check for exiting pod with success status. If any pod with given label selector is found running in current namespace it will exit with success else exit with failure after timeout.

⁠How to use it

Use with github packages⁠ or The docker image is hosted on docker hub and can be found on hub.docker.com⁠ or github-packages⁠

⁠Settings
Environment VariableRequiredDefaultDescription
POD_LABELSYes-This is comma (,) separated string of labels of dependency pods which will be checked for Running phase.
MAX_RETRYNO5Maximum number of times for which init container will try to check if dependency pods are Running.
RETRY_TIME_OUTNO1500Number of milliseconds init container will pause between each retry.

Example usage:

spec:
  containers:
  ...
  serviceAccountName: {{ .Values.serviceAccount }} #optional
  initContainers:
  - name: pod-dependency
    image: ylonkar/pod-dependency-init-container:1.0.2
    env:
    - name: POD_LABELS
      value: app=nodeapp,name=mongo-1
    - name: MAX_RETRY
      value: "10"
    - name: RETRY_TIME_OUT
      value: "5000"

⁠RBAC

In case of RBAC this container requires pods resource get, list, watch access. Which can be provided by below yaml

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: {{ .Values.serviceAccount }}
rules:
  - apiGroups:
      - ""
    resources:
      - pods
      - services
      - endpoints
    verbs:
      - get
      - list
      - watch
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ .Values.serviceAccount }}
  namespace: {{ .Values.namespace }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: system:serviceaccount:{{ .Values.serviceAccount }}:default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ .Values.serviceAccount }}
subjects:
- kind: ServiceAccount
  name: {{ .Values.serviceAccount }}
  namespace: {{ .Values.namespace }}

⁠To do

  • Add tests!
  • Add to travis-ci

Tag summary

Content type

Image

Digest

Size

44.7 MB

Last updated

over 5 years ago

docker pull ylonkar/pod-dependency-init-container