Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No reconciliation after changing podTargetLabels. Fixes #1390 #1901

Merged
merged 1 commit into from Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/infinispan/spec_update_test.go
Expand Up @@ -2,6 +2,7 @@ package infinispan

import (
"context"
"fmt"
"testing"

ispnv1 "github.com/infinispan/infinispan-operator/api/v1"
Expand Down Expand Up @@ -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)
Expand Down