Skip to content

Commit

Permalink
Workaround cass-config-builder bug #2
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Sep 18, 2024
1 parent 1a908f4 commit 1b4da6a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
80 changes: 55 additions & 25 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 @@ -556,31 +579,38 @@ func buildInitContainers(dc *api.CassandraDatacenter, rackName string, baseTempl
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
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/jvm-dependent.sh /config/"}

configContainer.VolumeMounts = combineVolumeMountSlices(configMounts, configContainer.VolumeMounts)
}
baseTemplate.Spec.InitContainers = append(baseTemplate.Spec.InitContainers, *serverCfg)
serverContainerIndex = len(baseTemplate.Spec.InitContainers) - 1
baseTemplate.Spec.InitContainers = append(baseTemplate.Spec.InitContainers, *configContainer)
}
// Workaround for cass-config-builder, copy missing files before cass-config-builder processes anything
baseTemplate.Spec.InitContainers = append([]corev1.Container{*configContainer}, baseTemplate.Spec.InitContainers...)
}
// } else if !dc.UseClientImage() && configContainerIndex < 0 && dc.ReadOnlyFs() && dc.Spec.ServerType == "dse" {
// // Workaround for cass-config-builder, copy missing files
// 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"}

// // TODO Or should we copy everything from cassandra/conf ? Same for dse/conf, since cass-config-builder does not understand immutable filesystem

// configContainer.Args = []string{"-c", "cp -rf /opt/dse/resources/cassandra/conf/jvm-dependent.sh /config/", "&&", "cp -rf /opt/dse/resources/cassandra/conf/jvm.options /config/"}

// configContainer.VolumeMounts = combineVolumeMountSlices(configMounts, configContainer.VolumeMounts)
// }
// baseTemplate.Spec.InitContainers = append(baseTemplate.Spec.InitContainers, *serverCfg)
// serverContainerIndex = len(baseTemplate.Spec.InitContainers) - 1
// baseTemplate.Spec.InitContainers = append(baseTemplate.Spec.InitContainers, *configContainer)
// }

if serverContainerIndex < 0 {
baseTemplate.Spec.InitContainers = append(baseTemplate.Spec.InitContainers, *serverCfg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciliation/construct_podtemplatespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2146,8 +2146,8 @@ func TestReadOnlyRootFilesystemVolumeChangesDSE(t *testing.T) {
assert.NoError(err, "Unexpected error encountered")

assert.Len(initContainers, 2, "Unexpected number of init containers returned")
assert.Equal(ServerConfigContainerName, initContainers[0].Name)
assert.Equal(ServerBaseConfigContainerName, initContainers[1].Name)
assert.Equal(ServerBaseConfigContainerName, initContainers[0].Name)
assert.Equal(ServerConfigContainerName, initContainers[1].Name)

assert.True(reflect.DeepEqual(initContainers[0].VolumeMounts,
[]corev1.VolumeMount{
Expand Down

0 comments on commit 1b4da6a

Please sign in to comment.