From b847de6d2d842e22994d293eff19b794e14a5ef1 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Wed, 18 Sep 2024 18:27:48 +0300 Subject: [PATCH] Fix read_only_fs integ-test (#707) * Add workaround for cass-config-builder bug, copy all DSE conf files if using readOnlyRootFilesystem --- .../construct_podtemplatespec.go | 26 +++++++++++++++++++ .../construct_podtemplatespec_test.go | 13 ++++++++-- .../smoke_test_read_only_fs_test.go | 7 +++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pkg/reconciliation/construct_podtemplatespec.go b/pkg/reconciliation/construct_podtemplatespec.go index a581d5db..17934205 100644 --- a/pkg/reconciliation/construct_podtemplatespec.go +++ b/pkg/reconciliation/construct_podtemplatespec.go @@ -512,6 +512,29 @@ func buildInitContainers(dc *api.CassandraDatacenter, rackName string, baseTempl } configContainer.VolumeMounts = []corev1.VolumeMount{configBaseMount} + } else if !dc.UseClientImage() && dc.ReadOnlyFs() && dc.Spec.ServerType == "dse" { + // Similar to k8ssandra 1.x, use config-container if we use k8ssandra-client to build configs + if configContainerIndex < 0 { + configContainer = &corev1.Container{ + Name: ServerBaseConfigContainerName, + } + } + + if configContainer.Image == "" { + serverImage, err := makeImage(dc) + if err != nil { + return err + } + + configContainer.Image = serverImage + if images.GetImageConfig() != nil && images.GetImageConfig().ImagePullPolicy != "" { + configContainer.ImagePullPolicy = images.GetImageConfig().ImagePullPolicy + } + + configContainer.Command = []string{"/bin/sh"} + configContainer.Args = []string{"-c", "cp -rf /opt/dse/resources/cassandra/conf/* /config/"} + } + configContainer.VolumeMounts = combineVolumeMountSlices(configMounts, configContainer.VolumeMounts) } serverCfg.VolumeMounts = combineVolumeMountSlices(configMounts, serverCfg.VolumeMounts) @@ -555,6 +578,9 @@ func buildInitContainers(dc *api.CassandraDatacenter, rackName string, baseTempl } else { baseTemplate.Spec.InitContainers = append(baseTemplate.Spec.InitContainers, *configContainer) } + } else if !dc.UseClientImage() && configContainerIndex < 0 && dc.ReadOnlyFs() && dc.Spec.ServerType == "dse" { + // Workaround for cass-config-builder, copy missing files before cass-config-builder processes anything + baseTemplate.Spec.InitContainers = append([]corev1.Container{*configContainer}, baseTemplate.Spec.InitContainers...) } if serverContainerIndex < 0 { diff --git a/pkg/reconciliation/construct_podtemplatespec_test.go b/pkg/reconciliation/construct_podtemplatespec_test.go index 7335d675..293a26c5 100644 --- a/pkg/reconciliation/construct_podtemplatespec_test.go +++ b/pkg/reconciliation/construct_podtemplatespec_test.go @@ -2145,8 +2145,9 @@ func TestReadOnlyRootFilesystemVolumeChangesDSE(t *testing.T) { assert.NotNil(initContainers, "No init containers were found") assert.NoError(err, "Unexpected error encountered") - assert.Len(initContainers, 1, "Unexpected number of init containers returned") - assert.Equal(ServerConfigContainerName, initContainers[0].Name) + assert.Len(initContainers, 2, "Unexpected number of init containers returned") + assert.Equal(ServerBaseConfigContainerName, initContainers[0].Name) + assert.Equal(ServerConfigContainerName, initContainers[1].Name) assert.True(reflect.DeepEqual(initContainers[0].VolumeMounts, []corev1.VolumeMount{ @@ -2156,6 +2157,14 @@ func TestReadOnlyRootFilesystemVolumeChangesDSE(t *testing.T) { }, }), fmt.Sprintf("Unexpected volume mounts for the base config container: %v", initContainers[0].VolumeMounts)) + assert.True(reflect.DeepEqual(initContainers[1].VolumeMounts, + []corev1.VolumeMount{ + { + Name: "server-config", + MountPath: "/config", + }, + }), fmt.Sprintf("Unexpected volume mounts for the base config container: %v", initContainers[0].VolumeMounts)) + containers := podTemplateSpec.Spec.Containers assert.NotNil(containers, "No containers were found") assert.NoError(err, "Unexpected error encountered") diff --git a/tests/smoke_test_read_only_fs/smoke_test_read_only_fs_test.go b/tests/smoke_test_read_only_fs/smoke_test_read_only_fs_test.go index c1fa3de8..65482264 100644 --- a/tests/smoke_test_read_only_fs/smoke_test_read_only_fs_test.go +++ b/tests/smoke_test_read_only_fs/smoke_test_read_only_fs_test.go @@ -60,10 +60,13 @@ var _ = Describe(testName, func() { ns.WaitForOutputAndLog(step, k, "true", 360) step = "creating a datacenter resource with 1 rack/1 node" - k = kubectl.ApplyFiles(dcYaml) + + testFile, err := ginkgo_util.CreateTestFile(dcYaml) + Expect(err).ToNot(HaveOccurred()) + k = kubectl.ApplyFiles(testFile) ns.ExecAndLog(step, k) - ns.WaitForDatacenterReady(dcName) + ns.WaitForDatacenterReadyWithTimeouts(dcName, 360, 360) ns.ExpectDoneReconciling(dcName) step = "deleting the dc"