Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ rules:
- patch
- update
- watch
- apiGroups:
- source.fluxcd.io
resources:
- helmcharts/finalizers
verbs:
- get
- patch
- update
- apiGroups:
- source.fluxcd.io
resources:
Expand Down
15 changes: 15 additions & 0 deletions controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{Requeue: true}, err
}

// set ownership reference so chart is garbage collected on
// repository removal
r.setOwnerRef(ctx, &chart, repository)

// try to pull chart
pulledChart, err := r.sync(repository, *chart.DeepCopy())
if err != nil {
Expand Down Expand Up @@ -282,3 +286,14 @@ func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart) {
}
}
}

func (r *HelmChartReconciler) setOwnerRef(ctx context.Context, chart *sourcev1.HelmChart, repository sourcev1.HelmRepository) {
if metav1.IsControlledBy(chart.GetObjectMeta(), repository.GetObjectMeta()) {
return
}
chart.SetOwnerReferences(append(chart.GetOwnerReferences(),
*metav1.NewControllerRef(repository.GetObjectMeta(), repository.GroupVersionKind())))
if err := r.Update(ctx, chart); err != nil {
r.Log.Error(err, fmt.Sprintf("failed to set owner reference to HelmRepository '%s'", repository.Name))
}
}
1 change: 1 addition & 0 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type HelmRepositoryReconciler struct {

// +kubebuilder:rbac:groups=source.fluxcd.io,resources=helmrepositories,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=source.fluxcd.io,resources=helmrepositories/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=source.fluxcd.io,resources=helmcharts/finalizers,verbs=get;update;patch

func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
Expand Down