-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: return images from resources when sync occurs #642
base: master
Are you sure you want to change the base?
Changes from 4 commits
3f1734a
b3eb347
ae4000b
b205965
6b9063a
5b2c46f
1a5b26f
a989b44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,6 +404,34 @@ func GetDeploymentReplicas(u *unstructured.Unstructured) *int64 { | |
return &val | ||
} | ||
|
||
func GetResourceImages(u *unstructured.Unstructured) []string { | ||
var images []string | ||
|
||
// Extract containers for resources like pods, without template | ||
containers, found, err := unstructured.NestedSlice(u.Object, "spec", "containers") | ||
if !found || err != nil { | ||
// Extract containers for other resources that have template | ||
containers, found, err = unstructured.NestedSlice(u.Object, "spec", "template", "spec", "containers") | ||
if !found || err != nil { | ||
return nil | ||
} | ||
} | ||
|
||
for _, container := range containers { | ||
containerMap, ok := container.(map[string]interface{}) | ||
if !ok { | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to extract as much data as possible. Added |
||
} | ||
image, found, err := unstructured.NestedString(containerMap, "image") | ||
if !found || err != nil { | ||
continue | ||
} | ||
images = append(images, image) | ||
} | ||
|
||
return images | ||
} | ||
|
||
// RetryUntilSucceed keep retrying given action with specified interval until action succeed or specified context is done. | ||
func RetryUntilSucceed(ctx context.Context, interval time.Duration, desc string, log logr.Logger, action func() error) { | ||
pollErr := wait.PollUntilContextCancel(ctx, interval, true, func(ctx context.Context) (bool /*done*/, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For CronJobs it seems that the image is under
spec.jobTemplate.spec.template.spec.containers
. Should we also check there?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 6b9063a