Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike committed Apr 11, 2024
1 parent ed9cea6 commit 95f2d2b
Showing 1 changed file with 81 additions and 18 deletions.
99 changes: 81 additions & 18 deletions controllers/suite/clusters/humiocluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,14 @@ var _ = Describe("HumioCluster Controller", func() {
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",
},
{
Name: "HUMIO_OPTS",
Value: "-Dakka.log-config-on-start=on -Dlog4j2.formatMsgNoLookups=true -Dzookeeper.client.secure=false",
Expand All @@ -1461,16 +1469,11 @@ var _ = Describe("HumioCluster Controller", func() {
Value: "false",
},
}
toCreate.Spec.EnvironmentVariables = []corev1.EnvVar{
{
Name: "test",
Value: "",
},
}
toCreate.Spec.EnvironmentVariables = []corev1.EnvVar{}
toCreate.Spec.NodePools[0].EnvironmentVariables = []corev1.EnvVar{
{
Name: "test",
Value: "",
Value: "np",
},
}

Expand All @@ -1479,28 +1482,81 @@ var _ = Describe("HumioCluster Controller", func() {
createAndBootstrapMultiNodePoolCluster(ctx, k8sClient, humioClientForTestSuite, toCreate, true, humiov1alpha1.HumioClusterStateRunning)
defer suite.CleanupCluster(ctx, k8sClient, toCreate)

mainNodePoolManager := controllers.NewHumioNodeManagerFromHumioCluster(toCreate)
legacyHumioClusterNodePoolManager := controllers.NewHumioNodeManagerFromHumioCluster(toCreate)
nodePoolManagerForNodePool := controllers.NewHumioNodeManagerFromHumioNodePool(toCreate, &toCreate.Spec.NodePools[0])

var updatedHumioCluster humiov1alpha1.HumioCluster
clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, key.Namespace, mainNodePoolManager.GetPodLabels())
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, legacyHumioClusterNodePoolManager.GetPodLabels())
Expect(clusterPods).To(HaveLen(toCreate.Spec.NodeCount))
for _, pod := range clusterPods {
humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName)
Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(toCreate.Spec.EnvironmentVariables[0]))
Expect(pod.Spec.Containers[humioIndex].Env).To(ContainElements(append(expectedCommonVars, corev1.EnvVar{
Name: "test", Value: "common"})))
}

nodePoolClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, key.Namespace, nodePoolManagerForNodePool.GetPodLabels())
Expect(clusterPods).To(HaveLen(toCreate.Spec.NodeCount))
for _, pod := range nodePoolClusterPods {
humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName)
Expect(pod.Spec.Containers[humioIndex].Env).To(ContainElements(append(expectedCommonVars, corev1.EnvVar{
Name: "test", Value: "np"})))
}

suite.UsingClusterBy(key.Name, "Updating the environment variable on main node pool successfully")
updatedCommonEnvironmentVariables := []corev1.EnvVar{
{
Name: "test",
Value: "common-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",
},
}
updatedEnvironmentVariables := []corev1.EnvVar{
{
Name: "test",
Value: "update",
Value: "common-update",
},
}

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())
Expand All @@ -1525,7 +1581,7 @@ var _ = Describe("HumioCluster Controller", func() {
}, testTimeout, suite.TestInterval).Should(Equal(1))

suite.UsingClusterBy(key.Name, "Restarting the cluster in a rolling fashion")
ensurePodsRollingRestart(ctx, mainNodePoolManager, 2)
ensurePodsRollingRestart(ctx, legacyHumioClusterNodePoolManager, 2)

Eventually(func() string {
updatedHumioCluster = humiov1alpha1.HumioCluster{}
Expand All @@ -1534,7 +1590,7 @@ var _ = Describe("HumioCluster Controller", func() {
}, testTimeout, suite.TestInterval).Should(BeIdenticalTo(humiov1alpha1.HumioClusterStateRunning))

Eventually(func() bool {
clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels())
clusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, legacyHumioClusterNodePoolManager.GetPodLabels())
Expect(len(clusterPods)).To(BeIdenticalTo(toCreate.Spec.NodeCount))

for _, pod := range clusterPods {
Expand All @@ -1544,7 +1600,7 @@ var _ = Describe("HumioCluster Controller", func() {
return true
}, testTimeout, suite.TestInterval).Should(BeTrue())

updatedClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels())
updatedClusterPods, _ := kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, legacyHumioClusterNodePoolManager.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)))
Expand All @@ -1569,13 +1625,20 @@ var _ = Describe("HumioCluster Controller", func() {
Value: "update",
},
}
npUpdatedEnvironmentVariables := []corev1.EnvVar{
{
Name: "test",
Value: "np-update",
},
}

Eventually(func() error {
updatedHumioCluster = humiov1alpha1.HumioCluster{}
err := k8sClient.Get(ctx, key, &updatedHumioCluster)
if err != nil {
return err
}
updatedHumioCluster.Spec.NodePools[0].EnvironmentVariables = updatedEnvironmentVariables
updatedHumioCluster.Spec.NodePools[0].EnvironmentVariables = npUpdatedEnvironmentVariables
return k8sClient.Update(ctx, &updatedHumioCluster)
}, testTimeout, suite.TestInterval).Should(Succeed())

Expand Down Expand Up @@ -1613,7 +1676,7 @@ var _ = Describe("HumioCluster Controller", func() {

for _, pod := range clusterPods {
humioIndex, _ := kubernetes.GetContainerIndexByName(pod, controllers.HumioContainerName)
Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(updatedEnvironmentVariables[0]))
Expect(pod.Spec.Containers[humioIndex].Env).Should(ContainElement(npUpdatedEnvironmentVariables[0]))
}
return true
}, testTimeout, suite.TestInterval).Should(BeTrue())
Expand All @@ -1626,7 +1689,7 @@ var _ = Describe("HumioCluster Controller", func() {

suite.UsingClusterBy(key.Name, "Confirming pod revision did not change for the other main pool")

nonUpdatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, mainNodePoolManager.GetPodLabels())
nonUpdatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, legacyHumioClusterNodePoolManager.GetPodLabels())
Expect(nonUpdatedClusterPods).To(HaveLen(toCreate.Spec.NodeCount))
for _, pod := range nonUpdatedClusterPods {
Expect(pod.Annotations).To(HaveKeyWithValue(controllers.PodRevisionAnnotation, "2"))
Expand Down

0 comments on commit 95f2d2b

Please sign in to comment.