From 69f9bbdaa6415c2114ea5359a6b3ee73fa3be775 Mon Sep 17 00:00:00 2001 From: Aurel Canciu Date: Thu, 5 Nov 2020 20:26:57 +0200 Subject: [PATCH] Use SetStatusCondition vs FilterOutCondition Change to rely on the upstream k8s api/meta SetStatusCondition to set/update the resources status conditions rather than FilterOutCondition from apis/meta which is due to be removed. Signed-off-by: Aurel Canciu --- api/v1beta1/bucket_types.go | 14 +++++++++----- api/v1beta1/gitrepository_types.go | 10 +++++++--- api/v1beta1/helmchart_types.go | 10 +++++++--- api/v1beta1/helmrepository_types.go | 10 +++++++--- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/api/v1beta1/bucket_types.go b/api/v1beta1/bucket_types.go index 83c5baef..60e34883 100644 --- a/api/v1beta1/bucket_types.go +++ b/api/v1beta1/bucket_types.go @@ -120,15 +120,19 @@ func BucketProgressing(bucket Bucket) Bucket { // SetBucketCondition sets the given condition with the given status, reason and // message on the Bucket. -func SetBucketCondition(bucket *Bucket, conditionType string, status metav1.ConditionStatus, reason, message string) { - bucket.Status.Conditions = meta.FilterOutCondition(bucket.Status.Conditions, conditionType) - bucket.Status.Conditions = append(bucket.Status.Conditions, metav1.Condition{ - Type: conditionType, +func SetBucketCondition(bucket *Bucket, condition string, status metav1.ConditionStatus, reason, message string) { + conditions := &bucket.Status.Conditions + generation := bucket.GetGeneration() + newCondition := metav1.Condition{ + Type: condition, Status: status, LastTransitionTime: metav1.Now(), Reason: reason, Message: message, - }) + ObservedGeneration: generation, + } + + apimeta.SetStatusCondition(conditions, newCondition) } // BucketReady sets the given Artifact and URL on the Bucket and sets the diff --git a/api/v1beta1/gitrepository_types.go b/api/v1beta1/gitrepository_types.go index 572c5381..a6820cbb 100644 --- a/api/v1beta1/gitrepository_types.go +++ b/api/v1beta1/gitrepository_types.go @@ -143,14 +143,18 @@ func GitRepositoryProgressing(repository GitRepository) GitRepository { // SetGitRepositoryCondition sets the given condition with the given status, // reason and message on the GitRepository. func SetGitRepositoryCondition(repository *GitRepository, condition string, status metav1.ConditionStatus, reason, message string) { - repository.Status.Conditions = meta.FilterOutCondition(repository.Status.Conditions, condition) - repository.Status.Conditions = append(repository.Status.Conditions, metav1.Condition{ + conditions := &repository.Status.Conditions + generation := repository.GetGeneration() + newCondition := metav1.Condition{ Type: condition, Status: status, LastTransitionTime: metav1.Now(), Reason: reason, Message: message, - }) + ObservedGeneration: generation, + } + + apimeta.SetStatusCondition(conditions, newCondition) } // GitRepositoryReady sets the given Artifact and URL on the GitRepository and diff --git a/api/v1beta1/helmchart_types.go b/api/v1beta1/helmchart_types.go index 62962c72..924e8f7b 100644 --- a/api/v1beta1/helmchart_types.go +++ b/api/v1beta1/helmchart_types.go @@ -120,14 +120,18 @@ func HelmChartProgressing(chart HelmChart) HelmChart { // SetHelmChartCondition sets the given condition with the given status, reason // and message on the HelmChart. func SetHelmChartCondition(chart *HelmChart, condition string, status metav1.ConditionStatus, reason, message string) { - chart.Status.Conditions = meta.FilterOutCondition(chart.Status.Conditions, condition) - chart.Status.Conditions = append(chart.Status.Conditions, metav1.Condition{ + conditions := &chart.Status.Conditions + generation := chart.GetGeneration() + newCondition := metav1.Condition{ Type: condition, Status: status, LastTransitionTime: metav1.Now(), Reason: reason, Message: message, - }) + ObservedGeneration: generation, + } + + apimeta.SetStatusCondition(conditions, newCondition) } // HelmChartReady sets the given Artifact and URL on the HelmChart and sets the diff --git a/api/v1beta1/helmrepository_types.go b/api/v1beta1/helmrepository_types.go index 133871be..ed1bd5d2 100644 --- a/api/v1beta1/helmrepository_types.go +++ b/api/v1beta1/helmrepository_types.go @@ -100,14 +100,18 @@ func HelmRepositoryProgressing(repository HelmRepository) HelmRepository { // SetHelmRepositoryCondition sets the given condition with the given status, // reason and message on the HelmRepository. func SetHelmRepositoryCondition(repository *HelmRepository, condition string, status metav1.ConditionStatus, reason, message string) { - repository.Status.Conditions = meta.FilterOutCondition(repository.Status.Conditions, condition) - repository.Status.Conditions = append(repository.Status.Conditions, metav1.Condition{ + conditions := &repository.Status.Conditions + generation := repository.GetGeneration() + newCondition := metav1.Condition{ Type: condition, Status: status, LastTransitionTime: metav1.Now(), Reason: reason, Message: message, - }) + ObservedGeneration: generation, + } + + apimeta.SetStatusCondition(conditions, newCondition) } // HelmRepositoryReady sets the given Artifact and URL on the HelmRepository and