Skip to content

Commit b1ddc9b

Browse files
committed
fixes
1 parent 3f966f2 commit b1ddc9b

2 files changed

Lines changed: 53 additions & 11 deletions

File tree

tests/e2e/operator/infra/gcp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,9 @@ func createGKERegionalCluster(ctx context.Context, client *container.Service, se
742742
"--tags", strings.Join([]string{defaultNodeTag}, ","), // Join tags if there are multiple
743743
"--enable-master-authorized-networks",
744744
"--master-authorized-networks", strings.Join([]string{"0.0.0.0/0"}, ","),
745-
"--num-nodes", fmt.Sprint(defaultNodesPerZone),
745+
"--num-nodes", fmt.Sprint(defaultNodesPerZone+1), // 2 nodes/zone avoids autoscaling during TestClusterScaleUp
746746
"--min-nodes", fmt.Sprint(defaultNodesPerZone),
747-
"--max-nodes", fmt.Sprint(defaultNodesPerZone + 1), // Needed for scaling cluster
747+
"--max-nodes", fmt.Sprint(defaultNodesPerZone + 2), // headroom above initial count
748748
"--enable-autoscaling", // Enable autoscaling
749749
"--autoprovisioning-network-tags", strings.Join([]string{autoprovisioningNodeTag}, ","),
750750
"--machine-type", gcpDefaultMachineType,

tests/e2e/operator/region.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"strconv"
1011
"strings"
1112
"testing"
1213
"time"
@@ -1403,19 +1404,60 @@ func generateLocalTenantURI(cluster string) string {
14031404
return fmt.Sprintf("postgresql://root:root@localhost:26257?options=-ccluster%%3D%s", cluster)
14041405
}
14051406

1406-
// generateExternalConnectionURI creates external connection URI using cockroach convert-url
1407-
// This is used for cross-cluster connections (e.g., replication from primary to standby)
1408-
// Format: cockroach convert-url 'postgresql://USERNAME:PASSWORD@HOST' [flags]
1407+
// generateExternalConnectionURI creates an external connection URI for cross-cluster PCR connections.
1408+
// It embeds the CA certificate inline so CRDB can verify TLS when using the stored external connection.
1409+
// Version-gated:
1410+
// - CRDB >= v26.2: uses 'cockroach convert-url --ca-cert --inline' (new command)
1411+
// - CRDB < v26.2: uses 'cockroach encode-uri --certs-dir' (old command)
14091412
func generateExternalConnectionURI(t *testing.T, kubectlOpts *k8s.KubectlOptions, pod string, connString string) string {
1413+
// Determine the CRDB version running in the pod.
1414+
versionOutput, err := execInCockroachdbContainer(t, kubectlOpts, pod,
1415+
"/cockroach/cockroach", "version", "--build-tag")
1416+
require.NoError(t, err, "failed to get CRDB version from pod")
1417+
version := strings.TrimSpace(versionOutput)
1418+
t.Logf("CRDB version in pod: %s", version)
1419+
1420+
if crdbVersionAtLeast(version, 26, 2) {
1421+
// v26.2+: convert-url supports --ca-cert and --inline to embed the cert inline.
1422+
output, err := execInCockroachdbContainer(t, kubectlOpts, pod,
1423+
"/cockroach/cockroach", "convert-url",
1424+
"--url", connString,
1425+
"--ca-cert=/cockroach/cockroach-certs/ca.crt",
1426+
"--inline")
1427+
require.NoError(t, err, "failed to run cockroach convert-url")
1428+
return strings.TrimSpace(output)
1429+
}
1430+
1431+
// Pre-v26.2: use encode-uri to embed the CA cert inline in the URL.
14101432
output, err := execInCockroachdbContainer(t, kubectlOpts, pod,
1411-
"/cockroach/cockroach", "convert-url",
1412-
"--url", connString, // Format: postgresql://user:pass@host:port
1413-
"--ca-cert=/cockroach/cockroach-certs/ca.crt",
1414-
"--inline")
1415-
require.NoError(t, err)
1433+
"/cockroach/cockroach", "encode-uri",
1434+
connString,
1435+
"--certs-dir=/cockroach/cockroach-certs")
1436+
require.NoError(t, err, "failed to run cockroach encode-uri")
14161437
return strings.TrimSpace(output)
14171438
}
14181439

1440+
// crdbVersionAtLeast reports whether a CRDB version string (e.g. "v26.1.3") is >= major.minor.
1441+
func crdbVersionAtLeast(version string, major, minor int) bool {
1442+
v := strings.TrimPrefix(version, "v")
1443+
parts := strings.SplitN(v, ".", 3)
1444+
if len(parts) < 2 {
1445+
return false
1446+
}
1447+
maj, err := strconv.Atoi(parts[0])
1448+
if err != nil {
1449+
return false
1450+
}
1451+
min, err := strconv.Atoi(parts[1])
1452+
if err != nil {
1453+
return false
1454+
}
1455+
if maj != major {
1456+
return maj > major
1457+
}
1458+
return min >= minor
1459+
}
1460+
14191461
// execInCockroachdbContainer runs any command inside the cockroachdb container of a pod.
14201462
// This is the base helper used by execSQL and execSQLOnVC.
14211463
func execInCockroachdbContainer(t *testing.T, kubectlOpts *k8s.KubectlOptions, pod string, cmd ...string) (string, error) {
@@ -1608,7 +1650,7 @@ func (r *Region) ValidatePCR(t *testing.T, cfg *AdvancedValidationConfig) {
16081650
if primaryClusterDomain == "" {
16091651
primaryClusterDomain = CustomDomains[0]
16101652
}
1611-
primaryHost := fmt.Sprintf("cockroachdb-public.%s.svc.%s:26257", primaryNamespace, CustomDomains[0])
1653+
primaryHost := fmt.Sprintf("cockroachdb-public.%s.svc.%s:26257", primaryNamespace, primaryClusterDomain)
16121654
primaryConnString := fmt.Sprintf("postgresql://%s:%s@%s?options=-ccluster%%3Dsystem", pcrSourceUser, pcrSourcePassword, primaryHost)
16131655
t.Logf("Primary connection string format: postgresql://pcr_source:***@%s?options=-ccluster%%3Dsystem", primaryHost)
16141656

0 commit comments

Comments
 (0)