Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Fix issue #374 with determining the cassandra version from image #375

Merged
merged 4 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/controller/cassandracluster/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ func initContainerEnvVar(cc *api.CassandraCluster, status *api.CassandraClusterS
image := strings.Split(cc.Spec.CassandraImage, ":")
serverVersion := cc.Spec.ServerVersion
if serverVersion == "" {
if len(image) == 2 {
version := strings.Split(image[1], "-")
if len(image) >= 2 {
version := strings.Split(image[len(image)-1], "-")
serverVersion = version[0]
if len(version) != 1 {
serverVersion += ".0"
Expand Down
31 changes: 31 additions & 0 deletions pkg/controller/cassandracluster/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func helperInitCluster(t *testing.T, name string) (*ReconcileCassandraCluster, *
return &rcc, &cc
}

func GetEnvVarByName(envVars []v1.EnvVar, name string) *v1.EnvVar {
for _, envVar := range envVars {
if envVar.Name == name {
return &envVar
}
}
return nil
}

func TestCreateNodeAffinity(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -330,6 +339,28 @@ func TestInitContainerConfigFileData(t *testing.T) {
assert.Equal(configFileData.String(), initEnvVar[0].Value)
}

func TestInitContainerServerVersionDetect(t *testing.T) {
// Check of Cassandra version detection in case of different image formats
dcName := "dc1"
rackName := "rack1"
dcRackName := fmt.Sprintf("%s-%s", dcName, rackName)

_, cc := helperInitCluster(t, "cassandracluster-1DC.yaml")
imageTag := "1.0.0"
images := []string{
fmt.Sprintf("artifactory-name/repo/cassandra:%s", imageTag),
fmt.Sprintf("artifactory-name:44301/repo/cassandra:%s", imageTag),
}
assert := assert.New(t)
for _, image := range images {
cc.Spec.CassandraImage = image
cassieResources := cc.Spec.Resources
initEnvVar := initContainerEnvVar(cc, &cc.Status, cassieResources, dcRackName)
prodVer := GetEnvVarByName(initEnvVar, "PRODUCT_VERSION")
assert.Equal(imageTag, prodVer.Value)
}
}
ibumarskov marked this conversation as resolved.
Show resolved Hide resolved

func TestGenerateCassandraStatefulSet(t *testing.T) {
assert := assert.New(t)
dcName := "dc1"
Expand Down