From 8071dadbf07c868fa16d803f6d90ce27e01f5810 Mon Sep 17 00:00:00 2001 From: stefanprodan <stefan.prodan@gmail.com> Date: Mon, 27 Apr 2020 11:16:10 +0300 Subject: [PATCH] status: record progressing Set ready condition to unknown while the reconciliation is progressing. This allows other operators to wait for a sync to complete. --- api/v1alpha1/condition_types.go | 4 ++++ api/v1alpha1/gitrepository_types.go | 20 ++++++++++++++++++-- api/v1alpha1/helmchart_types.go | 16 ++++++++++++++++ api/v1alpha1/helmrepository_types.go | 16 ++++++++++++++++ controllers/gitrepository_controller.go | 6 ++++++ controllers/helmchart_controller.go | 6 ++++++ controllers/helmrepository_controller.go | 6 ++++++ docs/spec/v1alpha1/common.md | 4 ++++ 8 files changed, 76 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/condition_types.go b/api/v1alpha1/condition_types.go index 71e63097f..1d88c692e 100644 --- a/api/v1alpha1/condition_types.go +++ b/api/v1alpha1/condition_types.go @@ -69,4 +69,8 @@ const ( // VerificationFailedReason represents the fact that the cryptographic provenance // verification for the source failed. VerificationFailedReason string = "VerificationFailed" + + // ProgressingReason represents the fact that a source reconciliation + // is underway. + ProgressingReason string = "Progressing" ) diff --git a/api/v1alpha1/gitrepository_types.go b/api/v1alpha1/gitrepository_types.go index 323667af0..7636df0f9 100644 --- a/api/v1alpha1/gitrepository_types.go +++ b/api/v1alpha1/gitrepository_types.go @@ -113,7 +113,7 @@ const ( ) // GitRepositoryReady sets the given artifact and url on the -// HelmRepository and resets the conditions to SourceCondition of +// GitRepository and resets the conditions to SourceCondition of // type Ready with status true and the given reason and message. // It returns the modified GitRepository. func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason, message string) GitRepository { @@ -139,7 +139,23 @@ func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason return repository } -// GitRepositoryNotReady resets the conditions of the HelmRepository +// GitRepositoryProgressing resets the conditions of the GitRepository +// to SourceCondition of type Ready with status unknown and +// progressing reason and message. It returns the modified GitRepository. +func GitRepositoryProgressing(repository GitRepository) GitRepository { + repository.Status.Conditions = []SourceCondition{ + { + Type: ReadyCondition, + Status: corev1.ConditionUnknown, + LastTransitionTime: metav1.Now(), + Reason: ProgressingReason, + Message: "reconciliation in progress", + }, + } + return repository +} + +// GitRepositoryNotReady resets the conditions of the GitRepository // to SourceCondition of type Ready with status false and the given // reason and message. It returns the modified GitRepository. func GitRepositoryNotReady(repository GitRepository, reason, message string) GitRepository { diff --git a/api/v1alpha1/helmchart_types.go b/api/v1alpha1/helmchart_types.go index 0f3bef064..521793d0c 100644 --- a/api/v1alpha1/helmchart_types.go +++ b/api/v1alpha1/helmchart_types.go @@ -93,6 +93,22 @@ func HelmChartReady(chart HelmChart, artifact Artifact, url, reason, message str return chart } +// HelmChartProgressing resets the conditions of the HelmChart +// to SourceCondition of type Ready with status unknown and +// progressing reason and message. It returns the modified HelmChart. +func HelmChartProgressing(chart HelmChart) HelmChart { + chart.Status.Conditions = []SourceCondition{ + { + Type: ReadyCondition, + Status: corev1.ConditionUnknown, + LastTransitionTime: metav1.Now(), + Reason: ProgressingReason, + Message: "reconciliation in progress", + }, + } + return chart +} + // HelmChartNotReady resets the conditions of the HelmChart to // SourceCondition of type Ready with status false and the given // reason and message. It returns the modified HelmChart. diff --git a/api/v1alpha1/helmrepository_types.go b/api/v1alpha1/helmrepository_types.go index 17c9985c5..1b24fb95a 100644 --- a/api/v1alpha1/helmrepository_types.go +++ b/api/v1alpha1/helmrepository_types.go @@ -92,6 +92,22 @@ func HelmRepositoryReady(repository HelmRepository, artifact Artifact, url, reas return repository } +// HelmRepositoryProgressing resets the conditions of the HelmRepository +// to SourceCondition of type Ready with status unknown and +// progressing reason and message. It returns the modified HelmRepository. +func HelmRepositoryProgressing(repository HelmRepository) HelmRepository { + repository.Status.Conditions = []SourceCondition{ + { + Type: ReadyCondition, + Status: corev1.ConditionUnknown, + LastTransitionTime: metav1.Now(), + Reason: ProgressingReason, + Message: "reconciliation in progress", + }, + } + return repository +} + // HelmRepositoryNotReady resets the conditions of the HelmRepository // to SourceCondition of type Ready with status false and the given // reason and message. It returns the modified HelmRepository. diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 714cbae9e..5e69bf176 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -68,6 +68,12 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro log.Error(err, "unable to update GitRepository status") return ctrl.Result{Requeue: true}, err } + } else { + repo = sourcev1.GitRepositoryProgressing(repo) + if err := r.Status().Update(ctx, &repo); err != nil { + log.Error(err, "unable to update GitRepository status") + return ctrl.Result{Requeue: true}, err + } } // try to remove old artifacts diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 7f7552273..2bdcb3748 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -68,6 +68,12 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { log.Error(err, "unable to update HelmChart status") return ctrl.Result{Requeue: true}, err } + } else { + chart = sourcev1.HelmChartProgressing(chart) + if err := r.Status().Update(ctx, &chart); err != nil { + log.Error(err, "unable to update HelmChart status") + return ctrl.Result{Requeue: true}, err + } } // try to remove old artifacts diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index d54e081e1..80fba9fc3 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -70,6 +70,12 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err log.Error(err, "unable to update HelmRepository status") return ctrl.Result{Requeue: true}, err } + } else { + repository = sourcev1.HelmRepositoryProgressing(repository) + if err := r.Status().Update(ctx, &repository); err != nil { + log.Error(err, "unable to update HelmRepository status") + return ctrl.Result{Requeue: true}, err + } } // try to remove old artifacts diff --git a/docs/spec/v1alpha1/common.md b/docs/spec/v1alpha1/common.md index 7119a329d..26e5e10a9 100644 --- a/docs/spec/v1alpha1/common.md +++ b/docs/spec/v1alpha1/common.md @@ -138,6 +138,10 @@ const ( // VerificationFailedReason represents the fact that the cryptographic provenance // verification for the source failed. VerificationFailedReason string = "VerificationFailed" + + // ProgressingReason represents the fact that a source reconciliation + // is underway. + ProgressingReason string = "Progressing" ) ```