Open tony2001 opened 6 months ago
@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
Sounds reasonable indeed!
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.