deckhouse / k8s-image-availability-exporter

Alert if an image used in Kubernetes cannot be pulled from container registry
Apache License 2.0
212 stars 25 forks source link

Multiple deployments with same image issue #59

Closed oleksiytsyban closed 7 months ago

oleksiytsyban commented 2 years ago

If there are several deployments with same image and at least one of them has Replicas = 0 there is a good chance of removing this image from checking list. rc.imageStore.ReconcileImage does not check for other deployments with same image.

nabokihms commented 8 months ago

Didn't manage to find where is the error exactly. Requires further investigation.

oleksiytsyban commented 8 months ago

It is not an error, it is just how it works. It checks deployments one by one and if Replicas = 0 then removes an image from the checklist. So if there are two deployments with the same image (canary deployment is an example) the first one can have Replicas = 1 and the image added to the checklist and the second can have Replicas = 0 and the image removed from the checklist. So we are not checking for the image despite it is in use.

nabokihms commented 8 months ago

I was searching for the piece of code where the exporter removes an image, but didn't manage to find it.

The exporter collects all containers with their controller references for the given image.

https://github.com/deckhouse/k8s-image-availability-exporter/blob/210abc0c05f55dc4ae286da6ed0c32936667e667/pkg/registry/indexers.go#L234-L258

controllerWithContainerInfos contains controller metadata fields. https://github.com/deckhouse/k8s-image-availability-exporter/blob/210abc0c05f55dc4ae286da6ed0c32936667e667/pkg/registry/indexers.go#L36-L43

I think the behavior you are speaking about was fixed in the scope of this mysterious PR https://github.com/deckhouse/k8s-image-availability-exporter/pull/67

oleksiytsyban commented 8 months ago

Yes, indeed the code I was talking about removed here: https://github.com/deckhouse/k8s-image-availability-exporter/pull/67/files#diff-72bfae920914f6e9789199b940ce1a9f3eb84125226bbb9b10db92174ff933dbL213-L227

I will test the latest version. Looks like the issue is resolved. Thank you.

oleksiytsyban commented 7 months ago

Tested with 0.10.1. Works fine. This issue is fixed. Thank you.