Skip to content

Conversation

@AntonShadrinNN
Copy link
Contributor

@AntonShadrinNN AntonShadrinNN commented Aug 5, 2025

Closes #1206
Closes #1032

Fixes a situation where it was impossible to update images that were in the yaml array.
The code can probably be improved, I will be glad to follow the recommendations.

@codecov-commenter
Copy link

codecov-commenter commented Aug 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.34%. Comparing base (18767ed) to head (646ea60).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1208      +/-   ##
==========================================
+ Coverage   63.05%   63.34%   +0.29%     
==========================================
  Files          23       23              
  Lines        3140     3165      +25     
==========================================
+ Hits         1980     2005      +25     
  Misses       1050     1050              
  Partials      110      110              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AntonShadrinNN AntonShadrinNN marked this pull request as ready for review August 5, 2025 21:22
@AntonShadrinNN
Copy link
Contributor Author

I decided to use the abcd[0] syntax, as it is simpler in terms of parsing and more intuitive in terms of appearance.

argocd-image-updater.argoproj.io/fooalias.helm.image-tag: foo[1].image
```

This works also for both annotation `<image_alias>.helm.image-name` and annotation `<image_alias>.helm.image-tag`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

earlier in this doc, it says all 3 annotations will support this index notation: image-name, image-tag, image-spec. So the above line should be updated to include all 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*Solution:* Use the index in square brackets of the item that needs to be updated, i.e.

```yaml
argocd-image-updater.argoproj.io/fooalias.helm.image-tag: foo[1].image
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it easier to understand which list element is targetted, you may want to change to use image foo-1 and foo-2 (not using another bar* image), and use foo-alias and foo[1] to refer to the 2nd element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, if I got the gist right.

idStr := matches[2]
id, err := strconv.Atoi(idStr)
if err != nil {
return fmt.Errorf("id \"%s\" in yaml array must match pattern ^(\\D+)\\[(\\d+)\\]$", idStr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the declared pattern should be used in the error msg, to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Forgot to change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, including tests

keys := strings.Split(key, ".")

// any-string[1]
pattern := `^(.*)\[(.*)\]$`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to use a more specific pattern to avoid invalid values like foo[x]:

pattern := `^([^[]+)\[(\d+)\]$`

Copy link
Contributor Author

@AntonShadrinNN AntonShadrinNN Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original version looked like this, but it makes it harder to return a clear error like this . The problem is that the search is based on the key. If it doesn't fit the pattern, then the search will follow it entirely, which means it will fall into the else block and simply write this value. Should I take a different approach, such as checking the validity of the strings and parsing them separately?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a small difference, in that case, let's just keep what you have now.

@chengfang chengfang force-pushed the ashadrin/allow_yaml_sequence_node_type branch from 0680f20 to c434ba0 Compare August 6, 2025 18:37
Signed-off-by: Anton Shadrin <[email protected]>

// any-string[1]
pattern := `^(.*)\[(.*)\]$`
re := regexp.MustCompile(pattern)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving the regexp compilation to the pkg level var? This func is called multiple times per image update and we should avoid recompiling the regexp repeatedly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Fixed it.

Anton Shadrin added 2 commits August 8, 2025 09:51
@chengfang chengfang merged commit e816c49 into argoproj-labs:master Aug 8, 2025
11 checks passed
@AntonShadrinNN
Copy link
Contributor Author

@chengfang First of all, thank you for your help.

Can I ask you to tag these changes? I would like to use it to solve my original problem.

chansuke pushed a commit to chansuke/argocd-image-updater that referenced this pull request Aug 9, 2025
Signed-off-by: Anton Shadrin <[email protected]>
Co-authored-by: Anton Shadrin <[email protected]>
dkarpele pushed a commit to dkarpele/argocd-image-updater that referenced this pull request Aug 10, 2025
Signed-off-by: Anton Shadrin <[email protected]>
Co-authored-by: Anton Shadrin <[email protected]>

(cherry picked from commit e816c49)
Signed-off-by: Denis Karpelevich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants