Commit Graph

9 Commits

Author SHA1 Message Date
Aurel Canciu c3fe4e0a77
Fix resolving image name for marker name attribute
The image name was incorrectly extracted from the given reference,
yielding a trimmed version of the string and breaking the resulting
replacement value.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-05-06 15:40:29 +03:00
Michael Bridgen 9caa3b42f1 Test that an unchanged image is not in result
With reference to

    https://github.com/fluxcd/image-automation-controller/issues/133

this commit adapts the update->result test so that it checks an
additional case: that a field with an update marker that _does_
correspond to a policy, but _doesn't_ get changed, is not included in
the results.

This test fails at present, because the method for determining the
result is to count which setters are referenced, rather than which
fields were changed.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-06 10:04:08 +01:00
Michael Bridgen 8eec8c095c Screen files, and output only those updated
This is intended to address two problems:

 - LocalPackage{Reader,Writer} like to reformat the YAML that passes
   through them; mostly this is harmless, but occasionally it will end
   up fighting format tooling, e.g., prettier.

 - It's possible that things like Helm chart templates are lying
   around in the git repository to which automation is applied. Those
   templates have extensions of ".yaml" but are not usually parseable
   as YAML, so would result in errors from the file reader.

This commit changes how updates are run -- firstly, it screens files
by checking for a token (`"$imagepolicy"`) that will be present in
files that might need updating. This cheaply removes some nodes --
likely including Helm chart templates -- from consideration.

Secondly, it now only writes files that were actually updated by an
imagepolicy setter, rather than writing everything that was an
input. This means it's less likely to reformat something that doesn't
need to be touched at all.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-01-04 14:44:42 +00:00
Michael Bridgen 76da2079e6 Supply :tag and :name setters for each image
It will be useful, for kustomizations e.g., to be able to set just the
tag or just the name (repository). This commit adds setters for those
to the schema -- they have the name of the image setter plus a suffix
of `:tag` or `:name`. For example:

    newName: ubuntu # {"$imagepolicy": "ns:policy:name"}
    newTag: 18.10   # {"$imagepolicy": "ns:policy:tag"}
2020-10-13 21:00:13 +01:00
Michael Bridgen 7e58a5bf47 Implement and test func for update using setters
This adds another means of updating files to the package pkg/update/,
in setters.go (and gives the existing file a better name).

In passing, I changed the test util for comparing before/after
updates, in pkg/files/, to give a little more context when comparing
file contents; and, since the comparison between actual and expected
is not symmetrical, I corrected the order of the args in the tests.
2020-10-13 20:59:35 +01:00
Michael Bridgen 963ee35c23 Preserve line-end comments when replacing image
Previously: replace the YNode (yaml.Node) with a new one which is just
the replacement string.
Now: change the value of the YNode, and set it back in place.
2020-09-29 12:19:12 +01:00
Kevin McDermott aad1df6af6 Apply image updates to CronJob objects
This updates the image replacement to switch on the kind of the node,
and change the way the replacements are done for CronJobs.

CronJobs have PodTemplateSpecs embedded deeper in the structure.
2020-09-09 10:30:48 +01:00
Michael Bridgen 7c6e87d06a Test the result of the automated commit
This factors out the function that checks directories for equivalence,
and uses it to check that the upstream repo has the expected update
when the controller has pushed its commit.
2020-07-23 18:20:35 +01:00
Michael Bridgen 739f3c1770 Add update strategy that uses image policy
Just to get points on the board, this gives ImageUpdateAutomation an
`update` field into which you can plug the name of an ImagePolicy
resource (from the image reflector controller). The idea is that the
automation will then replace the image in the policy, anywhere it's
used, with its latest version.
2020-07-23 18:20:35 +01:00