-
Notifications
You must be signed in to change notification settings - Fork 163
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
Add support for OCIRepository
as chartRef
#905
Conversation
35da8cd
to
87fd317
Compare
3a93f37
to
5cf3d4d
Compare
2ddf5c2
to
07c3cc4
Compare
976ee54
to
071fbef
Compare
@@ -95,6 +95,20 @@ func (r *HelmChartTemplate) Reconcile(ctx context.Context, req *Request) error { | |||
} | |||
} | |||
|
|||
if mustCleanDeployedChart(obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simply let the existence of a reference take precedence over the template existing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption is that if a user switch to a chartRef
and wants to use an existing ociRepo
it is because he wants to reduce the number of existing helmChart
resources. So if we don't clean up during the reconciliation, the user will likely perform the clean up by other means. That would leave a status
that does not reflect the actual state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a must to cleanup the old Charts from storage and etcd.
if !isValidChartRef(obj) { | ||
return ctrl.Result{}, reconcile.TerminalError(fmt.Errorf("invalid Chart reference")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is expected to be an impossible scenario, right? Because the API server validation won't allow such object to be created.
But if there's a possibility for such object to be reconciled, ensuring that the object status reflects a stalled condition would be better. That is, moving to reconcileRelease()
, marking the object with Ready=False and Stalled=True, and then returning the terminal error would be ideal.
But it can be left as it is if we will never process such object and the API server will let the user know about the invalid object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use CEL validation to have a oneOf
validation behaviour. Quoting here "Kubernetes CRD Validation Using CEL has been turned on by default since Kubernetes 1.25 and graduated to GA in Kubernetes 1.29." As of now we support k8s from 1.27 so most likely it is safe, but I assume that it is still a possible scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the broken code references from the last commit locally and did some manual testing and it works nicely.
Left some minor suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear from this PR if a mutable tag will trigger a Helm upgrade when the upstream digest changes. Can we have a test for this?
b40425d
to
d875211
Compare
OCIRepository
as chartRef
d875211
to
4bdc4c3
Compare
0cfb143
to
48fa9eb
Compare
Stuck helm-controller, the OCIRepo predicate is buggy:
The OCIRepo apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
metadata:
annotations:
reconcile.fluxcd.io/requestedAt: "2024-04-12T20:09:15.148746+03:00"
creationTimestamp: "2024-04-12T17:02:24Z"
finalizers:
- finalizers.fluxcd.io
generation: 2
name: podinfo
namespace: podinfo
resourceVersion: "5910"
uid: d2464665-8e4c-4845-a449-2e7a384c3292
spec:
interval: 1m
layerSelector:
mediaType: application/vnd.cncf.helm.chart.content.v1.tar+gzip
operation: copy
provider: generic
ref:
semver: '>=5.0.0'
timeout: 60s
url: oci://ghcr.io/stefanprodan/charts/podinfo
verify:
provider: notation
secretRef:
name: podinfo-notation
status:
artifact:
digest: sha256:9db648076519fe8ae594182fe0bb74bceb3bd516407d5da6577216d12a1f6625
lastUpdateTime: "2024-04-12T17:07:06Z"
metadata:
org.opencontainers.image.authors: stefanprodan ([email protected])
org.opencontainers.image.created: "2024-04-10T11:07:52Z"
org.opencontainers.image.description: Podinfo Helm chart for Kubernetes
org.opencontainers.image.source: https://github.com/stefanprodan/podinfo
org.opencontainers.image.title: podinfo
org.opencontainers.image.url: https://github.com/stefanprodan/podinfo
org.opencontainers.image.version: 6.6.2
path: ocirepository/podinfo/podinfo/sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154.tar.gz
revision: 6.6.2@sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154
size: 14905
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/podinfo/podinfo/sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154.tar.gz
conditions:
- lastTransitionTime: "2024-04-12T17:02:45Z"
message: stored artifact for digest '6.6.2@sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154'
observedGeneration: 2
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2024-04-12T17:02:45Z"
message: stored artifact for digest '6.6.2@sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154'
observedGeneration: 2
reason: Succeeded
status: "True"
type: ArtifactInStorage
- lastTransitionTime: "2024-04-12T17:02:45Z"
message: verified signature of revision 6.6.2@sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154
observedGeneration: 2
reason: Succeeded
status: "True"
type: SourceVerified
lastHandledReconcileAt: "2024-04-12T20:09:15.148746+03:00"
observedGeneration: 2
observedLayerSelector:
mediaType: application/vnd.cncf.helm.chart.content.v1.tar+gzip
operation: copy
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/podinfo/podinfo/latest.tar.gz |
The test succeded event does not contain the oci-digest annotation and breaks the promotion workflow:
The upgrade event has it:
|
4ce7e3c
to
94ccc4f
Compare
Just tested, test events show the - apiVersion: v1
count: 1
eventTime: null
firstTimestamp: "2024-04-16T08:48:41Z"
involvedObject:
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
name: podinfo
namespace: default
resourceVersion: "3928"
uid: 280e469f-e21e-4edd-b577-8d6ead548396
kind: Event
lastTimestamp: "2024-04-16T08:48:41Z"
message: 'Helm test succeeded for release default/podinfo.v2 with chart [email protected]+83295d47de6d:
3 test hooks completed successfully'
metadata:
annotations:
helm.toolkit.fluxcd.io/oci-digest: sha256:83295d47de6d6ca634ed4b952a7572fc176bcc38854d0c11ca0fa197bc5f1154
helm.toolkit.fluxcd.io/revision: 6.6.2+83295d47de6d
helm.toolkit.fluxcd.io/token: sha256:5ee5478adca0d5fa927d1ebff4714f8eea683389ac0e21489b5572806e3ab307
creationTimestamp: "2024-04-16T08:48:41Z"
name: podinfo.17c6b674cd8c4571
namespace: default
resourceVersion: "4061"
uid: 15a0533d-68d0-43ae-b019-ff3dd26ddbd2
reason: TestSucceeded
reportingComponent: helm-controller
reportingInstance: ""
source:
component: helm-controller
type: Normal
kind: List
metadata:
resourceVersion: "" |
@@ -182,7 +182,7 @@ func observeRollback(obj *v2.HelmRelease) storage.ObserveFunc { | |||
for i := range obj.Status.History { | |||
snap := obj.Status.History[i] | |||
if snap.Targets(rls.Name, rls.Namespace, rls.Version) { | |||
newSnap := release.ObservedToSnapshot(release.ObserveRelease(rls)) | |||
newSnap := release.ObservedToSnapshot(releaseToObservation(rls, snap)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that if no matching snapshot is found, we have no way of retrieving the corresponding oci digest
.
453b631
to
2da06bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Awesome contribution! Thanks @souleb 🥇
PS. I have run extensive tests and all the issues I found are now fixed.
is this ready to go live? can't wait to use it |
@gabrielqs this will be released in Flux v2.3, see fluxcd/flux2#4712 |
I plan to merge this tomorrow, so late reviews can still happen. |
It takes into account switching from a chart template to a referenced source (garbage collection). Signed-off-by: Soule BA <[email protected]>
Co-authored-by: Hidde Beydals <[email protected]> Signed-off-by: souleb <[email protected]>
Signed-off-by: Soule BA <[email protected]>
Signed-off-by: Soule BA <[email protected]>
Signed-off-by: Soule BA <[email protected]>
Co-authored-by: Stefan Prodan <[email protected]> Signed-off-by: souleb <[email protected]>
This is needed for an OCIRepository source in order to detect change for mutable tags. Signed-off-by: Soule BA <[email protected]>
Signed-off-by: Soule BA <[email protected]>
This commit add the oci artifact digest into the release observed snapshot. This is used to later to add that value as an annotation. Signed-off-by: Soule BA <[email protected]>
The test case successfully upgrade with the same chart because version is not computed the same way (12 digits of digest appended for OCIRepository source). Signed-off-by: Soule BA <[email protected]>
Signed-off-by: Soule BA <[email protected]>
Use artifact digest instead of revision to validate whether to trigger a new reconciliation Signed-off-by: Soule BA <[email protected]>
2da06bc
to
a98d957
Compare
Add support for `OCIRepository` as chartRef Signed-off-by: Sean Eagan <[email protected]>
Add support for `OCIRepository` as chartRef
fixes #789 #903