We want to make it possible to reconcile workload from OCI Registries, the same we can reconcile today from git or Helm repositories. The targets are Helm charts and kubernetes manifests.
We want to make it possible to reconcile workloads from OCI Registries, the same we can reconcile today from Git or Helm repositories.
The targets are Helm charts and Kubernetes manifests packaged as OCI artifacts.
## Motivation
Registries are evolving into generic artifact stores. Many of our users would like to take advantage of this fact in order to store their kubernetes declaration and Helm charts in registries and apply them using Flux. Helm already supports oci registries to store Charts.
Registries are evolving into generic artifact stores.
Many of our users would like to take advantage of this fact in order to store their Kubernetes manifests
and Helm charts in OCI registries and reconcile them with Flux. Helm already supports OCI as Charts storage.
This [request](https://github.com/fluxcd/source-controller/issues/124) has been made to the Flux team to add support for Helm charts in OCI registries.
This [request](https://github.com/fluxcd/source-controller/issues/124) has been made to the Flux team
to add support for Helm charts stored in OCI registries.
### Goals
- Introduce a new source that can reconcile 2 OCI artifact types from OCI compliant registries, Helm artifact and OCI image.
- This new source must respect the existing source contract, i.e. it must produce the same outputs as the existing sources. this will enable existing consumers to use the new source with minimal effort.
- Introduce a new source that can reconcile artifacts from OCI compliant registries, Helm artifact and OCI image.
- This new source must respect the existing source contract, i.e. it must produce the same outputs as the existing sources.
This will enable existing consumers to use the new source with minimal effort.
- Pave the way for eventually supporting other OCI artifact types.
### Non-Goals
- Introduce a new OCI artifact type that can be used to store kubernetes manifests in OCI registries.
- Introduce a new OCI artifact type that can be used to store Kubernetes manifests in OCI registries.
## Proposal
Introduce 2 new Flux resources:
Introduce two Flux resources:
- `OCIRegistry`, which holds the registry information, i.e. URL and credentials.
- `OCIArtifact`, which holds the artifact information, mainly a reference to the desired tag, semantic version or digest.
An `OCIArtifact` can be used to reference a Helm Chart published with a Helm artifact media type or any tar package published with an OCI Image media type.
An `OCIArtifact` can be used to reference a Helm Chart published with a Helm artifact media type or any tar package
published with an OCI Image media type.
For any other artifact type, we will return an event stating that the OCI artifact type is not supported.
The OCI artifact reconciler will retrieve an artifact based on the url and credentials provided by the reference `OCIRegistry`, and store the artifact locally for dependent controllers to consume.
The Helm Chart reconciler will retrieve an artifact based on the url and credentials provided by the reference `OCIRegistry`, build the chart, and store the artifact locally for dependent controllers to consume.
The OCI artifact reconciler will retrieve an artifact based on the URL and credentials provided by the reference `OCIRegistry`,
and store the artifact locally for kustomize-controller to consume.
The Helm Chart reconciler will retrieve an artifact based on the URL and credentials provided by the reference `OCIRegistry`,
build the chart, and store the artifact locally for helm-controller to consume.
### User Stories
#### Story 1
As a developper I want to push my kubernetes manifests as a tar archive to an OCI Registry, and then use Flux to reconcile it in my cluster.
> As a developer I want to push my Kubernetes manifests as a tar archive to an OCI Registry,
and then use a Flux `Kustomization` to reconcile it in my cluster.
First you define an `OCIRegistry` and setup authentication:
```yaml
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRegistry
metadata:
name: ghcr-podinfo
namespace: flux-system
spec:
url: ghcr.io/stefanprodan
# required for private registries
auth:
# one of
secretRef:
name: regcred
serviceAccountName: reg
```
Then you define an `OCIArtifact` using the `OCIRegistry`:
And finally in the Flux `Kustomizations`, the `OCIArtifact` can be used instead of a `GitRepository`:
```yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: podinfo
namespace: flux-system
spec:
sourceRef:
kind: OCIArtifact
name: podinfo
path: ./
prune: true
targetNamespace: default
wait: true
interval: 60m
timeout: 2m
```
#### Story 2
As a developper I want to push my Helm charts using the Helm cli to an OCI Registry, and then use Flux to reconcile it in my cluster.
> As a developer I want to push my Helm charts using the Helm CLI to an OCI Registry,
and then use a Flux `HelmRelease` to reconcile it in my cluster.
First you define an `OCIRegistry` and setup authentication if needed:
```yaml
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRegistry
metadata:
name: ghcr-podinfo
namespace: flux-system
spec:
url: ghcr.io/stefanprodan
# required for private registries
auth:
# one of
secretRef:
name: regcred
serviceAccountName: reg
```
Then in Flux `HelmReleases`, the `OCIRegistry` can be used instead of a `HelmRepository`:
```yaml
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: podinfo
spec:
interval: 60m
chart:
spec:
chart: podinfo
version: '6.0.x'
sourceRef:
kind: OCIRegistry
name: ghcr-podinfo
interval: 1m
```
### Alternatives
We could keep the `OCIRepository` proposal and tie `OCIArtifact` and `OCIRegistry` specs. That is considered unpractical, as we would like to be able to reuse a registry spec for different artifact types with different reconcilers.
We could use the `OCIRepository` [proposal](https://github.com/fluxcd/source-controller/pull/450)
which bundles both an `OCIArtifact` and `OCIRegistry`. That is considered unpractical,
as we would like to be able to reuse a registry spec
for different artifact types with different reconcilers.
Instead of reusing the `oci image` mediaType to adress the need to store Kubernetes manifests declaration, we could register our own artifact type. This is also considered un practical, as declaring a type has to go through the IANA process and Flux is not the owner of those type as Helm is for Helm artifact for example.
Instead of reusing the `oci image` mediaType to address the need to store Kubernetes manifests declaration,
we could register our own artifact type. This is also considered un practical,
as declaring a type has to go through the IANA process and Flux is not the owner of those type
as Helm is for Helm artifact for example.
## Design Details
The new APIs:
APIspec:
```go
type OCIRegistrySpec struct {
@ -89,31 +201,29 @@ type OCIRepositoryAuth struct {
}
type OCIArtifactSpec struct {
// Name is the name of the artifact to pull.
// Repository is the name of the artifact repository.
@ -304,15 +357,21 @@ type OCIArtifactSpec struct {
`The OCI Registry` client pulls all artifacts layers for supported types.
The `OCIArtifact` and `HelmChart` reconciler will expect `data` to be in the first layer of the artifact, and will discard all the other layers. The controllers will then resolve the artifact dependencies, as it is a domain specific problem.
The `OCIArtifact` and `HelmChart` reconciler will expect `data` to be in the first layer of the artifact,
and will discard all the other layers. The controllers will then resolve the artifact dependencies,
as it is a domain specific problem.
For example, if we have a Helm artifact, the dependent Helm Chart controller will pull the artifact, extract the Chart and then resolve the chart dependencies.
For example, if we have a Helm artifact, the dependent Helm Chart controller will pull the artifact,
extract the Chart and then resolve the chart dependencies.
### Enabling the feature
The feature is enabled by default. You can disable it by setting the `enabe-oci-registry` flag to false. Which will prevent registering the oci reconcilers in the controller manager. For Helm, the flag is checked in the `HelmChart` reconciler.
The feature is enabled by default.
The Helm chart reconciler will have a new source for downloading the charts, but we will keep using the `remoteChartBuilder` to build the charts. The `remoteChartBuilder` will be modified to accept a `Remote` interface, in order to support the OCI Registry.
The Helm chart reconciler will have a new source for downloading the charts,
but we will keep using the `remoteChartBuilder` to build the charts. The `remoteChartBuilder`
will be modified to accept a `Remote` interface,
in order to support the OCI Registry.
## Follow-up work
@ -322,7 +381,9 @@ There will be a specific Flux command (built on top of ORAS) to help users push
The artifact will be of type `application/vnd.oci.image.config.v1+json`. The directory pointed to by `path` will be archived and compressed to `tar+gzip`. The layer media type will be `application/vnd.oci.image.layer.v1.tar+gzip`.
The artifact will be of type `application/vnd.oci.image.config.v1+json`.
The directory pointed to by `path` will be archived and compressed to `tar+gzip`.
The layer media type will be `application/vnd.oci.image.layer.v1.tar+gzip`.