From 2d73ca4ff212bd18097e8ca5a2468be1ff971ea5 Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Tue, 14 Feb 2023 15:56:30 -0700 Subject: [PATCH] osd: ensure rook version label is not set on pod The rook-version tag must not be set on the pod spec labels since it will result in the ceph daemons being restarted every time there is a rook version update, even if the ceph version or pod spec was not otherwise updated. The rook-version tag was being added to the OSD pod spec due to a shared pointer to the labels. The code intended to only add the version label to the deployment labels, but since the pod labels shared the map variable, the pod unintentionally also had the version label added. Signed-off-by: Travis Nielsen (cherry picked from commit 1ba93b4047c14d65f77a6167175b84f5a30e353c) --- pkg/operator/ceph/cluster/osd/osd_test.go | 8 ++++++++ pkg/operator/ceph/cluster/osd/spec.go | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/operator/ceph/cluster/osd/osd_test.go b/pkg/operator/ceph/cluster/osd/osd_test.go index 2c26ad083..bcaa024cf 100644 --- a/pkg/operator/ceph/cluster/osd/osd_test.go +++ b/pkg/operator/ceph/cluster/osd/osd_test.go @@ -436,6 +436,14 @@ func TestGetOSDInfo(t *testing.T) { DataPathMap: opconfig.NewDatalessDaemonDataPathMap(c.clusterInfo.Namespace, c.spec.DataDirHostPath), } + t.Run("version labels are on deployment and not pod spec", func(t *testing.T) { + d1, _ := c.makeDeployment(osdProp, osd1, dataPathMap) + assert.NotEqual(t, "", d1.Labels["rook-version"]) + assert.Equal(t, "", d1.Spec.Template.Labels["rook-version"]) + assert.NotEqual(t, "", d1.Labels["ceph-version"]) + assert.Equal(t, "", d1.Spec.Template.Labels["ceph-version"]) + }) + t.Run("get info from PVC-based OSDs", func(t *testing.T) { d1, _ := c.makeDeployment(osdProp, osd1, dataPathMap) osdInfo1, _ := c.getOSDInfo(d1) diff --git a/pkg/operator/ceph/cluster/osd/spec.go b/pkg/operator/ceph/cluster/osd/spec.go index 45d3a44dc..95a07900b 100644 --- a/pkg/operator/ceph/cluster/osd/spec.go +++ b/pkg/operator/ceph/cluster/osd/spec.go @@ -617,11 +617,21 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC k8sutil.RemoveDuplicateEnvVars(&podTemplateSpec.Spec) + // Copy the pod labels into a new map so the deployment labels can + // diverge from the pod labels. For example, we don't want the + // rook-version label to be added to the pod labels or else it will + // cause the osd pods to be updated with every rook upgrade even if + // the osds don't need to restart. + deploymentLabels := map[string]string{} + for key, value := range podTemplateSpec.Labels { + deploymentLabels[key] = value + } + deployment := &apps.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: deploymentName, Namespace: c.clusterInfo.Namespace, - Labels: podTemplateSpec.Labels, + Labels: deploymentLabels, }, Spec: apps.DeploymentSpec{ Selector: &metav1.LabelSelector{ @@ -669,7 +679,6 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC cephv1.GetOSDLabels(c.spec.Labels).ApplyToObjectMeta(&deployment.ObjectMeta) cephv1.GetOSDLabels(c.spec.Labels).ApplyToObjectMeta(&deployment.Spec.Template.ObjectMeta) controller.AddCephVersionLabelToDeployment(c.clusterInfo.CephVersion, deployment) - controller.AddCephVersionLabelToDeployment(c.clusterInfo.CephVersion, deployment) err := c.clusterInfo.OwnerInfo.SetControllerReference(deployment) if err != nil { return nil, errors.Wrapf(err, "failed to set owner reference to osd deployment %q", deployment.Name)