image-automation-controller icon indicating copy to clipboard operation
image-automation-controller copied to clipboard

ImageUpdateAutomation v1beta2 API with refactored controller

Open darkowlzz opened this issue 3 months ago • 2 comments

This change refactors image-automation-controller to implement the new unified standards of flux controllers.

See https://github.com/fluxcd/image-automation-controller/issues/643 for some overview of the new changes.

Following are some highlights of the changes:

  • Introduce v1beta2 API which introduces new status fields .observedPolicies and .observedSourceRevision required for the new reconciliation model.
  • Refactor the ImageUpdateAutomationReconciler to align with other flux controllers in the way we report the status and send notifications.
  • When the checkout and push branch of the source are the same, the controller now returns early when there's no change in the policies and the remote source. This would help avoid full reconciliations when nothing has changed. When the push branch is different from checkout branch or a refspec is provided, full reconciliation will always be performed.
  • The controller/reconciler e2e tests have been refactored to simplify the tests and expand what's tested. Some tests involving the remote git state changes have been moved to the tests in internal/source package tests.
  • Introduce internal/source package which provides all the source management API. These source management operations are tested in detail independent of the reconciler.
  • The commit template values now has a new update ResultV2 (introduced in https://github.com/fluxcd/image-automation-controller/pull/642) which includes the old and new value of the changes made to the objects in files. This is accessible under .Changed. The previous update Result remains available under .Updated. ResultV2 contains all the updates, even if the update wasn't a complete image but part of an image.
  • The policy applying code has been moved to internal/policy package to be maintained and tested independent of the reconciler and can be used reconciler and source manager tests as needed.
  • Use the ResultV2 based commit template description and examples in the v1beta2 API spec docs.

Example ImageUpdateAutomation status with the new fields:

status:
  conditions:
  - lastTransitionTime: "2024-03-18T20:01:57Z"
    message: repository up-to-date
    observedGeneration: 8
    reason: Succeeded
    status: "True"
    type: Ready
  lastAutomationRunTime: "2024-03-18T21:02:30Z"
  lastHandledReconcileAt: "1710791381"
  lastPushCommit: 8084f1bb180ac259c6698cd027064b7dce86a72a
  lastPushTime: "2024-03-18T18:53:04Z"
  observedGeneration: 8
  observedPolicies:
    podinfo-policy:
      name: ghcr.io/stefanprodan/podinfo
      tag: 4.0.6
    myapp1:
      name: ghcr.io/fluxcd/myapp1
      tag: 4.0.0
    myapp2:
      name: ghcr.io/fluxcd/myapp2
      tag: 2.0.0
  observedSourceRevision: main@sha1:8084f1bb180ac259c6698cd027064b7dce86a72a

Instructions for testing

To test this, checkout this branch and build the container image with make docker-build IMG=<image-name> TAG=<tag>. Before deploying the container image, update/install the CRDs to v1beta2 API with make install or apply the CRD manifests in config/crd/bases. Create git repository, image repository, policy and update automation object and test.

Fixes #437

darkowlzz avatar Mar 12 '24 01:03 darkowlzz