Skip to content
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

Implement automatic distribution updates from OCI artifacts #33

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

stefanprodan
Copy link
Member

@stefanprodan stefanprodan commented Jun 15, 2024

This PR adds a new optional filed named .spec.distribution.artifact to the FluxInstance API. When specified, the operator will pull the artifact from the registry on a regular interval to determine the latest Flux version available including CVE patches and hotfixes.

Using this feature, CNCF Flux users can keep Flux up-to-date without having to update the operator every time there is a new Flux version available.

apiVersion: fluxcd.controlplane.io/v1
kind: FluxInstance
metadata:
  name: flux
  namespace: flux-system
spec:
  distribution:
    version: "2.x"
    registry: "ghcr.io/fluxcd"
    artifact: "oci://ghcr.io/controlplaneio-fluxcd/flux-operator-manifests"

For enterprise customers, this feature allows for automated updates of CVE patches to fixed versions and semver ranges without having to update the operator.

apiVersion: fluxcd.controlplane.io/v1
kind: FluxInstance
metadata:
  name: flux
  namespace: flux-system
spec:
  distribution:
    version: "2.3.0"
    registry: "ghcr.io/controlplaneio-fluxcd/distroless"
    imagePullSecret: "flux-enterprise-auth"
    artifact: "oci://ghcr.io/controlplaneio-fluxcd/flux-operator-manifests"

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
@stefanprodan stefanprodan added enhancement New feature or request area/update-automation Flux update automation related issues and pull requests labels Jun 15, 2024
@stefanprodan stefanprodan requested a review from souleb June 15, 2024 11:45
@stefanprodan stefanprodan force-pushed the distro-artifact branch 2 times, most recently from 33373a5 to 09e1350 Compare June 15, 2024 11:58
curl -sLO https://github.com/controlplaneio-fluxcd/distribution/archive/refs/heads/main.tar.gz
tar xzf main.tar.gz -C "${DEST_DIR}"

mkdir -p "${IMG_DIR}"
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe should add a check here?

Copy link
Member Author

Choose a reason for hiding this comment

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

-p will not create the dir if it exists.

internal/builder/pull.go Show resolved Hide resolved
internal/builder/options.go Outdated Show resolved Hide resolved
internal/controller/fluxinstance_controller.go Outdated Show resolved Hide resolved
// e.g. 'oci://ghcr.io/controlplaneio-fluxcd/flux-operator-manifests:latest'.
// +kubebuilder:validation:Pattern="^oci://.*$"
// +optional
Artifact string `json:"artifact,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

can we name it maybe artifactURL?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did consider this but given that we use registry and not registryURL, for consistency I chose to not have the URL suffix.

@stefanprodan stefanprodan force-pushed the distro-artifact branch 2 times, most recently from e134caf to a2fd0f2 Compare June 16, 2024 05:35
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
ctxPull, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

artifactDigest, err := builder.PullArtifact(ctxPull, artifactURL, tmpDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I got it correctly, at every reconciliation we fetch the manifests and don't store it locally. What do you think about storing the artifact and its manifest digest, at each reconciliation, we would first fetch the manifest and compare the digest with local version before attempting to fetch the blob?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we could have a similar storage & auth implementation as SC in a followup PR. I'm also considering using the layer caching I implemented in Timoni which is more close to how OverlayFS works in OCI registries.

Copy link
Contributor

@souleb souleb left a comment

Choose a reason for hiding this comment

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

LGTM!

@stefanprodan stefanprodan merged commit 5410bea into main Jun 17, 2024
1 check passed
@stefanprodan stefanprodan deleted the distro-artifact branch June 17, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/update-automation Flux update automation related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants