This is an implementation of k8s-wait-for that allows you to wait for multiple items in one process, so you only need to start one init container.
This uses informers (wrapped in a sigs.k8s.io/controller-runtime/pkg/cache.Cache) to get the status updates for all the items that this application is waiting for.
It accepts arguments in the following formats:
namespace,service,service-namenamespace,job,job-namenamespace,pod,pod-nameservice,service-nameusing the namespace from the--namespace,-nflag ordefaultjob,job-nameusing the namespace from the--namespace,-nflag ordefaultpod,pod-nameusing the namespace from the--namespace,-nflag ordefaultpod-nameusing the namespace from the--namespace,-nflag ordefaultand the kindpod
For pods it waits until the pod is Ready (k8s.io/kubectl/pkg/util/podutils.IsPodReady).
For jobs it wait until the Completed condition is true.
For services it will wait until all pods that match the service selector are Ready (like above).
If it is an ExternalName service it is always assumed to be ready.
$ kube-wait-for-multi default,job,some-job default,service,some-service default,pod,some-pod-88bb5f7bb-wx4f7
Wait for the job some-job to complete, the service some-service to have all available pods and the pod some-pod-88bb5f7bb-wx4f7 to be ready and available.
The program will also wait when a service does not exist yet.
$ kube-wait-for-multi default,job,some-job default,job,test default,service,service1 default,service,service2
Starting with namespaces: [default]
Starting informers...
wait status
└── [❔] namespace/default
├── [✅] service/service1: Available
├── [❔] service/service2: Unavailable
├── [✅] job/some-job: Complete
└── [❌] job/test: NotComplete
[... some time later ...]
wait status
└── [✅] namespace/default
Hosted on Docker Hub: https://hub.docker.com/r/erayan/k8s-wait-for-multi
There are latest, nonroot, <tag> and <tag>-nonroot labels available, in amd64 (v2), arm (v7) and arm64.