Skip to content

Commit

Permalink
enable reusing an existing OCIRepo as chartRef
Browse files Browse the repository at this point in the history
Signed-off-by: Soule BA <[email protected]>
  • Loading branch information
souleb committed Mar 9, 2024
1 parent 5e83e51 commit d01518c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
7 changes: 6 additions & 1 deletion api/v2beta2/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ type PostRenderer struct {
}

// HelmReleaseSpec defines the desired state of a Helm release.
// +kubebuilder:validation:XValidation:rule="(has(self.chart) && !has(self.chartRef) || (!has(self.chart) && has(self.chartRef))", message="either chart or chartRef must be set"
type HelmReleaseSpec struct {
// Chart defines the template of the v1beta2.HelmChart that should be created
// for this HelmRelease.
// +required
// +optional
Chart HelmChartTemplate `json:"chart"`

// ChartRef holds a reference to a v1beta2.HelmChart resource
// +optional
ChartRef *CrosssNameSpaceSourceReference `json:"chartRef,omitempty"`

// Interval at which to reconcile the Helm release.
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
Expand Down
26 changes: 26 additions & 0 deletions api/v2beta2/reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ type CrossNamespaceObjectReference struct {
Namespace string `json:"namespace,omitempty"`
}

// CrosssNameSpaceSourceReference contains enough information to let you locate
// the typed referenced object at cluster level.
type CrosssNameSpaceSourceReference struct {
// APIVersion of the referent.
// +optional
APIVersion string `json:"apiVersion,omitempty"`

// Kind of the referent.
// +kubebuilder:validation:Enum=OCIRepository;HelmChart
// +required
Kind string `json:"kind"`

// Name of the referent.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +required
Name string `json:"name"`

// Namespace of the referent.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Optional
// +optional
Namespace string `json:"namespace,omitempty"`
}

// ValuesReference contains a reference to a resource containing Helm values,
// and optionally the key they can be found at.
type ValuesReference struct {
Expand Down
20 changes: 20 additions & 0 deletions api/v2beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,32 @@ spec:
required:
- spec
type: object
chartRef:
description: ChartRef holds a reference to a v1beta2.HelmChart resource
properties:
apiVersion:
description: APIVersion of the referent.
type: string
kind:
description: Kind of the referent.
enum:
- OCIRepository
- HelmChart
type: string
name:
description: Name of the referent.
maxLength: 253
minLength: 1
type: string
namespace:
description: Namespace of the referent.
maxLength: 63
minLength: 1
type: string
required:
- kind
- name
type: object
dependsOn:
description: DependsOn may contain a meta.NamespacedObjectReference
slice with references to HelmRelease resources that must be ready
Expand Down Expand Up @@ -2002,9 +2028,12 @@ spec:
type: object
type: array
required:
- chart
- interval
type: object
x-kubernetes-validations:
- message: either chart or chartRef must be set
rule: (has(self.chart) && !has(self.chartRef) || (!has(self.chart) &&
has(self.chartRef))
status:
default:
observedGeneration: -1
Expand Down
19 changes: 15 additions & 4 deletions internal/controller/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ func (r *HelmReleaseReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
if err := mgr.GetFieldIndexer().IndexField(ctx, &v2.HelmRelease{}, v2.SourceIndexKey,
func(o client.Object) []string {
obj := o.(*v2.HelmRelease)
namespacedName := types.NamespacedName{}
if obj.Spec.ChartRef != nil {
namespacedName.Namespace = obj.Spec.ChartRef.Namespace
namespacedName.Name = obj.Spec.ChartRef.Name
} else {
namespacedName.Namespace = obj.Spec.Chart.GetNamespace(obj.GetNamespace())
namespacedName.Name = obj.GetHelmChartName()
}

return []string{
types.NamespacedName{
Namespace: obj.Spec.Chart.GetNamespace(obj.GetNamespace()),
Name: obj.GetHelmChartName(),
}.String(),
namespacedName.String(),
}
},
); err != nil {
Expand All @@ -131,6 +137,11 @@ func (r *HelmReleaseReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
handler.EnqueueRequestsFromMapFunc(r.requestsForHelmChartChange),
builder.WithPredicates(intpredicates.SourceRevisionChangePredicate{}),
).
Watches(
&sourcev1.OCIRepository{},
handler.EnqueueRequestsFromMapFunc(r.requestsForOCIRrepositoryChange),
builder.WithPredicates(intpredicates.SourceRevisionChangePredicate{}),
).
WithOptions(controller.Options{
RateLimiter: opts.RateLimiter,
}).
Expand Down

0 comments on commit d01518c

Please sign in to comment.