Skip to content

Commit

Permalink
Fix read_only_fs integ-test (#707)
Browse files Browse the repository at this point in the history
* Add workaround for cass-config-builder bug, copy all DSE conf files if using readOnlyRootFilesystem
  • Loading branch information
burmanm committed Sep 18, 2024
1 parent a56b7ce commit b847de6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
26 changes: 26 additions & 0 deletions pkg/reconciliation/construct_podtemplatespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions pkg/reconciliation/construct_podtemplatespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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")
Expand Down
7 changes: 5 additions & 2 deletions tests/smoke_test_read_only_fs/smoke_test_read_only_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b847de6

Please sign in to comment.