From cfbdb0bf8b07002f6ccb506d235e12c18f631b89 Mon Sep 17 00:00:00 2001 From: Ryan Emerson Date: Tue, 7 Nov 2023 10:10:41 +0000 Subject: [PATCH] No reconciliation after changing podTargetLabels. Fixes #1390 --- .../handler/manage/statefulset_updates.go | 7 ++++++ .../handler/provision/statefulsets.go | 9 +++++-- test/e2e/infinispan/spec_update_test.go | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/pkg/reconcile/pipeline/infinispan/handler/manage/statefulset_updates.go b/pkg/reconcile/pipeline/infinispan/handler/manage/statefulset_updates.go index 8a683aae0..a45f137d7 100644 --- a/pkg/reconcile/pipeline/infinispan/handler/manage/statefulset_updates.go +++ b/pkg/reconcile/pipeline/infinispan/handler/manage/statefulset_updates.go @@ -47,6 +47,13 @@ func StatefulSetRollingUpgrade(i *ispnv1.Infinispan, ctx pipeline.Context) { rollingUpgrade = false } + // Changes to podLabels + currentLabels := provision.StatefulSetPodLabels(i.GetStatefulSetName(), i) + previousLabels := statefulSet.Spec.Template.ObjectMeta.Labels + if !reflect.DeepEqual(currentLabels, previousLabels) { + updateNeeded = true + } + // Changes to statefulset.spec.template.spec.containers[].resources spec := &statefulSet.Spec.Template.Spec container := kube.GetContainer(provision.InfinispanContainer, spec) diff --git a/pkg/reconcile/pipeline/infinispan/handler/provision/statefulsets.go b/pkg/reconcile/pipeline/infinispan/handler/provision/statefulsets.go index 244f536a7..ed7e30fb6 100644 --- a/pkg/reconcile/pipeline/infinispan/handler/provision/statefulsets.go +++ b/pkg/reconcile/pipeline/infinispan/handler/provision/statefulsets.go @@ -65,10 +65,9 @@ func ClusterStatefulSet(i *ispnv1.Infinispan, ctx pipeline.Context) { } func ClusterStatefulSetSpec(statefulSetName string, i *ispnv1.Infinispan, ctx pipeline.Context) (*appsv1.StatefulSet, error) { - labelsForPod := i.PodLabels() + labelsForPod := StatefulSetPodLabels(statefulSetName, i) labelsForSelector := i.PodSelectorLabels() labelsForSelector[consts.StatefulSetPodLabel] = statefulSetName - labelsForPod[consts.StatefulSetPodLabel] = statefulSetName configFiles := ctx.ConfigFiles() statefulSetAnnotations := consts.DeploymentAnnotations @@ -166,6 +165,12 @@ func ClusterStatefulSetSpec(statefulSetName string, i *ispnv1.Infinispan, ctx pi return statefulSet, nil } +func StatefulSetPodLabels(statefulSetName string, i *ispnv1.Infinispan) map[string]string { + labelsForPod := i.PodLabels() + labelsForPod[consts.StatefulSetPodLabel] = statefulSetName + return labelsForPod +} + func addUserIdentities(ctx pipeline.Context, i *ispnv1.Infinispan, statefulset *appsv1.StatefulSet) { // Only append IDENTITIES_HASH and secret volume if authentication is enabled spec := &statefulset.Spec.Template.Spec diff --git a/test/e2e/infinispan/spec_update_test.go b/test/e2e/infinispan/spec_update_test.go index a33377efb..7c5f9bd67 100644 --- a/test/e2e/infinispan/spec_update_test.go +++ b/test/e2e/infinispan/spec_update_test.go @@ -2,6 +2,7 @@ package infinispan import ( "context" + "fmt" "testing" ispnv1 "github.com/infinispan/infinispan-operator/api/v1" @@ -102,6 +103,29 @@ func TestInfinispanMigrateFromCacheToDatagrid(t *testing.T) { genericTestForContainerUpdated(*spec, modifier, verifier) } +func TestUpdatePodTargetLabels(t *testing.T) { + t.Parallel() + defer testKube.CleanNamespaceAndLogOnPanic(t, tutils.Namespace) + + podLabel := "pod-label-1" + var modifier = func(ispn *ispnv1.Infinispan) { + ispn.ObjectMeta.Annotations = map[string]string{ + ispnv1.PodTargetLabels: podLabel, + } + ispn.ObjectMeta.Labels = map[string]string{ + podLabel: "value", + } + } + var verifier = func(ispn *ispnv1.Infinispan, ss *appsv1.StatefulSet) { + labels := ss.Spec.Template.ObjectMeta.Labels + if _, exists := labels[podLabel]; !exists { + panic(fmt.Sprintf("'%s' label not found in StatefulSet spec", podLabel)) + } + } + spec := tutils.DefaultSpec(t, testKube, nil) + genericTestForContainerUpdated(*spec, modifier, verifier) +} + func genericTestForContainerUpdated(ispn ispnv1.Infinispan, modifier func(*ispnv1.Infinispan), verifier func(*ispnv1.Infinispan, *appsv1.StatefulSet)) { testKube.CreateInfinispan(&ispn, tutils.Namespace) testKube.WaitForInfinispanPods(int(ispn.Spec.Replicas), tutils.SinglePodTimeout, ispn.Name, tutils.Namespace)