Skip to content

Commit 3a93f37

Browse files
committed
Adding additional tests for ociRepository chartRef
Signed-off-by: Soule BA <bah.soule@gmail.com>
1 parent e85adca commit 3a93f37

File tree

7 files changed

+459
-15
lines changed

7 files changed

+459
-15
lines changed

.github/workflows/e2e.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ jobs:
138138
kubectl -n install-create-target-ns get deployment install-create-target-ns-install-create-target-ns-podinfo
139139
140140
kubectl -n helm-system delete -f config/testdata/install-create-target-ns
141+
- name: Run install from ocirepo test
142+
run: |
143+
kubectl -n helm-system apply -f config/testdata/install-from-ocirepo-source
144+
kubectl -n helm-system wait helmreleases/podinfo-from-ocirepo --for=condition=ready --timeout=4m
145+
kubectl -n helm-system delete -f config/testdata/install-from-ocirepo-source
141146
- name: Run install fail test
142147
run: |
143148
test_name=install-fail

api/v2beta2/reference_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type CrossNamespaceSourceReference struct {
5050
APIVersion string `json:"apiVersion,omitempty"`
5151

5252
// Kind of the referent.
53-
// +kubebuilder:validation:Enum=OCIRepository;HelmChart
53+
// +kubebuilder:validation:Enum=OCIRepository
5454
// +required
5555
Kind string `json:"kind"`
5656

config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,6 @@ spec:
13031303
description: Kind of the referent.
13041304
enum:
13051305
- OCIRepository
1306-
- HelmChart
13071306
type: string
13081307
name:
13091308
description: Name of the referent.

config/rbac/role.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ rules:
5555
- helmcharts/status
5656
verbs:
5757
- get
58+
- apiGroups:
59+
- source.toolkit.fluxcd.io
60+
resources:
61+
- ocirepositories
62+
verbs:
63+
- get
64+
- list
65+
- watch
66+
- apiGroups:
67+
- source.toolkit.fluxcd.io
68+
resources:
69+
- ocirepositories/status
70+
verbs:
71+
- get
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
apiVersion: source.toolkit.fluxcd.io/v1beta2
3+
kind: OCIRepository
4+
metadata:
5+
name: podinfo-ocirepo
6+
spec:
7+
interval: 10m
8+
url: oci://ghcr.io/stefanprodan/charts/podinfo
9+
ref:
10+
tag: 6.6.0
11+
---
12+
apiVersion: helm.toolkit.fluxcd.io/v2beta2
13+
kind: HelmRelease
14+
metadata:
15+
name: podinfo-from-ocirepo
16+
spec:
17+
releaseName: podinfo
18+
chartRef:
19+
kind: OCIRepository
20+
name: podinfo-ocirepo
21+
interval: 50m
22+
driftDetection:
23+
mode: enabled
24+
install:
25+
timeout: 10m
26+
remediation:
27+
retries: 3
28+
upgrade:
29+
timeout: 10m
30+
values:
31+
resources:
32+
requests:
33+
cpu: 100m
34+
memory: 64Mi

internal/controller/helmrelease_controller.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import (
7474
// +kubebuilder:rbac:groups=helm.toolkit.fluxcd.io,resources=helmreleases/finalizers,verbs=get;create;update;patch;delete
7575
// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=helmcharts,verbs=get;list;watch
7676
// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=helmcharts/status,verbs=get
77+
// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=ocirepositories,verbs=get;list;watch
78+
// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=ocirepositories/status,verbs=get
7779
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch
7880

7981
// HelmReleaseReconciler reconciles a HelmRelease object.
@@ -155,7 +157,7 @@ func (r *HelmReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request)
155157
}
156158

157159
if !isValidChartRef(obj) {
158-
return ctrl.Result{}, reconcile.TerminalError(fmt.Errorf("invalid HelmChart reference"))
160+
return ctrl.Result{}, reconcile.TerminalError(fmt.Errorf("invalid Chart reference"))
159161
}
160162

161163
// Initialize the patch helper with the current version of the object.
@@ -277,7 +279,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe
277279
return ctrl.Result{}, reconcile.TerminalError(err)
278280
}
279281

