From 9c44512c59599513ebf731e5a168e03f40ef8f73 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk <509198+m1kola@users.noreply.github.com> Date: Wed, 27 Aug 2025 16:36:08 +0200 Subject: [PATCH] Remove outdated code This piece of code is meant to preserve cert hash annotation in the pod template. We currently do not use cert hash annotation on the pod: we only use sts level annotations. --- controllers/operator/construct/database_construction.go | 7 ++----- pkg/statefulset/statefulset_util.go | 9 --------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/controllers/operator/construct/database_construction.go b/controllers/operator/construct/database_construction.go index d4ae74ab7..66d51dd72 100644 --- a/controllers/operator/construct/database_construction.go +++ b/controllers/operator/construct/database_construction.go @@ -466,7 +466,7 @@ func buildDatabaseStatefulSetConfigurationFunction(mdb databaseStatefulSetSource appLabelKey: opts.ServiceName, } - annotationFunc := statefulset.WithAnnotations(defaultPodAnnotations(opts.CertificateHash)) + annotationFunc := statefulset.WithAnnotations(defaultStatefulSetAnnotations(opts.CertificateHash)) podTemplateAnnotationFunc := podtemplatespec.NOOP() annotationFunc = statefulset.Apply( @@ -1057,11 +1057,8 @@ func DatabaseStartupProbe() probes.Modification { ) } -func defaultPodAnnotations(certHash string) map[string]string { +func defaultStatefulSetAnnotations(certHash string) map[string]string { return map[string]string{ - // This annotation is necessary to trigger a pod restart - // if the certificate secret is out of date. This happens if - // existing certificates have been replaced/rotated/renewed. certs.CertHashAnnotationKey: certHash, } } diff --git a/pkg/statefulset/statefulset_util.go b/pkg/statefulset/statefulset_util.go index b81343257..3158100e5 100644 --- a/pkg/statefulset/statefulset_util.go +++ b/pkg/statefulset/statefulset_util.go @@ -19,7 +19,6 @@ import ( apiEquality "k8s.io/apimachinery/pkg/api/equality" apiErrors "k8s.io/apimachinery/pkg/api/errors" - "github.com/mongodb/mongodb-kubernetes/controllers/operator/certs" "github.com/mongodb/mongodb-kubernetes/controllers/operator/inspect" "github.com/mongodb/mongodb-kubernetes/controllers/operator/workflow" kubernetesClient "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/kube/client" @@ -121,14 +120,6 @@ func CreateOrUpdateStatefulset(ctx context.Context, getUpdateCreator kubernetesC log.Debug("Created StatefulSet") return statefulSetToCreate, nil } - // preserve existing certificate hash if new one is not statefulSetToCreate - existingCertHash, okExisting := existingStatefulSet.Spec.Template.Annotations[certs.CertHashAnnotationKey] - if newCertHash, okNew := statefulSetToCreate.Spec.Template.Annotations[certs.CertHashAnnotationKey]; existingCertHash != "" && newCertHash == "" && okExisting && okNew { - if statefulSetToCreate.Spec.Template.Annotations == nil { - statefulSetToCreate.Spec.Template.Annotations = map[string]string{} - } - statefulSetToCreate.Spec.Template.Annotations[certs.CertHashAnnotationKey] = existingCertHash - } // there already exists a pvc size annotation, that means we did resize at least once // we need to make sure to keep the annotation.