Skip to content

Commit

Permalink
spec.Image field always overwritten by Operand image for CVE releases.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson committed May 17, 2023
1 parent ae253b6 commit bef8619
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Expand Up @@ -79,7 +79,7 @@ func StatefulSetRollingUpgrade(i *ispnv1.Infinispan, ctx pipeline.Context) {

// Check if the base-image has been upgraded due to a CVE
requestedOperand := ctx.Operand()
if requestedOperand.CVE && container.Image != requestedOperand.Image {
if requestedOperand.CVE && container.Image != i.ImageName() {
ctx.Log().Info(fmt.Sprintf("CVE release '%s'. StatefulSet Rolling upgrade required", requestedOperand.Ref()))
updateNeeded = true
container.Image = requestedOperand.Image
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/infinispan/custom_image_test.go
@@ -0,0 +1,37 @@
package infinispan

import (
"context"
"testing"

ispnv1 "github.com/infinispan/infinispan-operator/api/v1"
"github.com/infinispan/infinispan-operator/pkg/kubernetes"
"github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan/handler/provision"
tutils "github.com/infinispan/infinispan-operator/test/e2e/utils"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
)

func TestCustomImage(t *testing.T) {
t.Parallel()
defer testKube.CleanNamespaceAndLogOnPanic(t, tutils.Namespace)

img := "quay.io/infinispan/server:latest"
spec := tutils.DefaultSpec(t, testKube, func(i *ispnv1.Infinispan) {
i.Spec.Image = pointer.String(img)
})

testKube.CreateInfinispan(spec, tutils.Namespace)
testKube.WaitForInfinispanPods(1, tutils.SinglePodTimeout, spec.Name, tutils.Namespace)
testKube.WaitForInfinispanCondition(spec.Name, spec.Namespace, ispnv1.ConditionWellFormed)

ss := &appsv1.StatefulSet{}
tutils.ExpectNoError(testKube.Kubernetes.Client.Get(context.TODO(), types.NamespacedName{Namespace: spec.Namespace, Name: spec.GetStatefulSetName()}, ss))
container := kubernetes.GetContainer(provision.InfinispanContainer, &ss.Spec.Template.Spec)
// Ensure that no SS rolling upgrade is executed as the default test Operand is marked as a CVE release
// https://github.com/infinispan/infinispan-operator/issues/1817
assert.Equal(t, int64(1), ss.Generation)
assert.Equal(t, img, container.Image)
}

0 comments on commit bef8619

Please sign in to comment.