280-
msg := fmt.Sprintf("could not get HelmChart object: %s", err.Error())
282+
msg := fmt.Sprintf("could not get Source object: %s", err.Error())
281283
conditions.MarkFalse(obj, meta.ReadyCondition, v2.ArtifactFailedReason, msg)
282284
return ctrl.Result{}, err
283285
}
@@ -289,13 +291,13 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe
289291
// Check if the source is ready.
290292
if ready, msg := isSourceReady(source); !ready {
291293
log.Info(msg)
292-
conditions.MarkFalse(obj, meta.ReadyCondition, "HelmChartNotReady", msg)
294+
conditions.MarkFalse(obj, meta.ReadyCondition, "SourceNotReady", msg)
293295
// Do not requeue immediately, when the artifact is created
294296
// the watcher should trigger a reconciliation.
295297
return jitter.JitteredRequeueInterval(ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}), errWaitForChart
296298
}
297299
// Remove any stale corresponding Ready=False condition with Unknown.
298-
if conditions.HasAnyReason(obj, meta.ReadyCondition, "HelmChartNotReady") {
300+
if conditions.HasAnyReason(obj, meta.ReadyCondition, "SourceNotReady") {
299301
conditions.MarkUnknown(obj, meta.ReadyCondition, meta.ProgressingReason, "reconciliation in progress")
300302
}
301303

@@ -315,7 +317,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe
315317
loadedChart, err := loader.SecureLoadChartFromURL(loader.NewRetryableHTTPClient(ctx, r.artifactFetchRetries), source.GetArtifact().URL, source.GetArtifact().Digest)
316318
if err != nil {
317319
if errors.Is(err, loader.ErrFileNotFound) {
318-
msg := fmt.Sprintf("Chart not ready: artifact not found. Retrying in %s", r.requeueDependency.String())
320+
msg := fmt.Sprintf("Source not ready: artifact not found. Retrying in %s", r.requeueDependency.String())
319321
conditions.MarkFalse(obj, meta.ReadyCondition, v2.ArtifactFailedReason, msg)
320322
log.Info(msg)
321323
return ctrl.Result{RequeueAfter: r.requeueDependency}, errWaitForDependency
@@ -678,6 +680,9 @@ func (r *HelmReleaseReconciler) getSource(ctx context.Context, obj *v2.HelmRelea
678680
return r.getHelmChartFromOCIRef(ctx, obj)
679681
}
680682
name, namespace = obj.Spec.ChartRef.Name, obj.Spec.ChartRef.Namespace
683+
if namespace == "" {
684+
namespace = obj.GetNamespace()
685+
}
681686
} else {
682687
namespace, name = obj.Status.GetHelmChart()
683688
}
@@ -696,7 +701,10 @@ func (r *HelmReleaseReconciler) getSource(ctx context.Context, obj *v2.HelmRelea
696701
}
697702

698703
func (r *HelmReleaseReconciler) getHelmChartFromOCIRef(ctx context.Context, obj *v2.HelmRelease) (source.Source, error) {
699-
namespace, name := obj.Spec.ChartRef.Name, obj.Spec.ChartRef.Namespace
704+
name, namespace := obj.Spec.ChartRef.Name, obj.Spec.ChartRef.Namespace
705+
if namespace == "" {
706+
namespace = obj.GetNamespace()
707+
}
700708
ociRepoRef := types.NamespacedName{Namespace: namespace, Name: name}
701709

702710
if err := intacl.AllowsAccessTo(obj, sourcev1.OCIRepositoryKind, ociRepoRef); err != nil {

0 commit comments

Comments
 (0)