Update controller to OCIRepository v1 (GA)

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan 2025-05-28 14:37:02 +03:00
parent ff69170036
commit 034ea18c4b
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF
14 changed files with 63 additions and 72 deletions

View File

@ -43,7 +43,7 @@ operator.
## Guides
* [Get started with GitOps Toolkit](https://fluxcd.io/flux/get-started/)
* [Get started with Flux](https://fluxcd.io/flux/get-started/)
* [Manage Helm Releases](https://fluxcd.io/flux/guides/helmreleases/)
* [Setup Notifications](https://fluxcd.io/flux/guides/notifications/)

View File

@ -2,8 +2,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: helm-system
resources:
- https://github.com/fluxcd/source-controller/releases/download/v1.5.0/source-controller.crds.yaml
- https://github.com/fluxcd/source-controller/releases/download/v1.5.0/source-controller.deployment.yaml
- https://github.com/fluxcd/source-controller/releases/download/v1.6.0/source-controller.crds.yaml
- https://github.com/fluxcd/source-controller/releases/download/v1.6.0/source-controller.deployment.yaml
- ../crd
- ../rbac
- ../manager

View File

@ -1,4 +1,4 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
name: podinfo

View File

@ -1,5 +1,5 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
name: podinfo-ocirepo
@ -9,7 +9,7 @@ spec:
ref:
tag: 6.6.0
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: podinfo-from-ocirepo

View File

@ -1,5 +1,5 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
name: upgrade-from-ocirepo-source
@ -9,7 +9,7 @@ spec:
ref:
digest: "sha256:cdd538a0167e4b51152b71a477e51eb6737553510ce8797dbcc537e1342311bb"
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: upgrade-from-ocirepo-source

View File

@ -1,5 +1,5 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
name: upgrade-from-ocirepo-source

View File

@ -232,7 +232,7 @@ HelmRelease object.
#### OCIRepository reference example
```yaml
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
name: podinfo

View File

@ -56,7 +56,6 @@ import (
"github.com/fluxcd/pkg/runtime/patch"
"github.com/fluxcd/pkg/runtime/predicates"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/fluxcd/pkg/chartutil"
@ -143,7 +142,7 @@ func (r *HelmReleaseReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
builder.WithPredicates(intpredicates.SourceRevisionChangePredicate{}),
).
Watches(
&sourcev1beta2.OCIRepository{},
&sourcev1.OCIRepository{},
handler.EnqueueRequestsFromMapFunc(r.requestsForOCIRrepositoryChange),
builder.WithPredicates(intpredicates.SourceRevisionChangePredicate{}),
).
@ -436,7 +435,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe
return jitter.JitteredRequeueInterval(ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}), nil
}
// reconcileDelete deletes the v1beta2.HelmChart of the v2.HelmRelease,
// reconcileDelete deletes the v1.HelmChart of the v2.HelmRelease,
// and uninstalls the Helm release if the resource has not been suspended.
func (r *HelmReleaseReconciler) reconcileDelete(ctx context.Context, obj *v2.HelmRelease) (ctrl.Result, error) {
// Only uninstall the release and delete the HelmChart resource if the
@ -712,7 +711,7 @@ func (r *HelmReleaseReconciler) buildRESTClientGetter(ctx context.Context, obj *
func (r *HelmReleaseReconciler) getSource(ctx context.Context, obj *v2.HelmRelease) (sourcev1.Source, error) {
var name, namespace string
if obj.HasChartRef() {
if obj.Spec.ChartRef.Kind == sourcev1beta2.OCIRepositoryKind {
if obj.Spec.ChartRef.Kind == sourcev1.OCIRepositoryKind {
return r.getSourceFromOCIRef(ctx, obj)
}
name, namespace = obj.Spec.ChartRef.Name, obj.Spec.ChartRef.Namespace
@ -743,11 +742,11 @@ func (r *HelmReleaseReconciler) getSourceFromOCIRef(ctx context.Context, obj *v2
}
ociRepoRef := types.NamespacedName{Namespace: namespace, Name: name}
if err := intacl.AllowsAccessTo(obj, sourcev1beta2.OCIRepositoryKind, ociRepoRef); err != nil {
if err := intacl.AllowsAccessTo(obj, sourcev1.OCIRepositoryKind, ociRepoRef); err != nil {
return nil, err
}
or := sourcev1beta2.OCIRepository{}
or := sourcev1.OCIRepository{}
if err := r.Client.Get(ctx, ociRepoRef, &or); err != nil {
return nil, err
}
@ -805,7 +804,7 @@ func (r *HelmReleaseReconciler) requestsForHelmChartChange(ctx context.Context,
}
func (r *HelmReleaseReconciler) requestsForOCIRrepositoryChange(ctx context.Context, o client.Object) []reconcile.Request {
or, ok := o.(*sourcev1beta2.OCIRepository)
or, ok := o.(*sourcev1.OCIRepository)
if !ok {
err := fmt.Errorf("expected an OCIRepository, got %T", o)
ctrl.LoggerFrom(ctx).Error(err, "failed to get requests for OCIRepository change")
@ -907,7 +906,7 @@ func (r *HelmReleaseReconciler) mutateChartWithSourceRevision(chart *chart.Chart
// If the source is an OCIRepository, we can try to mutate the chart version
// with the artifact revision. The revision is either a <tag>@<digest> or
// just a digest.
obj, ok := source.(*sourcev1beta2.OCIRepository)
obj, ok := source.(*sourcev1.OCIRepository)
if !ok {
// if not make sure to return an empty string to delete the digest of the
// last attempted revision

View File

@ -54,7 +54,6 @@ import (
feathelper "github.com/fluxcd/pkg/runtime/features"
"github.com/fluxcd/pkg/runtime/patch"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
v2 "github.com/fluxcd/helm-controller/api/v2"
intacl "github.com/fluxcd/helm-controller/internal/acl"
@ -1448,17 +1447,17 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
t.Run("waits for ChartRef to have an Artifact", func(t *testing.T) {
g := NewWithT(t)
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
TypeMeta: metav1.TypeMeta{
APIVersion: sourcev1beta2.GroupVersion.String(),
Kind: sourcev1beta2.OCIRepositoryKind,
APIVersion: sourcev1.GroupVersion.String(),
Kind: sourcev1.OCIRepositoryKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: "mock",
Generation: 2,
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 2,
Conditions: []metav1.Condition{
{
@ -1505,16 +1504,16 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
t.Run("reports values composition failure", func(t *testing.T) {
g := NewWithT(t)
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: "mock",
Generation: 2,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 2,
Artifact: &sourcev1.Artifact{},
Conditions: []metav1.Condition{
@ -1567,16 +1566,16 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
t.Run("reports Helm chart load failure", func(t *testing.T) {
g := NewWithT(t)
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: "mock",
Generation: 2,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 2,
Artifact: &sourcev1.Artifact{
URL: testServer.URL() + "/does-not-exist",
@ -1644,16 +1643,16 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
},
}
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: "mock",
Generation: 2,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 2,
Artifact: &sourcev1.Artifact{
URL: testServer.URL() + "/does-not-exist",
@ -1713,16 +1712,16 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
g.Expect(err).ToNot(HaveOccurred())
chartArtifact.Revision += "@" + chartArtifact.Digest
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: "mock",
Generation: 1,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 1,
Artifact: chartArtifact,
Conditions: []metav1.Condition{
@ -1805,17 +1804,17 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
})
// ocirepo is the chartRef object to switch to.
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: ns.Name,
Generation: 1,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
URL: "oci://test-example.com",
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 1,
Artifact: ociArtifact,
Conditions: []metav1.Condition{
@ -1898,17 +1897,17 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
})
// ocirepo is the chartRef object to switch to.
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: ns.Name,
Generation: 1,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
URL: "oci://test-example.com",
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 1,
Artifact: ociArtifact,
Conditions: []metav1.Condition{
@ -1975,17 +1974,17 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
})
// ocirepo is the chartRef object to switch to.
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: ns.Name,
Generation: 1,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
URL: "oci://test-example.com",
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 1,
Artifact: ociArtifact,
Conditions: []metav1.Condition{
@ -2078,17 +2077,17 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
}
// ocirepo is the chartRef object to switch to.
ocirepo := &sourcev1beta2.OCIRepository{
ocirepo := &sourcev1.OCIRepository{
ObjectMeta: metav1.ObjectMeta{
Name: "ocirepo",
Namespace: ns.Name,
Generation: 1,
},
Spec: sourcev1beta2.OCIRepositorySpec{
Spec: sourcev1.OCIRepositorySpec{
URL: "oci://test-example.com",
Interval: metav1.Duration{Duration: 1 * time.Second},
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 1,
Artifact: ociArtifact,
Conditions: []metav1.Condition{
@ -3781,17 +3780,17 @@ func Test_isHelmChartReady(t *testing.T) {
}
func Test_isOCIRepositoryReady(t *testing.T) {
mock := &sourcev1beta2.OCIRepository{
mock := &sourcev1.OCIRepository{
TypeMeta: metav1.TypeMeta{
Kind: sourcev1beta2.OCIRepositoryKind,
APIVersion: sourcev1beta2.GroupVersion.String(),
Kind: sourcev1.OCIRepositoryKind,
APIVersion: sourcev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "mock",
Namespace: "default",
Generation: 2,
},
Status: sourcev1beta2.OCIRepositoryStatus{
Status: sourcev1.OCIRepositoryStatus{
ObservedGeneration: 2,
Conditions: []metav1.Condition{
{
@ -3805,7 +3804,7 @@ func Test_isOCIRepositoryReady(t *testing.T) {
tests := []struct {
name string
obj *sourcev1beta2.OCIRepository
obj *sourcev1.OCIRepository
want bool
wantReason string
}{
@ -3816,7 +3815,7 @@ func Test_isOCIRepositoryReady(t *testing.T) {
},
{
name: "OCIRepository generation differs from observed generation while Ready=True",
obj: func() *sourcev1beta2.OCIRepository {
obj: func() *sourcev1.OCIRepository {
m := mock.DeepCopy()
m.Generation = 3
return m
@ -3826,7 +3825,7 @@ func Test_isOCIRepositoryReady(t *testing.T) {
},
{
name: "OCIRepository generation differs from observed generation while Ready=False",
obj: func() *sourcev1beta2.OCIRepository {
obj: func() *sourcev1.OCIRepository {
m := mock.DeepCopy()
m.Generation = 3
conditions.MarkFalse(m, meta.ReadyCondition, "Reason", "some reason")
@ -3837,7 +3836,7 @@ func Test_isOCIRepositoryReady(t *testing.T) {
},
{
name: "OCIRepository has Stalled=True",
obj: func() *sourcev1beta2.OCIRepository {
obj: func() *sourcev1.OCIRepository {
m := mock.DeepCopy()
conditions.MarkFalse(m, meta.ReadyCondition, "Reason", "some reason")
conditions.MarkStalled(m, "Reason", "some stalled reason")
@ -3848,7 +3847,7 @@ func Test_isOCIRepositoryReady(t *testing.T) {
},
{
name: "OCIRepository does not have an Artifact",
obj: func() *sourcev1beta2.OCIRepository {
obj: func() *sourcev1.OCIRepository {
m := mock.DeepCopy()
m.Status.Artifact = nil
return m
@ -3918,8 +3917,8 @@ func Test_TryMutateChartWithSourceRevision(t *testing.T) {
},
}
s := &sourcev1beta2.OCIRepository{
Status: sourcev1beta2.OCIRepositoryStatus{
s := &sourcev1.OCIRepository{
Status: sourcev1.OCIRepositoryStatus{
Artifact: &sourcev1.Artifact{
Revision: tt.revision,
},

View File

@ -32,7 +32,6 @@ import (
"github.com/fluxcd/pkg/runtime/testenv"
"github.com/fluxcd/pkg/testserver"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
v2 "github.com/fluxcd/helm-controller/api/v2"
// +kubebuilder:scaffold:imports
@ -50,7 +49,6 @@ func NewTestScheme() *runtime.Scheme {
utilruntime.Must(corev1.AddToScheme(s))
utilruntime.Must(apiextensionsv1.AddToScheme(s))
utilruntime.Must(sourcev1.AddToScheme(s))
utilruntime.Must(sourcev1beta2.AddToScheme(s))
utilruntime.Must(v2.AddToScheme(s))
return s
}

View File

@ -39,11 +39,11 @@ import (
"github.com/fluxcd/helm-controller/internal/strings"
)
// HelmChartTemplate attempts to create, update or delete a v1beta2.HelmChart
// HelmChartTemplate attempts to create, update or delete a v1.HelmChart
// based on the given Request data.
//
// It does this by building a v1beta2.HelmChart from the template declared in
// the v2.HelmRelease, and then reconciling that v1beta2.HelmChart using
// It does this by building a v1.HelmChart from the template declared in
// the v2.HelmRelease, and then reconciling that v1.HelmChart using
// a server-side apply.
//
// When the server-side apply succeeds, the namespaced name of the chart is
@ -59,7 +59,7 @@ import (
// indicates they should retry.
//
// In case the v2.HelmRelease is marked for deletion, the reconciler will
// not continue to attempt to create or update the v1beta2.HelmChart.
// not continue to attempt to create or update the v1.HelmChart.
type HelmChartTemplate struct {
client client.Client
eventRecorder record.EventRecorder
@ -212,8 +212,8 @@ func (r *HelmChartTemplate) reconcileDelete(ctx context.Context, obj *v2.HelmRel
return nil
}
// buildHelmChartFromTemplate builds a v1beta2.HelmChart from the
// v2beta1.HelmChartTemplate of the given v2beta1.HelmRelease.
// buildHelmChartFromTemplate builds a v1.HelmChart from the
// v2.HelmChartTemplate of the given v2.HelmRelease.
func buildHelmChartFromTemplate(obj *v2.HelmRelease) *sourcev1.HelmChart {
template := obj.Spec.Chart.DeepCopy()
result := &sourcev1.HelmChart{

View File

@ -32,7 +32,6 @@ import (
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
v2 "github.com/fluxcd/helm-controller/api/v2"
"github.com/fluxcd/helm-controller/internal/acl"
@ -485,7 +484,7 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) {
Spec: v2.HelmReleaseSpec{
Interval: metav1.Duration{Duration: 1 * time.Hour},
ChartRef: &v2.CrossNamespaceSourceReference{
Kind: sourcev1beta2.OCIRepositoryKind,
Kind: sourcev1.OCIRepositoryKind,
Name: "oci-repository",
},
},

View File

@ -40,7 +40,6 @@ import (
"github.com/fluxcd/pkg/runtime/testenv"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
v2 "github.com/fluxcd/helm-controller/api/v2"
)
@ -57,7 +56,6 @@ func NewTestScheme() *runtime.Scheme {
utilruntime.Must(corev1.AddToScheme(s))
utilruntime.Must(apiextensionsv1.AddToScheme(s))
utilruntime.Must(sourcev1.AddToScheme(s))
utilruntime.Must(sourcev1beta2.AddToScheme(s))
utilruntime.Must(v2.AddToScheme(s))
return s
}

View File

@ -47,7 +47,6 @@ import (
"github.com/fluxcd/pkg/runtime/pprof"
"github.com/fluxcd/pkg/runtime/probes"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
v2 "github.com/fluxcd/helm-controller/api/v2"
intdigest "github.com/fluxcd/helm-controller/internal/digest"
@ -72,7 +71,6 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(sourcev1.AddToScheme(scheme))
utilruntime.Must(sourcev1beta2.AddToScheme(scheme))
utilruntime.Must(v2.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}