Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix replication dcname overrides #1030

Merged
merged 11 commits into from
Aug 17, 2023
Merged

Conversation

adejanovski
Copy link
Contributor

@adejanovski adejanovski commented Jul 26, 2023

What this PR does:
There are several places in the code where we don't account for the DC name overrides, notably when placing annotations that include dc names, and when creating restore mappings.
This PR addresses these problems and adds testing to avoid regressions.
Most E2E tests are now using a DC name override (at the notable exception of the upgrade one because older versions of the CRD didn't have the DatacenterName field).
This led to a lot of changes in the tests to replace many hardcoded references to the dc names with some future proof name discovery logic.

Which issue(s) this PR fixes:
Fixes #1026

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CHANGELOG.md updated (not required for documentation PRs)
  • CLA Signed: DataStax CLA

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #1030 (4453da0) into main (b8d1502) will increase coverage by 0.04%.
The diff coverage is 62.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1030      +/-   ##
==========================================
+ Coverage   57.43%   57.48%   +0.04%     
==========================================
  Files          99      100       +1     
  Lines       10011    10045      +34     
==========================================
+ Hits         5750     5774      +24     
- Misses       3768     3779      +11     
+ Partials      493      492       -1     
Files Changed Coverage Δ
apis/k8ssandra/v1alpha1/k8ssandracluster_types.go 33.78% <0.00%> (-2.45%) ⬇️
pkg/cassandra/management.go 0.00% <0.00%> (ø)
pkg/medusa/utils.go 0.00% <0.00%> (ø)
pkg/reaper/resource.go 8.47% <0.00%> (ø)
pkg/stargate/config.go 0.00% <0.00%> (ø)
pkg/stargate/stargate.go 3.50% <33.33%> (ø)
pkg/k8ssandra/util.go 25.00% <44.44%> (ø)
controllers/k8ssandra/seeds.go 54.62% <50.00%> (ø)
pkg/reaper/vector.go 63.63% <50.00%> (ø)
pkg/stargate/vector.go 63.63% <50.00%> (ø)
... and 18 more

... and 3 files with indirect coverage changes

@adejanovski adejanovski marked this pull request as ready for review August 11, 2023 12:17
@adejanovski adejanovski requested a review from a team as a code owner August 11, 2023 12:17
@@ -59,7 +59,7 @@ jobs:
e2e_test:
- CreateMultiDatacenterCluster
- CreateMixedMultiDataCenterCluster
- AddDcToCluster
- AddDcToClusterDiffDataplane
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was renamed because we have another test with the AddDcToCluster prefix (AddDcToClusterSameDataplane), which was executed each time AddDcToCluster was invoked.
This is because subtests in Go seem to execute every test that starts with the configured value.

cassDcName := dcName
if dcNameOverride != nil && *dcNameOverride != "" {
cassDcName = *dcNameOverride
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is covered in the e2e tests, which codecov cannot detect.

@@ -24,7 +24,7 @@ const (
// DefaultResourceName generates a name for a new Reaper resource that is derived from the Cassandra cluster and DC
// names.
func DefaultResourceName(dc *cassdcapi.CassandraDatacenter) string {
return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.Name + "-reaper")
return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.DatacenterName() + "-reaper")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in the e2e tests.

Comment on lines 32 to 33
reaper1Key := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: namespace, Name: "cluster1-real-dc1-reaper"}}
reaper2Key := framework.ClusterKey{K8sContext: f.DataPlaneContexts[1], NamespacedName: types.NamespacedName{Namespace: namespace, Name: "cluster1-real-dc2-reaper"}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't use the DcPrefix() function here because the DC object doesn't exist yet.

@@ -5,7 +5,7 @@ import (
"k8s.io/utils/strings/slices"
)

func GetDatacenterForDecommission(kc *api.K8ssandraCluster) string {
func GetDatacenterForDecommission(kc *api.K8ssandraCluster) (string, *string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Could we have (string, string) as return type? I'm sure many would stumble into this issue, looking at the signature, but not realizing one is a pointer and one isn't. Especially since there's no real need for it be a pointer (it's not like we have to replace this instance of data and keep pointing to it catching changes).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing 👍

@burmanm
Copy link
Contributor

burmanm commented Aug 15, 2023

issue: The last commit is not right and shouldn't be done. We need to have tests without dc name override as default. Otherwise the entire purpose of "metadata/name" goes away and should be removed and we create uuids for all datacenters.

This PR however does not do that, but now we've removed all the normal behavior testing, thus user could be using the default settings and end up with non-working setup.

Special cases should only have their special tests, not be part of every test. Otherwise we risk the possibility that we start to depend on every possible extra setting being available (which should then be added to all e2e tests) and cases where there's less settings set things will no longer work.

@adejanovski adejanovski force-pushed the fix-replication-dcname-overrides branch from 8b6368e to 4453da0 Compare August 16, 2023 15:07
@sonarcloud
Copy link

sonarcloud bot commented Aug 16, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

No Coverage information No Coverage information
19.8% 19.8% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@adejanovski adejanovski merged commit 6099857 into main Aug 17, 2023
59 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System replication annotations aren't using the dc name overrides
2 participants