Skip to content

Commit

Permalink
Upgrade C* 4.0 in e2e tests to 4.0.13 (fixes #1342) (#1343)
Browse files Browse the repository at this point in the history
* Upgrade C* 4.0 in e2e tests to 4.0.13 (fixes #1342)

* Fix operator upgrade test

* Always allow cass-operator autoupdates

---------

Co-authored-by: Alexander Dejanovski <[email protected]>
  • Loading branch information
olim7t and adejanovski authored Jun 6, 2024
1 parent e494dac commit c9d12b2
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 105 deletions.
1 change: 1 addition & 0 deletions controllers/medusa/medusarestorejob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func updateMedusaRestoreInitContainer(req *medusa.RestoreRequest) error {
if err := setRestoreMappingInRestoreContainer(req.RestoreJob.Status.RestoreMapping, req.Datacenter); err != nil {
return err
}

return setRestoreKeyInRestoreContainer(req.RestoreJob.Status.RestoreKey, req.Datacenter)
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/cassandra/datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig)

dc := &cassdcapi.CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: template.Meta.Name,
Annotations: map[string]string{},
Namespace: namespace,
Name: template.Meta.Name,
Annotations: map[string]string{
cassdcapi.UpdateAllowedAnnotation: string(cassdcapi.AllowUpdateAlways),
},
Labels: utils.MergeMap(map[string]string{
api.NameLabel: api.NameLabelValue,
api.PartOfLabel: api.PartOfLabelValue,
Expand Down
74 changes: 3 additions & 71 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func beforeTest(t *testing.T, f *framework.E2eFramework, opts *e2eTestOpts) erro
return nil
}

func upgradeToLatest(t *testing.T, ctx context.Context, f *framework.E2eFramework, namespace string) error {
func upgradeToLatest(t *testing.T, ctx context.Context, f *framework.E2eFramework, namespace, dcPrefix string) error {
deploymentConfig := framework.OperatorDeploymentConfig{
Namespace: namespace,
ClusterScoped: false,
Expand Down Expand Up @@ -716,7 +716,7 @@ func applyPollingDefaults() {
polling.medusaBackupDone.timeout = 10 * time.Minute
polling.medusaBackupDone.interval = 15 * time.Second

polling.medusaRestoreDone.timeout = 10 * time.Minute
polling.medusaRestoreDone.timeout = 15 * time.Minute
polling.medusaRestoreDone.interval = 15 * time.Second

polling.datacenterUpdating.timeout = 1 * time.Minute
Expand Down Expand Up @@ -955,51 +955,9 @@ func createSingleDatacenterClusterWithUpgrade(t *testing.T, ctx context.Context,
assertCassandraDatacenterK8cStatusReady(ctx, t, f, kcKey, dcKey.Name)
dcPrefix := DcPrefix(t, f, dcKey)

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)

// Save the Stargate deployment resource hash to verify if it was modified by the upgrade.
// It'll allow to wait for the pod to be successfully upgraded before performing the Stargate API tests.
stargateDeploymentKey := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: namespace, Name: dcPrefix + "-default-stargate-deployment"}}
initialStargateResourceHash := GetStargateResourceHash(t, f, ctx, stargateDeploymentKey)
initialStargatePodNames := GetStargatePodNames(t, f, ctx, stargateDeploymentKey)
require.Len(initialStargatePodNames, 1, "expected 1 Stargate pod in namespace %s", namespace)

t.Log("retrieve database credentials")
username, password, err := f.RetrieveDatabaseCredentials(ctx, f.DataPlaneContexts[0], namespace, k8ssandra.SanitizedName())
require.NoError(err, "failed to retrieve database credentials")

t.Log("deploying Stargate ingress routes in context", f.DataPlaneContexts[0])
stargateRestHostAndPort := ingressConfigs[f.DataPlaneContexts[0]].StargateRest
stargateGrpcHostAndPort := ingressConfigs[f.DataPlaneContexts[0]].StargateGrpc
stargateCqlHostAndPort := ingressConfigs[f.DataPlaneContexts[0]].StargateCql
f.DeployStargateIngresses(t, f.DataPlaneContexts[0], namespace, dcPrefix+"-stargate-service", stargateRestHostAndPort, stargateGrpcHostAndPort)
defer f.UndeployAllIngresses(t, f.DataPlaneContexts[0], namespace)

// Perform the upgrade
err = upgradeToLatest(t, ctx, f, namespace)
err = upgradeToLatest(t, ctx, f, namespace, dcPrefix)
require.NoError(err, "failed to upgrade to latest version")

// Wait for the Stargate deployment resource hash to change.
// It'll allow to wait for the pod to be successfully upgraded before performing the Stargate API tests.
// It's possible that this assertion will fail if the Stargate deployment resource hash is not changed.
newStargateResourceHash := waitForStargateUpgrade(t, f, ctx, stargateDeploymentKey, initialStargateResourceHash)

t.Logf("Stargate initial deployment resource hash: %s / Current hash: %s", initialStargateResourceHash, newStargateResourceHash)
if initialStargateResourceHash != newStargateResourceHash {
// Stargate deployment was modified after the upgrade, we need to wait for the new pod to be ready
t.Log("Stargate deployment updated, waiting for new pod to be ready")
require.Eventually(func() bool {
newStargatePodNames := GetStargatePodNames(t, f, ctx, stargateDeploymentKey)
return !utils.SliceContains(newStargatePodNames, initialStargatePodNames[0])
}, polling.stargateReady.timeout, polling.stargateReady.interval)
}

checkStargateApisReachable(t, ctx, f.DataPlaneContexts[0], namespace, dcPrefix, stargateRestHostAndPort, stargateGrpcHostAndPort, stargateCqlHostAndPort, username, password, false, f)

replication := map[string]int{DcName(t, f, dcKey): 1}
testStargateApis(t, f, ctx, f.DataPlaneContexts[0], namespace, dcPrefix, username, password, false, replication)
}

// createSingleDatacenterCluster creates a K8ssandraCluster with one CassandraDatacenter
Expand Down Expand Up @@ -2108,32 +2066,6 @@ func DcName(
return cassdc.DatacenterName()
}

func waitForStargateUpgrade(t *testing.T, f *framework.E2eFramework, ctx context.Context, stargateDeploymentKey framework.ClusterKey, initialStargateResourceHash string) string {
stargateChan := make(chan string)
go func() {
for {
stargateDeploymentResourceHash := GetStargateResourceHash(t, f, ctx, stargateDeploymentKey)
if stargateDeploymentResourceHash != initialStargateResourceHash {
stargateChan <- stargateDeploymentResourceHash
return
}
time.Sleep(time.Second)
}
}()

stargateUpgradeTimeout := time.After(5 * time.Minute)
for {
select {
case newStargateResourceHash := <-stargateChan:
t.Logf("Stargate deployment resource hash changed to %s", newStargateResourceHash)
return newStargateResourceHash
case <-stargateUpgradeTimeout:
t.Log("Stargate deployment resource hash did not change")
return initialStargateResourceHash
}
}
}

func checkMetricsFiltersAbsence(t *testing.T, ctx context.Context, f *framework.E2eFramework, dcKey framework.ClusterKey) error {
t.Logf("check that metric filters are absent on dc %s in cluster %s", dcKey.Name, dcKey.K8sContext)
cassdc := &cassdcapi.CassandraDatacenter{}
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/gc/4.0-jdk11-CMS/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: test
spec:
cassandra:
serverVersion: 4.0.3
serverVersion: 4.0.13
datacenters:
- metadata:
name: dc1
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/gc/4.0-jdk11-G1/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: test
spec:
cassandra:
serverVersion: 4.0.3
serverVersion: 4.0.13
datacenters:
- metadata:
name: dc1
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/gc/4.0-jdk11-ZGC/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: test
spec:
cassandra:
serverVersion: 4.0.3
serverVersion: 4.0.13
datacenters:
- metadata:
name: dc1
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/fixtures/multi-dc-medusa/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
spec:
cassandra:
clusterName: "E2E Test Cluster"
serverVersion: "4.0.0"
serverImage: k8ssandra/cass-management-api:4.0.0
serverVersion: "4.0.13"
serverImage: k8ssandra/cass-management-api:4.0.13
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/multi-dc-mixed/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
cassandra:
clusterName: "E2E Test Cluster"
serverVersion: "4.0.3"
serverVersion: "4.0.13"
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/multi-dc-reaper/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
heapSize: 256Mi
cassandra:
clusterName: "E2E Test Cluster"
serverVersion: "4.0.1"
serverVersion: "4.0.13"
datacenters:
- metadata:
name: dc1
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/remove-dc/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: test
spec:
cassandra:
serverVersion: "4.0.1"
serverVersion: "4.0.13"
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/remove-local-dc/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: test
spec:
cassandra:
serverVersion: "4.0.1"
serverVersion: "4.0.13"
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/single-dc-dse-medusa/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
secure: false
cassandra:
clusterName: "First Cluster"
serverVersion: 6.8.36
serverVersion: 6.8.43
serverType: dse
datacenters:
- metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
name: cluster1
spec:
cassandra:
serverVersion: 4.0.11
serverVersion: 4.0.13
datacenters:
- metadata:
name: cluster1-dc1
Expand All @@ -47,7 +47,7 @@ metadata:
name: cluster2
spec:
cassandra:
serverVersion: 4.0.11
serverVersion: 4.0.13
superuserSecretRef:
name: cluster2-superuser
datacenters:
Expand Down
26 changes: 9 additions & 17 deletions test/testdata/fixtures/single-dc-upgrade/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ spec:
name: dc1
k8sContext: kind-k8ssandra-0
size: 2
initContainers:
- name: "server-config-init"
resources:
requests:
memory: 256Mi
cpu: 1
limits:
memory: 512Mi
cpu: 1
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand All @@ -18,21 +27,4 @@ spec:
resources:
requests:
storage: 5Gi
stargate:
size: 1
heapSize: 384Mi
livenessProbe:
initialDelaySeconds: 100
periodSeconds: 10
failureThreshold: 20
successThreshold: 1
timeoutSeconds: 20
readinessProbe:
initialDelaySeconds: 100
periodSeconds: 10
failureThreshold: 20
successThreshold: 1
timeoutSeconds: 20
cassandraConfigMapRef:
name: cassandra-config
mgmtAPIHeap: 64Mi
2 changes: 1 addition & 1 deletion test/testdata/fixtures/single-dc/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
anAnnotationKeyDcLevel: anAnnotationValueDCLevel
k8sContext: kind-k8ssandra-0
size: 3
serverVersion: 4.0.6
serverVersion: 4.0.13
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/fixtures/stop-dc/k8ssandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: cluster1
spec:
cassandra:
serverVersion: "4.0.1"
serverVersion: "4.0.13"
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
Expand Down

0 comments on commit c9d12b2

Please sign in to comment.