From ac161b6fcd7f115195eb2ca8d150f258981f8de4 Mon Sep 17 00:00:00 2001 From: yangw Date: Sat, 7 Oct 2023 16:56:56 +0800 Subject: [PATCH] [Fix] - sts will never be created (#663) * Fix err would be set nil Signed-off-by: drivebyer * nolint for shadow Signed-off-by: drivebyer --------- Signed-off-by: drivebyer Signed-off-by: Matt Robinson --- k8sutils/poddisruption.go | 2 +- k8sutils/services.go | 2 +- k8sutils/statefulset.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/k8sutils/poddisruption.go b/k8sutils/poddisruption.go index 3029afea9..f1cc97075 100644 --- a/k8sutils/poddisruption.go +++ b/k8sutils/poddisruption.go @@ -120,7 +120,7 @@ func CreateOrUpdatePodDisruptionBudget(pdbDef *policyv1.PodDisruptionBudget) err logger := pdbLogger(pdbDef.Namespace, pdbDef.Name) storedPDB, err := GetPodDisruptionBudget(pdbDef.Namespace, pdbDef.Name) if err != nil { - if err = patch.DefaultAnnotator.SetLastAppliedAnnotation(pdbDef); err != nil { + if err := patch.DefaultAnnotator.SetLastAppliedAnnotation(pdbDef); err != nil { //nolint logger.Error(err, "Unable to patch redis PodDisruptionBudget with comparison object") return err } diff --git a/k8sutils/services.go b/k8sutils/services.go index 9db0f340b..3d6548b5b 100644 --- a/k8sutils/services.go +++ b/k8sutils/services.go @@ -137,7 +137,7 @@ func CreateOrUpdateService(namespace string, serviceMeta metav1.ObjectMeta, owne storedService, err := getService(namespace, serviceMeta.Name) if err != nil { if errors.IsNotFound(err) { - if err = patch.DefaultAnnotator.SetLastAppliedAnnotation(serviceDef); err != nil { + if err := patch.DefaultAnnotator.SetLastAppliedAnnotation(serviceDef); err != nil { //nolint logger.Error(err, "Unable to patch redis service with compare annotations") } return createService(namespace, serviceDef) diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index c6e56c37c..690e40500 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -94,7 +94,7 @@ func CreateOrUpdateStateFul(namespace string, stsMeta metav1.ObjectMeta, params storedStateful, err := GetStatefulSet(namespace, stsMeta.Name) statefulSetDef := generateStatefulSetsDef(stsMeta, params, ownerDef, initcontainerParams, containerParams, getSidecars(sidecars)) if err != nil { - if err = patch.DefaultAnnotator.SetLastAppliedAnnotation(statefulSetDef); err != nil { + if err := patch.DefaultAnnotator.SetLastAppliedAnnotation(statefulSetDef); err != nil { //nolint logger.Error(err, "Unable to patch redis statefulset with comparison object") return err } @@ -663,7 +663,7 @@ func updateStatefulSet(namespace string, stateful *appsv1.StatefulSet, recreateS } logger.V(1).Info("recreating StatefulSet because the update operation wasn't possible", "reason", strings.Join(failMsg, ", ")) propagationPolicy := metav1.DeletePropagationForeground - if err = generateK8sClient().AppsV1().StatefulSets(namespace).Delete(context.TODO(), stateful.GetName(), metav1.DeleteOptions{PropagationPolicy: &propagationPolicy}); err != nil { + if err := generateK8sClient().AppsV1().StatefulSets(namespace).Delete(context.TODO(), stateful.GetName(), metav1.DeleteOptions{PropagationPolicy: &propagationPolicy}); err != nil { //nolint return errors.Wrap(err, "failed to delete StatefulSet to avoid forbidden action") } }