-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to ADDITIONAL_VARS are not applied to existing clusters. Fixes …
- Loading branch information
1 parent
588dab2
commit c502123
Showing
3 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package infinispan | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
ispnv1 "github.com/infinispan/infinispan-operator/api/v1" | ||
kube "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" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestAdditionalVarsUpdated(t *testing.T) { | ||
// The Operator must be running locall in order for changes to the ADDITIONAL_VAR env | ||
// variable to take effect | ||
if tutils.RunLocalOperator != "TRUE" { | ||
t.SkipNow() | ||
} | ||
defer testKube.CleanNamespaceAndLogOnPanic(t, tutils.Namespace) | ||
|
||
val1 := "value1" | ||
tutils.ExpectNoError(os.Setenv("ADDITIONAL_VARS", "[\"VAR1\"]")) | ||
tutils.ExpectNoError(os.Setenv("VAR1", val1)) | ||
|
||
spec := tutils.DefaultSpec(t, testKube, nil) | ||
testKube.CreateInfinispan(spec, tutils.Namespace) | ||
testKube.WaitForInfinispanCondition(spec.Name, spec.Namespace, ispnv1.ConditionWellFormed) | ||
podList := testKube.WaitForInfinispanPods(1, tutils.SinglePodTimeout, spec.Name, tutils.Namespace) | ||
|
||
assert.Equal(t, val1, getEnvVar("VAR1", &podList.Items[0].Spec)) | ||
|
||
// Update the ADDITIONAL_VARS | ||
val2 := "value2" | ||
tutils.ExpectNoError(os.Setenv("ADDITIONAL_VARS", "[\"VAR1\", \"VAR2\"]")) | ||
tutils.ExpectNoError(os.Setenv("VAR2", val2)) | ||
// Add an annotation to the Infinispan CR to trigger a new reconciliation that would not ordernarily cause a | ||
// StatefulSet rolling upgrade. This is necessary to simulate the restarting of the Operator Pod by OLM when the | ||
// ADDITIONAL_VARS env is updated in a Subscription | ||
var modifier = func(ispn *ispnv1.Infinispan) { | ||
ispn.Annotations = map[string]string{ | ||
"ignore": "me", | ||
} | ||
} | ||
var verifier = func(ispn *ispnv1.Infinispan, ss *appsv1.StatefulSet) { | ||
assert.Equal(t, val1, getEnvVar("VAR1", &ss.Spec.Template.Spec)) | ||
assert.Equal(t, val2, getEnvVar("VAR2", &ss.Spec.Template.Spec)) | ||
} | ||
verifyStatefulSetUpdate(*spec, modifier, verifier) | ||
} | ||
|
||
func getEnvVar(env string, podSpec *corev1.PodSpec) string { | ||
container := kube.GetContainer(provision.InfinispanContainer, podSpec) | ||
for _, e := range container.Env { | ||
if env == e.Name { | ||
return e.Value | ||
} | ||
} | ||
panic(fmt.Sprintf("ENV '%s' not found in container", env)) | ||
} |