Merge pull request #13 from fluxcd/helmchart-ownership
Set owner ref to HelmRepository on HelmChart
This commit is contained in:
commit
9696bf7f29
|
|
@ -38,6 +38,14 @@ rules:
|
|||
- patch
|
||||
- update
|
||||
- watch
|
||||
- apiGroups:
|
||||
- source.fluxcd.io
|
||||
resources:
|
||||
- helmcharts/finalizers
|
||||
verbs:
|
||||
- get
|
||||
- patch
|
||||
- update
|
||||
- apiGroups:
|
||||
- source.fluxcd.io
|
||||
resources:
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue