From ed9cea605ad24d3cdda8c0bc712463b827e39e94 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Thu, 11 Apr 2024 13:19:32 +0200 Subject: [PATCH] Refactor CommonEnvironmentVariables --- controllers/humiocluster_controller.go | 3 - controllers/humiocluster_defaults.go | 2 +- .../clusters/humiocluster_controller_test.go | 468 +++++++----------- 3 files changed, 190 insertions(+), 283 deletions(-) diff --git a/controllers/humiocluster_controller.go b/controllers/humiocluster_controller.go index b48cbc447..d75a0431b 100644 --- a/controllers/humiocluster_controller.go +++ b/controllers/humiocluster_controller.go @@ -100,9 +100,6 @@ func (r *HumioClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request r.Log = r.Log.WithValues("Request.UID", hc.UID) - // Prefer CommonEnvironmentVariables over top-level HumioCluster.HumioNodeSpec.EnvironmentVariables as the latter will be deprecated in the future. - hc.Spec.CommonEnvironmentVariables = mergeEnvVars(hc.Spec.EnvironmentVariables, hc.Spec.CommonEnvironmentVariables) - var humioNodePools HumioNodePoolList humioNodePools.Add(NewHumioNodeManagerFromHumioCluster(hc)) for idx := range hc.Spec.NodePools { diff --git a/controllers/humiocluster_defaults.go b/controllers/humiocluster_defaults.go index 0413ca5cc..f79d4debc 100644 --- a/controllers/humiocluster_defaults.go +++ b/controllers/humiocluster_defaults.go @@ -129,7 +129,7 @@ func NewHumioNodeManagerFromHumioCluster(hc *humiov1alpha1.HumioCluster) *HumioN ExtraVolumes: hc.Spec.ExtraVolumes, HumioServiceAccountAnnotations: hc.Spec.HumioServiceAccountAnnotations, HumioServiceLabels: hc.Spec.HumioServiceLabels, - EnvironmentVariables: mergeEnvVars(hc.Spec.EnvironmentVariables, hc.Spec.CommonEnvironmentVariables), + EnvironmentVariables: mergeEnvVars(hc.Spec.CommonEnvironmentVariables, hc.Spec.EnvironmentVariables), ImageSource: hc.Spec.ImageSource, HumioESServicePort: hc.Spec.HumioESServicePort, HumioServicePort: hc.Spec.HumioServicePort, diff --git a/controllers/suite/clusters/humiocluster_controller_test.go b/controllers/suite/clusters/humiocluster_controller_test.go index 37ac63084..4f28da865 100644 --- a/controllers/suite/clusters/humiocluster_controller_test.go +++ b/controllers/suite/clusters/humiocluster_controller_test.go @@ -1427,304 +1427,211 @@ var _ = Describe("HumioCluster Controller", func() { }) Context("Humio Cluster Update Environment Variable Multi Node Pool", func() { - It("Should correctly replace pods to use new environment variable for multi node pool clusters", - Label("envvar"), func() { - key := types.NamespacedName{ - Name: "humiocluster-update-envvar-np", - Namespace: testProcessNamespace, - } - toCreate := constructBasicMultiNodePoolHumioCluster(key, true, 1) - toCreate.Spec.NodeCount = 1 - toCreate.Spec.NodePools[0].NodeCount = 1 - toCreate.Spec.CommonEnvironmentVariables = []corev1.EnvVar{ - { - Name: "COMMON_ENV_VAR", - Value: "value", - }, - { - Name: "test", - Value: "common", - }, - } - toCreate.Spec.EnvironmentVariables = []corev1.EnvVar{ - { - Name: "test", - Value: "", - }, - { - Name: "HUMIO_OPTS", - Value: "-Dakka.log-config-on-start=on -Dlog4j2.formatMsgNoLookups=true -Dzookeeper.client.secure=false", - }, - { - Name: "ZOOKEEPER_URL", - Value: "humio-cp-zookeeper-0.humio-cp-zookeeper-headless.default:2181", - }, - { - Name: "KAFKA_SERVERS", - Value: "humio-cp-kafka-0.humio-cp-kafka-headless.default:9092", - }, - { - Name: "HUMIO_KAFKA_TOPIC_PREFIX", - Value: key.Name, - }, - { - Name: "AUTHENTICATION_METHOD", - Value: "oauth", - }, - { - Name: "ENABLE_IOC_SERVICE", - Value: "false", - }, - } - toCreate.Spec.NodePools[0].EnvironmentVariables = []corev1.EnvVar{ - { - Name: "test", - Value: "np", - }, - } - - suite.UsingClusterBy(key.Name, "Creating the cluster successfully") - ctx := context.Background() - createAndBootstrapMultiNodePoolCluster(ctx, k8sClient, humioClientForTestSuite, toCreate, true, humiov1alpha1.HumioClusterStateRunning) - defer suite.CleanupCluster(ctx, k8sClient, toCreate) + It("Should correctly replace pods to use new environment variable for multi node pool clusters", func() { + key := types.NamespacedName{ + Name: "humiocluster-update-envvar-np", + Namespace: testProcessNamespace, + } + toCreate := constructBasicMultiNodePoolHumioCluster(key, true, 1) + toCreate.Spec.NodeCount = 1 + toCreate.Spec.NodePools[0].NodeCount = 1 + toCreate.Spec.CommonEnvironmentVariables = []corev1.EnvVar{ + { + Name: "HUMIO_OPTS", + Value: "-Dakka.log-config-on-start=on -Dlog4j2.formatMsgNoLookups=true -Dzookeeper.client.secure=false", + }, + { + Name: "ZOOKEEPER_URL", + Value: "humio-cp-zookeeper-0.humio-cp-zookeeper-headless.default:2181", + }, + { + Name: "KAFKA_SERVERS", + Value: "humio-cp-kafka-0.humio-cp-kafka-headless.default:9092", + }, + { + Name: "HUMIO_KAFKA_TOPIC_PREFIX", + Value: key.Name, + }, + { + Name: "AUTHENTICATION_METHOD", + Value: "oauth", + }, + { + Name: "ENABLE_IOC_SERVICE", + Value: "false", + }, + } + toCreate.Spec.EnvironmentVariables = []corev1.EnvVar{ + { + Name: "test", + Value: "", + }, + } + toCreate.Spec.NodePools[0].EnvironmentVariables = []corev1.EnvVar{ + { + Name: "test", + Value: "", + }, + } - mainNodePoolManager := controllers.NewHumioNodeManagerFromHumioCluster(toCreate) - customNodePoolManager := controllers.NewHumioNodeManagerFromHumioNodePool(toCreate, &toCreate.Spec.NodePools[0]) + suite.UsingClusterBy(key.Name, "Creating the cluster successfully") + ctx := context.Background() + createAndBootstrapMultiNodePoolCluster(ctx, k8sClient, humioClientForTestSuite, toCreate, true, humiov1alpha1.HumioClusterStateRunning) + defer suite.CleanupCluster(ctx, k8sClient, toCreate) - expectedCommonVars := []corev1.EnvVar{ - { - Name: "COMMON_ENV_VAR", - Value: "value", - }, - { - Name: "KAFKA_SERVERS", - Value: "humio-cp-kafka-0.humio-cp-kafka-headless.default:9092", - }, - } - clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, key.Namespace, mainNodePoolManager.GetPodLabels()) - Expect(clusterPods).To(HaveLen(toCreate.Spec.NodeCount)) - for _, pod := range clusterPods { - humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) - Expect(pod.Spec.Containers[humioIndex].Env).To(ContainElements(append(expectedCommonVars, corev1.EnvVar{ - Name: "test", Value: "common"}))) - } + mainNodePoolManager := controllers.NewHumioNodeManagerFromHumioCluster(toCreate) - customClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, key.Namespace, customNodePoolManager.GetPodLabels()) - Expect(clusterPods).To(HaveLen(toCreate.Spec.NodeCount)) - for _, pod := range customClusterPods { - humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) - Expect(pod.Spec.Containers[humioIndex].Env).To(ContainElements(append(expectedCommonVars, corev1.EnvVar{ - Name: "test", Value: "np"}))) - } + var updatedHumioCluster humiov1alpha1.HumioCluster + clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, key.Namespace, mainNodePoolManager.GetPodLabels()) + for _, pod := range clusterPods { + humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) + Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(toCreate.Spec.EnvironmentVariables[0])) + } - suite.UsingClusterBy(key.Name, "Updating the environment variable on main node pool successfully") - updatedCommonEnvironmentVariables := []corev1.EnvVar{ - { - Name: "COMMON_ENV_VAR", - Value: "value", - }, - } - updatedEnvironmentVariables := []corev1.EnvVar{ - { - Name: "test", - Value: "update", - }, - { - Name: "HUMIO_OPTS", - Value: "-Dakka.log-config-on-start=on -Dlog4j2.formatMsgNoLookups=true -Dzookeeper.client.secure=false", - }, - { - Name: "ZOOKEEPER_URL", - Value: "humio-cp-zookeeper-0.humio-cp-zookeeper-headless.default:2181", - }, - { - Name: "KAFKA_SERVERS", - Value: "humio-cp-kafka-0.humio-cp-kafka-headless.default:9092", - }, - { - Name: "HUMIO_KAFKA_TOPIC_PREFIX", - Value: key.Name, - }, - { - Name: "AUTHENTICATION_METHOD", - Value: "oauth", - }, - { - Name: "ENABLE_IOC_SERVICE", - Value: "false", - }, + suite.UsingClusterBy(key.Name, "Updating the environment variable on main node pool successfully") + updatedEnvironmentVariables := []corev1.EnvVar{ + { + Name: "test", + Value: "update", + }, + } + Eventually(func() error { + updatedHumioCluster = humiov1alpha1.HumioCluster{} + err := k8sClient.Get(ctx, key, &updatedHumioCluster) + if err != nil { + return err } + updatedHumioCluster.Spec.EnvironmentVariables = updatedEnvironmentVariables + return k8sClient.Update(ctx, &updatedHumioCluster) + }, testTimeout, suite.TestInterval).Should(Succeed()) - var updatedHumioCluster humiov1alpha1.HumioCluster - Eventually(func() error { - updatedHumioCluster = humiov1alpha1.HumioCluster{} - err := k8sClient.Get(ctx, key, &updatedHumioCluster) - if err != nil { - return err - } - updatedHumioCluster.Spec.CommonEnvironmentVariables = updatedCommonEnvironmentVariables - updatedHumioCluster.Spec.EnvironmentVariables = updatedEnvironmentVariables - return k8sClient.Update(ctx, &updatedHumioCluster) - }, testTimeout, suite.TestInterval).Should(Succeed()) - - Eventually(func() string { - updatedHumioCluster = humiov1alpha1.HumioCluster{} - Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) - return updatedHumioCluster.Status.State - }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRestarting)) + Eventually(func() string { + updatedHumioCluster = humiov1alpha1.HumioCluster{} + Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) + return updatedHumioCluster.Status.State + }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRestarting)) - suite.UsingClusterBy(key.Name, "Confirming only one node pool is in the correct state") - Eventually(func() int { - var poolsInCorrectState int - updatedHumioCluster = humiov1alpha1.HumioCluster{} - Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) - for _, poolStatus := range updatedHumioCluster.Status.NodePoolStatus { - if poolStatus.State == humiov1alpha1.HumioClusterStateRestarting { - poolsInCorrectState++ - } + suite.UsingClusterBy(key.Name, "Confirming only one node pool is in the correct state") + Eventually(func() int { + var poolsInCorrectState int + updatedHumioCluster = humiov1alpha1.HumioCluster{} + Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) + for _, poolStatus := range updatedHumioCluster.Status.NodePoolStatus { + if poolStatus.State == humiov1alpha1.HumioClusterStateRestarting { + poolsInCorrectState++ } - return poolsInCorrectState - }, testTimeout, suite.TestInterval).Should(Equal(1)) - - suite.UsingClusterBy(key.Name, "Restarting the cluster in a rolling fashion") - ensurePodsRollingRestart(ctx, mainNodePoolManager, 2) + } + return poolsInCorrectState + }, testTimeout, suite.TestInterval).Should(Equal(1)) - Eventually(func() string { - updatedHumioCluster = humiov1alpha1.HumioCluster{} - Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) - return updatedHumioCluster.Status.State - }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRunning)) + suite.UsingClusterBy(key.Name, "Restarting the cluster in a rolling fashion") + ensurePodsRollingRestart(ctx, mainNodePoolManager, 2) - Eventually(func() bool { - clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels()) - Expect(len(clusterPods)).To(BeIdenticalTo(toCreate.Spec.NodeCount)) + Eventually(func() string { + updatedHumioCluster = humiov1alpha1.HumioCluster{} + Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) + return updatedHumioCluster.Status.State + }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRunning)) - for _, pod := range clusterPods { - humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) - Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(updatedEnvironmentVariables[0])) - } - return true - }, testTimeout, suite.TestInterval).Should(BeTrue()) + Eventually(func() bool { + clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels()) + Expect(len(clusterPods)).To(BeIdenticalTo(toCreate.Spec.NodeCount)) - updatedClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels()) - if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" { - suite.UsingClusterBy(key.Name, "Ensuring pod names are not changed") - Expect(podNames(clusterPods)).To(Equal(podNames(updatedClusterPods))) + for _, pod := range clusterPods { + humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) + Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(updatedEnvironmentVariables[0])) } + return true + }, testTimeout, suite.TestInterval).Should(BeTrue()) - suite.UsingClusterBy(key.Name, "Confirming pod revision did not change for the other node pool") - additionalNodePoolManager := controllers.NewHumioNodeManagerFromHumioNodePool(&updatedHumioCluster, &updatedHumioCluster.Spec.NodePools[0]) + updatedClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels()) + if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" { + suite.UsingClusterBy(key.Name, "Ensuring pod names are not changed") + Expect(podNames(clusterPods)).To(Equal(podNames(updatedClusterPods))) + } - nonUpdatedClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, additionalNodePoolManager.GetPodLabels()) - Expect(nonUpdatedClusterPods).To(HaveLen(toCreate.Spec.NodePools[0].NodeCount)) - Expect(updatedHumioCluster.Spec.NodePools[0].EnvironmentVariables).To(Equal(toCreate.Spec.NodePools[0].EnvironmentVariables)) - for _, pod := range nonUpdatedClusterPods { - Expect(pod.Annotations).To(HaveKeyWithValue(controllers.PodRevisionAnnotation, "1")) - } + suite.UsingClusterBy(key.Name, "Confirming pod revision did not change for the other node pool") + additionalNodePoolManager := controllers.NewHumioNodeManagerFromHumioNodePool(&updatedHumioCluster, &updatedHumioCluster.Spec.NodePools[0]) - clusterPods, _ = kubernetes.ListPods(ctx, k8sClient, key.Namespace, additionalNodePoolManager.GetPodLabels()) + nonUpdatedClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, additionalNodePoolManager.GetPodLabels()) + Expect(nonUpdatedClusterPods).To(HaveLen(toCreate.Spec.NodePools[0].NodeCount)) + Expect(updatedHumioCluster.Spec.NodePools[0].EnvironmentVariables).To(Equal(toCreate.Spec.NodePools[0].EnvironmentVariables)) + for _, pod := range nonUpdatedClusterPods { + Expect(pod.Annotations).To(HaveKeyWithValue(controllers.PodRevisionAnnotation, "1")) + } - suite.UsingClusterBy(key.Name, "Updating the environment variable on additional node pool successfully") - updatedEnvironmentVariables = []corev1.EnvVar{ - { - Name: "test", - Value: "update", - }, - { - Name: "HUMIO_OPTS", - Value: "-Dakka.log-config-on-start=on -Dlog4j2.formatMsgNoLookups=true -Dzookeeper.client.secure=false", - }, - { - Name: "ZOOKEEPER_URL", - Value: "humio-cp-zookeeper-0.humio-cp-zookeeper-headless.default:2181", - }, - { - Name: "KAFKA_SERVERS", - Value: "humio-cp-kafka-0.humio-cp-kafka-headless.default:9092", - }, - { - Name: "HUMIO_KAFKA_TOPIC_PREFIX", - Value: key.Name, - }, - { - Name: "AUTHENTICATION_METHOD", - Value: "oauth", - }, - { - Name: "ENABLE_IOC_SERVICE", - Value: "false", - }, - } - npUpdatedEnvironmentVariables := []corev1.EnvVar{ - { - Name: "test", - Value: "np-update", - }, - } + clusterPods, _ = kubernetes.ListPods(ctx, k8sClient, key.Namespace, additionalNodePoolManager.GetPodLabels()) - Eventually(func() error { - updatedHumioCluster = humiov1alpha1.HumioCluster{} - err := k8sClient.Get(ctx, key, &updatedHumioCluster) - if err != nil { - return err - } - updatedHumioCluster.Spec.NodePools[0].EnvironmentVariables = npUpdatedEnvironmentVariables - return k8sClient.Update(ctx, &updatedHumioCluster) - }, testTimeout, suite.TestInterval).Should(Succeed()) + suite.UsingClusterBy(key.Name, "Updating the environment variable on additional node pool successfully") + updatedEnvironmentVariables = []corev1.EnvVar{ + { + Name: "test", + Value: "update", + }, + } + Eventually(func() error { + updatedHumioCluster = humiov1alpha1.HumioCluster{} + err := k8sClient.Get(ctx, key, &updatedHumioCluster) + if err != nil { + return err + } + updatedHumioCluster.Spec.NodePools[0].EnvironmentVariables = updatedEnvironmentVariables + return k8sClient.Update(ctx, &updatedHumioCluster) + }, testTimeout, suite.TestInterval).Should(Succeed()) - Eventually(func() string { - updatedHumioCluster = humiov1alpha1.HumioCluster{} - Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) - return updatedHumioCluster.Status.State - }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRestarting)) + Eventually(func() string { + updatedHumioCluster = humiov1alpha1.HumioCluster{} + Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) + return updatedHumioCluster.Status.State + }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRestarting)) - suite.UsingClusterBy(key.Name, "Confirming only one node pool is in the correct state") - Eventually(func() int { - var poolsInCorrectState int - updatedHumioCluster = humiov1alpha1.HumioCluster{} - Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) - for _, poolStatus := range updatedHumioCluster.Status.NodePoolStatus { - if poolStatus.State == humiov1alpha1.HumioClusterStateRestarting { - poolsInCorrectState++ - } + suite.UsingClusterBy(key.Name, "Confirming only one node pool is in the correct state") + Eventually(func() int { + var poolsInCorrectState int + updatedHumioCluster = humiov1alpha1.HumioCluster{} + Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) + for _, poolStatus := range updatedHumioCluster.Status.NodePoolStatus { + if poolStatus.State == humiov1alpha1.HumioClusterStateRestarting { + poolsInCorrectState++ } - return poolsInCorrectState - }, testTimeout, suite.TestInterval).Should(Equal(1)) - - suite.UsingClusterBy(key.Name, "Restarting the cluster in a rolling fashion") - ensurePodsRollingRestart(ctx, additionalNodePoolManager, 2) + } + return poolsInCorrectState + }, testTimeout, suite.TestInterval).Should(Equal(1)) - Eventually(func() string { - updatedHumioCluster = humiov1alpha1.HumioCluster{} - Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) - return updatedHumioCluster.Status.State - }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRunning)) + suite.UsingClusterBy(key.Name, "Restarting the cluster in a rolling fashion") + ensurePodsRollingRestart(ctx, additionalNodePoolManager, 2) - Eventually(func() bool { - clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, additionalNodePoolManager.GetPodLabels()) - Expect(len(clusterPods)).To(BeIdenticalTo(toCreate.Spec.NodeCount)) + Eventually(func() string { + updatedHumioCluster = humiov1alpha1.HumioCluster{} + Expect(k8sClient.Get(ctx, key, &updatedHumioCluster)).Should(Succeed()) + return updatedHumioCluster.Status.State + }, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRunning)) - for _, pod := range clusterPods { - humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) - Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElements(npUpdatedEnvironmentVariables)) - } - return true - }, testTimeout, suite.TestInterval).Should(BeTrue()) + Eventually(func() bool { + clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, additionalNodePoolManager.GetPodLabels()) + Expect(len(clusterPods)).To(BeIdenticalTo(toCreate.Spec.NodeCount)) - updatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, additionalNodePoolManager.GetPodLabels()) - if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" { - suite.UsingClusterBy(key.Name, "Ensuring pod names are not changed") - Expect(podNames(clusterPods)).To(Equal(podNames(updatedClusterPods))) + for _, pod := range clusterPods { + humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName) + Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(updatedEnvironmentVariables[0])) } + return true + }, testTimeout, suite.TestInterval).Should(BeTrue()) - suite.UsingClusterBy(key.Name, "Confirming pod revision did not change for the other main pool") + updatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, additionalNodePoolManager.GetPodLabels()) + if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" { + suite.UsingClusterBy(key.Name, "Ensuring pod names are not changed") + Expect(podNames(clusterPods)).To(Equal(podNames(updatedClusterPods))) + } - nonUpdatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels()) - Expect(nonUpdatedClusterPods).To(HaveLen(toCreate.Spec.NodeCount)) - for _, pod := range nonUpdatedClusterPods { - Expect(pod.Annotations).To(HaveKeyWithValue(controllers.PodRevisionAnnotation, "2")) - } - }) + suite.UsingClusterBy(key.Name, "Confirming pod revision did not change for the other main pool") + + nonUpdatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels()) + Expect(nonUpdatedClusterPods).To(HaveLen(toCreate.Spec.NodeCount)) + for _, pod := range nonUpdatedClusterPods { + Expect(pod.Annotations).To(HaveKeyWithValue(controllers.PodRevisionAnnotation, "2")) + } + }) }) Context("Humio Cluster Ingress", func() { @@ -2185,6 +2092,11 @@ var _ = Describe("HumioCluster Controller", func() { } toCreate := suite.ConstructBasicSingleNodeHumioCluster(key, true) toCreate.Spec.Image = oldSupportedHumioVersion + // ZOOKEEPER_URL gets filtered out by default in the call to ConstructBasicSingleNodeHumioCluster, so we add it back here + toCreate.Spec.EnvironmentVariables = append([]corev1.EnvVar{{ + Name: "ZOOKEEPER_URL", + Value: "humio-cp-zookeeper-0.humio-cp-zookeeper-headless.default:2181", + }}, toCreate.Spec.EnvironmentVariables...) suite.UsingClusterBy(key.Name, "Creating the cluster successfully without ephemeral disks") ctx := context.Background() @@ -2225,15 +2137,13 @@ var _ = Describe("HumioCluster Controller", func() { return []string{} }, testTimeout, suite.TestInterval).Should(BeEquivalentTo([]string{"-c", "export CORES=$(getconf _NPROCESSORS_ONLN) && export HUMIO_OPTS=\"$HUMIO_OPTS -XX:ActiveProcessorCount=$(getconf _NPROCESSORS_ONLN)\" && export ZONE=$(cat /shared/availability-zone) && export ZOOKEEPER_PREFIX_FOR_NODE_UUID=/humio_$(cat /shared/availability-zone)_ && exec bash /app/humio/run.sh"})) - Eventually(func() []corev1.EnvVar { - clusterPods, err := kubernetes.ListPods(ctx, k8sClient, key.Namespace, hnp.GetPodLabels()) - Expect(err).ToNot(HaveOccurred()) - if len(clusterPods) > 0 { - humioIdx, _ := kubernetes.GetContainerIndexByName(clusterPods[0], controllers.HumioContainerName) - return clusterPods[0].Spec.Containers[humioIdx].Env - } - return []corev1.EnvVar{} - }, testTimeout, suite.TestInterval).Should(ContainElement(corev1.EnvVar{Name: "ZOOKEEPER_URL_FOR_NODE_UUID", Value: "$(ZOOKEEPER_URL)"})) + clusterPods, err := kubernetes.ListPods(ctx, k8sClient, key.Namespace, hnp.GetPodLabels()) + Expect(err).ToNot(HaveOccurred()) + humioIdx, _ := kubernetes.GetContainerIndexByName(clusterPods[0], controllers.HumioContainerName) + Expect(clusterPods[0].Spec.Containers[humioIdx].Env).To(ContainElement(corev1.EnvVar{ + Name: "ZOOKEEPER_URL_FOR_NODE_UUID", + Value: "$(ZOOKEEPER_URL)", + })) }) It("Should correctly configure container arguments and ephemeral disks env var with default vhost selection method", func() { key := types.NamespacedName{