Use same logger during reconcile operations
This commit is contained in:
parent
95acc78577
commit
b0f4908af0
|
@ -72,12 +72,14 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to remove old artifacts
|
// try to remove old artifacts
|
||||||
r.gc(repo)
|
if err := r.gc(repo); err != nil {
|
||||||
|
log.Error(err, "artifacts GC failed")
|
||||||
|
}
|
||||||
|
|
||||||
// try git clone
|
// try git clone
|
||||||
syncedRepo, err := r.sync(ctx, *repo.DeepCopy())
|
syncedRepo, err := r.sync(ctx, *repo.DeepCopy())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Git repository sync failed", "error", err.Error())
|
log.Error(err, "Git repository sync failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// update status
|
// update status
|
||||||
|
@ -322,10 +324,9 @@ func (r *GitRepositoryReconciler) shouldResetStatus(repository sourcev1.GitRepos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository) {
|
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository) error {
|
||||||
if repository.Status.Artifact != nil {
|
if repository.Status.Artifact != nil {
|
||||||
if err := r.Storage.RemoveAllButCurrent(*repository.Status.Artifact); err != nil {
|
return r.Storage.RemoveAllButCurrent(*repository.Status.Artifact)
|
||||||
r.Log.Info("Artifacts GC failed", "error", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,9 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to remove old artifacts
|
// try to remove old artifacts
|
||||||
r.gc(chart)
|
if err := r.gc(chart); err != nil {
|
||||||
|
log.Error(err, "artifacts GC failed")
|
||||||
|
}
|
||||||
|
|
||||||
// get referenced chart repository
|
// get referenced chart repository
|
||||||
repository, err := r.chartRepository(ctx, chart)
|
repository, err := r.chartRepository(ctx, chart)
|
||||||
|
@ -87,12 +89,14 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
|
||||||
// set ownership reference so chart is garbage collected on
|
// set ownership reference so chart is garbage collected on
|
||||||
// repository removal
|
// repository removal
|
||||||
r.setOwnerRef(ctx, &chart, repository)
|
if err := r.setOwnerRef(ctx, &chart, repository); err != nil {
|
||||||
|
log.Error(err, "failed to set owner reference")
|
||||||
|
}
|
||||||
|
|
||||||
// try to pull chart
|
// try to pull chart
|
||||||
pulledChart, err := r.sync(repository, *chart.DeepCopy())
|
pulledChart, err := r.sync(repository, *chart.DeepCopy())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Helm chart sync failed", "error", err.Error())
|
log.Error(err, "Helm chart sync failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// update status
|
// update status
|
||||||
|
@ -278,21 +282,18 @@ func (r *HelmChartReconciler) shouldResetStatus(chart sourcev1.HelmChart) (bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart) {
|
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart) error {
|
||||||
if chart.Status.Artifact != nil {
|
if chart.Status.Artifact != nil {
|
||||||
if err := r.Storage.RemoveAllButCurrent(*chart.Status.Artifact); err != nil {
|
return r.Storage.RemoveAllButCurrent(*chart.Status.Artifact)
|
||||||
r.Log.Info("Artifacts GC failed", "error", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HelmChartReconciler) setOwnerRef(ctx context.Context, chart *sourcev1.HelmChart, repository sourcev1.HelmRepository) {
|
func (r *HelmChartReconciler) setOwnerRef(ctx context.Context, chart *sourcev1.HelmChart, repository sourcev1.HelmRepository) error {
|
||||||
if metav1.IsControlledBy(chart.GetObjectMeta(), repository.GetObjectMeta()) {
|
if !metav1.IsControlledBy(chart.GetObjectMeta(), repository.GetObjectMeta()) {
|
||||||
return
|
|
||||||
}
|
|
||||||
chart.SetOwnerReferences(append(chart.GetOwnerReferences(),
|
chart.SetOwnerReferences(append(chart.GetOwnerReferences(),
|
||||||
*metav1.NewControllerRef(repository.GetObjectMeta(), repository.GroupVersionKind())))
|
*metav1.NewControllerRef(repository.GetObjectMeta(), repository.GroupVersionKind())))
|
||||||
if err := r.Update(ctx, chart); err != nil {
|
return r.Update(ctx, chart)
|
||||||
r.Log.Error(err, fmt.Sprintf("failed to set owner reference to HelmRepository '%s'", repository.Name))
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,12 +74,14 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to remove old artifacts
|
// try to remove old artifacts
|
||||||
r.gc(repository)
|
if err := r.gc(repository); err != nil {
|
||||||
|
log.Error(err, "artifacts GC failed")
|
||||||
|
}
|
||||||
|
|
||||||
// try to download index
|
// try to download index
|
||||||
syncedRepo, err := r.sync(*repository.DeepCopy())
|
syncedRepo, err := r.sync(*repository.DeepCopy())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Helm repository sync failed", "error", err.Error())
|
log.Error(err, "Helm repository sync failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// update status
|
// update status
|
||||||
|
@ -221,10 +223,9 @@ func (r *HelmRepositoryReconciler) shouldResetStatus(repository sourcev1.HelmRep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository) {
|
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository) error {
|
||||||
if repository.Status.Artifact != nil {
|
if repository.Status.Artifact != nil {
|
||||||
if err := r.Storage.RemoveAllButCurrent(*repository.Status.Artifact); err != nil {
|
return r.Storage.RemoveAllButCurrent(*repository.Status.Artifact)
|
||||||
r.Log.Info("Artifacts GC failed", "error", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue