k8s-image-availability-exporter icon indicating copy to clipboard operation
k8s-image-availability-exporter copied to clipboard

Add Argo Rollouts support

Open tony2001 opened this issue 1 year ago • 2 comments

We use Argo Rollouts for gradual deployment of our services, so we needed to detect missing images for them as well. The support is quite straightforward, but it requires its own client, which I kinda dislike. I would be grateful if you can think of any way to get rid of it.

tony2001 avatar Feb 05 '24 19:02 tony2001

@tony2001 thanks! The idea is excellent, but my only concern is importing the github.com/argoproj/argo-rollouts.

We can play around with it and use the dynamic client. This approach is more generic, and we will be able to add more resources in the future without importing the world.

Example:

var rolloutsResource = schema.GroupVersionResource{Group: "argoproj,io", Version: "v1alpha1", Resource: "rollouts"}

clusterClient, err := dynamic.NewForConfig(clusterConfig)
if err != nil {
    log.Fatalln(err)
}

informer = dynamicinformer.NewFilteredDynamicInformer(
    clusterClient,
    rolloutsResource,
    corev1.NamespaceAll,
    30*time.Second,
    cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
    nil,
)

To work with objects, there is the unstructured package.

containers, _, _ := unstructured.NestedSlice(obj.Object, "spec", "template", "spec", "containers")

res := make([]corev1.Container{}, 0, len(containers))

for _, c := range containers {
      if props, ok := c.(map[string]interface{}); ok {
            res := append(res, corev1.Container{
                Image: props["image"].(string),
                Name:  props["name"].(string),
             }) 
      }


}

return res 

nabokihms avatar Feb 07 '24 14:02 nabokihms

Sounds reasonable indeed!

tony2001 avatar Feb 07 '24 15:02 tony2001