Skip to content

Commit

Permalink
Support Stargate with DSE and upgrade Stargate to 1.0.77 (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
adejanovski authored Dec 5, 2023
1 parent 02d4415 commit 2039871
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-1.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen

## unreleased

* [ENHANCEMENT] [#1125](https://github.com/k8ssandra/k8ssandra-operator/issues/1125) Support Stargate with DSE and upgrade Stargate to 1.0.77
* [ENHANCEMENT] [#1122](https://github.com/k8ssandra/k8ssandra-operator/issues/1122) Expose backup size in MedusaBackup CRD
2 changes: 1 addition & 1 deletion apis/stargate/v1alpha1/stargate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type StargateTemplate struct {
// ContainerImage is the image characteristics to use for Stargate containers. Leave nil
// to use a default image.
// +optional
// +kubebuilder:default={repository:"stargateio", tag:"v1.0.67"}
// +kubebuilder:default={repository:"stargateio", tag:"v1.0.77"}
ContainerImage *images.Image `json:"containerImage,omitempty"`

// ServiceAccount is the service account name to use for Stargate pods.
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12013,7 +12013,7 @@ spec:
containerImage:
default:
repository: stargateio
tag: v1.0.67
tag: v1.0.77
description: ContainerImage is the image characteristics
to use for Stargate containers. Leave nil to use a
default image.
Expand Down Expand Up @@ -13481,7 +13481,7 @@ spec:
containerImage:
default:
repository: stargateio
tag: v1.0.67
tag: v1.0.77
description: ContainerImage is the image characteristics
to use for Stargate containers. Leave nil to
use a default image.
Expand Down Expand Up @@ -30737,7 +30737,7 @@ spec:
containerImage:
default:
repository: stargateio
tag: v1.0.67
tag: v1.0.77
description: ContainerImage is the image characteristics to use
for Stargate containers. Leave nil to use a default image.
properties:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/stargate.k8ssandra.io_stargates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ spec:
containerImage:
default:
repository: stargateio
tag: v1.0.67
tag: v1.0.77
description: ContainerImage is the image characteristics to use for
Stargate containers. Leave nil to use a default image.
properties:
Expand Down Expand Up @@ -2306,7 +2306,7 @@ spec:
containerImage:
default:
repository: stargateio
tag: v1.0.67
tag: v1.0.77
description: ContainerImage is the image characteristics to
use for Stargate containers. Leave nil to use a default image.
properties:
Expand Down
28 changes: 23 additions & 5 deletions pkg/stargate/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ const (
DefaultImageRepository = "stargateio"
DefaultImageName3 = "stargate-3_11"
DefaultImageName4 = "stargate-4_0"
DefaultVersion = "1.0.67"
DefaultImageNameDse68 = "stargate-dse-68"
DefaultVersion = "1.0.77"
// When changing the default version above, please also change the kubebuilder marker in
// apis/stargate/v1alpha1/stargate_types.go accordingly.
)

type ClusterVersion string

const (
ClusterVersion3 ClusterVersion = "3.11"
ClusterVersion4 ClusterVersion = "4.0"
ClusterVersion3 ClusterVersion = "3.11"
ClusterVersion4 ClusterVersion = "4.0"
ClusterVersion68 ClusterVersion = "6.8"
)

var (
Expand All @@ -59,6 +61,12 @@ var (
Name: DefaultImageName4,
Tag: "v" + DefaultVersion,
}
defaultImage68 = images.Image{
Registry: images.DefaultRegistry,
Repository: DefaultImageRepository,
Name: DefaultImageNameDse68,
Tag: "v" + DefaultVersion,
}
)

// NewDeployments compute the Deployments to create for the given Stargate and CassandraDatacenter
Expand Down Expand Up @@ -189,6 +197,11 @@ func NewDeployments(stargate *api.Stargate, dc *cassdcapi.CassandraDatacenter, l
},
}

if coreapi.ServerDistribution(dc.Spec.ServerType) == coreapi.ServerDistributionDse {
// Stargate requires a DSE env variable set to "1" to use the right backend.
deployment.Spec.Template.Spec.Containers[0].Env = append(deployment.Spec.Template.Spec.Containers[0].Env, corev1.EnvVar{Name: "DSE", Value: "1"})
}

klusterName, nameFound := stargate.Labels[coreapi.K8ssandraClusterNameLabel]
klusterNamespace, namespaceFound := stargate.Labels[coreapi.K8ssandraClusterNamespaceLabel]

Expand Down Expand Up @@ -219,6 +232,9 @@ func computeSeedServiceUrl(dc *cassdcapi.CassandraDatacenter) string {
}

func computeClusterVersion(dc *cassdcapi.CassandraDatacenter) ClusterVersion {
if coreapi.ServerDistribution(dc.Spec.ServerType) == coreapi.ServerDistributionDse {
return ClusterVersion68
}
cassandraVersion := dc.Spec.ServerVersion
if strings.HasPrefix(cassandraVersion, "3") {
return ClusterVersion3
Expand All @@ -228,11 +244,13 @@ func computeClusterVersion(dc *cassdcapi.CassandraDatacenter) ClusterVersion {
}

func computeImage(template *api.StargateTemplate, clusterVersion ClusterVersion) *images.Image {
if clusterVersion == ClusterVersion68 {
return template.ContainerImage.ApplyDefaults(defaultImage68)
}
if clusterVersion == ClusterVersion3 {
return template.ContainerImage.ApplyDefaults(defaultImage3)
} else {
return template.ContainerImage.ApplyDefaults(defaultImage4)
}
return template.ContainerImage.ApplyDefaults(defaultImage4)
}

func computeResourceRequirements(template *api.StargateTemplate) corev1.ResourceRequirements {
Expand Down
39 changes: 39 additions & 0 deletions pkg/stargate/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,45 @@ func testImages(t *testing.T) {
assert.Contains(t, deployment.Spec.Template.Spec.ImagePullSecrets, corev1.LocalObjectReference{Name: "my-secret"})
assert.Len(t, deployment.Spec.Template.Spec.ImagePullSecrets, 1)
})
t.Run("default image DSE 6.8", func(t *testing.T) {
stargate := stargate.DeepCopy()
stargate.Spec.ContainerImage = &images.Image{
Repository: "stargateio",
Tag: "v" + DefaultVersion,
}
dc := dc.DeepCopy()
dc.Spec.ServerVersion = "6.8.40"
dc.Spec.ServerType = "dse"
logger := testlogr.NewTestLogger(t)
deployments := NewDeployments(stargate, dc, logger)
require.Len(t, deployments, 1)
deployment := deployments["cluster1-dc1-default-stargate-deployment"]
assert.Equal(t, defaultImage68.String(), deployment.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, corev1.PullIfNotPresent, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy)
assert.Empty(t, deployment.Spec.Template.Spec.ImagePullSecrets)
assert.Equal(t, "1", utils.FindEnvVarInContainer(&deployment.Spec.Template.Spec.Containers[0], "DSE").Value)
})
t.Run("custom image DSE 6.8", func(t *testing.T) {
stargate := stargate.DeepCopy()
image := &images.Image{
Repository: "my-custom-repo",
Tag: "latest",
PullSecretRef: &corev1.LocalObjectReference{Name: "my-secret"},
}
stargate.Spec.ContainerImage = image
dc := dc.DeepCopy()
dc.Spec.ServerVersion = "6.8.40"
dc.Spec.ServerType = "dse"
logger := testlogr.NewTestLogger(t)
deployments := NewDeployments(stargate, dc, logger)
require.Len(t, deployments, 1)
deployment := deployments["cluster1-dc1-default-stargate-deployment"]
assert.Equal(t, "docker.io/my-custom-repo/stargate-dse-68:latest", deployment.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, corev1.PullAlways, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy)
assert.Contains(t, deployment.Spec.Template.Spec.ImagePullSecrets, corev1.LocalObjectReference{Name: "my-secret"})
assert.Len(t, deployment.Spec.Template.Spec.ImagePullSecrets, 1)
assert.Equal(t, "1", utils.FindEnvVarInContainer(&deployment.Spec.Template.Spec.Containers[0], "DSE").Value)
})
}

func affinityForRack(dc *cassdcapi.CassandraDatacenter, rackName string) *corev1.Affinity {
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/dse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func createSingleDseDatacenterCluster(t *testing.T, ctx context.Context, namespa
dcKey := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: namespace, Name: "dc1"}}
checkDatacenterReady(t, ctx, dcKey, f)
assertCassandraDatacenterK8cStatusReady(ctx, t, f, kcKey, dcKey.Name)
dcPrefix := DcPrefix(t, f, dcKey)

t.Log("Check that we can communicate through CQL with DSE")
_, err = f.ExecuteCql(ctx, f.DataPlaneContexts[0], namespace, kc.SanitizedName(), DcPrefix(t, f, dcKey)+"-default-sts-0",
_, err = f.ExecuteCql(ctx, f.DataPlaneContexts[0], namespace, kc.SanitizedName(), dcPrefix+"-default-sts-0",
"SELECT * FROM system.local")
require.NoError(t, err, "failed to execute CQL query against DSE")

Expand Down Expand Up @@ -67,6 +68,11 @@ func createSingleDseDatacenterCluster(t *testing.T, ctx context.Context, namespa
_, err = f.ExecuteCqlNoAuth(f.DataPlaneContexts[0], namespace, DcPrefix(t, f, dcKey)+"-default-sts-0",
"SELECT server_id FROM system.local")
require.Error(t, err, "expected CQL query without auth to fail")

stargateKey := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: namespace, Name: dcPrefix + "-stargate"}}
checkStargateReady(t, f, ctx, stargateKey)

checkStargateK8cStatusReady(t, f, ctx, kcKey, dcKey)
}

// createSingleDseSearchDatacenterCluster creates a K8ssandraCluster with one CassandraDatacenter running with search enabled
Expand Down
3 changes: 3 additions & 0 deletions test/testdata/fixtures/single-dc-dse/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ metadata:
name: test
spec:
auth: true
stargate:
size: 1
heapSize: 384Mi
cassandra:
serverVersion: 6.8.26
serverType: dse
Expand Down

0 comments on commit 2039871

Please sign in to comment.