Skip to content

Commit 69899e3

Browse files
committed
Make org.infinispan.LOCKS cache as AVAILABLE automatically
1 parent f291f23 commit 69899e3

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

test/e2e/upgrade/common.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,27 @@ func checkBatch(t *testing.T, infinispan *ispnv1.Infinispan) {
259259
testKube.DeleteBatch(batch)
260260
}
261261

262-
func assertNoDegradedCaches() {
262+
func locksCacheDegraded(operand version.Operand) bool {
263+
if operand.UpstreamVersion.Major > 14 {
264+
return false
265+
}
266+
podList := &corev1.PodList{}
267+
tutils.ExpectNoError(
268+
testKube.Kubernetes.ResourcesList(tutils.Namespace, map[string]string{"app": "infinispan-pod"}, podList, ctx),
269+
)
270+
271+
for _, pod := range podList.Items {
272+
log, err := testKube.Kubernetes.Logs(provision.InfinispanContainer, pod.GetName(), pod.GetNamespace(), false, ctx)
273+
tutils.ExpectNoError(err)
274+
if strings.Contains(log, "DEGRADED_MODE") {
275+
return true
276+
}
277+
}
278+
return false
279+
}
280+
281+
// healDegradedLocksCache forces the org.infinispan.LOCKS cache to AVAILABLE so that subsequent upgrades can proceed
282+
func healDegradedLocksCache(operand version.Operand, client tutils.HTTPClient) {
263283
podList := &corev1.PodList{}
264284
tutils.ExpectNoError(
265285
testKube.Kubernetes.ResourcesList(tutils.Namespace, map[string]string{"app": "infinispan-pod"}, podList, ctx),
@@ -269,7 +289,8 @@ func assertNoDegradedCaches() {
269289
log, err := testKube.Kubernetes.Logs(provision.InfinispanContainer, pod.GetName(), pod.GetNamespace(), false, ctx)
270290
tutils.ExpectNoError(err)
271291
if strings.Contains(log, "DEGRADED_MODE") {
272-
panic("Detected a cache in DEGRADED_MODE, unable to continue with test")
292+
tutils.Log().Infof("Setting org.infinispan.LOCKS cache to AVAILABLE for Operand %s", operand)
293+
tutils.NewCacheHelper("org.infinispan.LOCKS", client).Available(true)
273294
}
274295
}
275296
}

test/e2e/upgrade/upgrade_operands_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ func TestOperandUpgrades(t *testing.T) {
4141

4242
// Create the Infinispan CR
4343
replicas := 2
44+
startingOperand := versionManager.Operands[startingOperandIdx]
4445
ispn := tutils.DefaultSpec(t, testKube, func(i *ispnv1.Infinispan) {
4546
i.Spec.Replicas = int32(replicas)
4647
i.Spec.Service.Container.EphemeralStorage = false
4748
i.Spec.Logging.Categories["org.infinispan.topology"] = ispnv1.LoggingLevelTrace
48-
i.Spec.Version = versionManager.Operands[startingOperandIdx].Ref()
49+
i.Spec.Version = startingOperand.Ref()
4950
})
5051

5152
log.Infof("Testing upgrades from Operand '%s' to '%s'", ispn.Spec.Version, versionManager.Latest().Ref())
@@ -56,15 +57,17 @@ func TestOperandUpgrades(t *testing.T) {
5657
numEntries := 100
5758
client := tutils.HTTPClientForClusterWithVersionManager(ispn, testKube, versionManager)
5859

60+
if op := *startingOperand; locksCacheDegraded(op) {
61+
healDegradedLocksCache(op, client)
62+
}
63+
5964
// Add a persistent cache with data to ensure contents can be read after upgrade(s)
6065
createAndPopulatePersistentCache(persistentCacheName, numEntries, client)
6166

6267
// Add a volatile cache with data to ensure contents can be backed up and then restored after upgrade(s)
6368
createAndPopulateVolatileCache(volatileCacheName, numEntries, client)
6469

65-
assertNoDegradedCaches()
6670
backup := createBackupAndWaitToSucceed(ispn.Name, t)
67-
6871
skippedOperands := tutils.OperandSkipSet()
6972
for _, operand := range versionManager.Operands[startingOperandIdx:] {
7073
// Skip an Operand in the upgrade graph if there's a known issue
@@ -75,6 +78,10 @@ func TestOperandUpgrades(t *testing.T) {
7578
log.Debugf("Next Operand %s", operand.Ref())
7679

7780
ispn = testKube.WaitForInfinispanConditionWithTimeout(ispn.Name, tutils.Namespace, ispnv1.ConditionWellFormed, conditionTimeout)
81+
if op := *startingOperand; locksCacheDegraded(op) {
82+
healDegradedLocksCache(op, client)
83+
}
84+
7885
tutils.ExpectNoError(
7986
testKube.UpdateInfinispan(ispn, func() {
8087
ispn.Spec.Version = operand.Ref()
@@ -89,8 +96,6 @@ func TestOperandUpgrades(t *testing.T) {
8996
i.Status.Operand.Phase == ispnv1.OperandPhaseRunning
9097
})
9198
log.Info("Upgrade complete")
92-
assertOperandImage(operand.Image, ispn)
93-
assertNoDegradedCaches()
9499

95100
// Ensure that persistent cache entries have survived the upgrade(s)
96101
// Refresh the hostAddr and client as the url will change if NodePort is used.

test/e2e/upgrade/upgrade_test.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ func TestUpgrade(t *testing.T) {
4242

4343
testKube.CreateInfinispan(spec, tutils.Namespace)
4444
testKube.WaitForInfinispanPods(replicas, tutils.SinglePodTimeout, spec.Name, tutils.Namespace)
45-
testKube.WaitForInfinispanConditionWithTimeout(spec.Name, spec.Namespace, ispnv1.ConditionWellFormed, conditionTimeout)
46-
assertNoDegradedCaches()
45+
spec = testKube.WaitForInfinispanConditionWithTimeout(spec.Name, spec.Namespace, ispnv1.ConditionWellFormed, conditionTimeout)
46+
47+
versionManager := testKube.VersionManagerFromCSV(sub)
48+
operand, err := versionManager.WithRef(spec.Spec.Version)
49+
tutils.ExpectNoError(err)
4750

4851
numEntries := 100
49-
client := tutils.HTTPClientForClusterWithVersionManager(spec, testKube, testKube.VersionManagerFromCSV(sub))
52+
client := tutils.HTTPClientForClusterWithVersionManager(spec, testKube, versionManager)
53+
54+
if locksCacheDegraded(operand) {
55+
healDegradedLocksCache(operand, client)
56+
}
5057

5158
// Add a persistent cache with data to ensure contents can be read after upgrade(s)
5259
createAndPopulatePersistentCache(persistentCacheName, numEntries, client)
@@ -77,7 +84,7 @@ func TestUpgrade(t *testing.T) {
7784
// https://github.com/infinispan/infinispan-operator/issues/1719
7885
time.Sleep(time.Minute)
7986

80-
versionManager := testKube.VersionManagerFromCSV(sub)
87+
versionManager = testKube.VersionManagerFromCSV(sub)
8188
if ispnPreUpgrade.Spec.Version == "" {
8289
relatedImageJdk := testKube.InstalledCSVEnv("RELATED_IMAGE_OPENJDK", sub)
8390
if relatedImageJdk != "" {
@@ -118,6 +125,13 @@ func TestUpgrade(t *testing.T) {
118125
continue
119126
}
120127

128+
client = tutils.HTTPClientForClusterWithVersionManager(spec, testKube, versionManager)
129+
op, err := versionManager.WithRef(ispnPreUpgrade.Spec.Version)
130+
tutils.ExpectNoError(err)
131+
if locksCacheDegraded(op) {
132+
healDegradedLocksCache(op, client)
133+
}
134+
121135
tutils.ExpectNoError(
122136
testKube.UpdateInfinispan(ispn, func() {
123137
ispn.Spec.Version = latestOperand.Ref()
@@ -142,9 +156,12 @@ func TestUpgrade(t *testing.T) {
142156
// Ensure that persistent cache entries have survived the upgrade(s)
143157
// Refresh the hostAddr and client as the url will change if NodePort is used.
144158
client = tutils.HTTPClientForClusterWithVersionManager(spec, testKube, versionManager)
145-
assertNoDegradedCaches()
146159
tutils.NewCacheHelper(persistentCacheName, client).AssertSize(numEntries)
147160

161+
if locksCacheDegraded(latestOperand) {
162+
healDegradedLocksCache(latestOperand, client)
163+
}
164+
148165
// Restore the backup and ensure that the cache exists with the expected number of entries
149166
restoreName := "upgrade-restore-" + strings.ReplaceAll(strings.TrimLeft(sub.Status.CurrentCSV, olm.SubName+".v"), ".", "-")
150167
if restore, err := createRestoreAndWaitToSucceed(restoreName, backup, t); err != nil {
@@ -163,7 +180,7 @@ func TestUpgrade(t *testing.T) {
163180
checkBatch(t, spec)
164181

165182
// Kill the first pod to ensure that the cluster can recover from failover after upgrade
166-
err := testKube.Kubernetes.Client.Delete(ctx, &corev1.Pod{
183+
err = testKube.Kubernetes.Client.Delete(ctx, &corev1.Pod{
167184
ObjectMeta: metav1.ObjectMeta{
168185
Name: spec.Name + "-0",
169186
Namespace: tutils.Namespace,
@@ -174,7 +191,7 @@ func TestUpgrade(t *testing.T) {
174191
testKube.WaitForInfinispanConditionWithTimeout(spec.Name, tutils.Namespace, ispnv1.ConditionWellFormed, conditionTimeout)
175192

176193
// Ensure that persistent cache entries still contain the expected numEntries
177-
versionManager := testKube.VersionManagerFromCSV(sub)
194+
versionManager = testKube.VersionManagerFromCSV(sub)
178195
client = tutils.HTTPClientForClusterWithVersionManager(spec, testKube, versionManager)
179196
tutils.NewCacheHelper(persistentCacheName, client).AssertSize(numEntries)
180197
}

0 commit comments

Comments
 (0)