@@ -1388,6 +1388,91 @@ func TestNewConfig(t *testing.T) {
13881388 },
13891389 wantPortCount : 4 ,
13901390 },
1391+ {
1392+ name : "separate migration datastore URI" ,
1393+ args : args {
1394+ cluster : v1alpha1.ClusterSpec {Config : json .RawMessage (`
1395+ {
1396+ "logLevel": "info",
1397+ "datastoreEngine": "cockroachdb"
1398+ }
1399+ ` )},
1400+ globalConfig : OperatorConfig {
1401+ ImageName : "image" ,
1402+ UpdateGraph : updates.UpdateGraph {
1403+ Channels : []updates.Channel {
1404+ {
1405+ Name : "cockroachdb" ,
1406+ Metadata : map [string ]string {"datastore" : "cockroachdb" , "default" : "true" },
1407+ Nodes : []updates.State {
1408+ {ID : "v1" , Tag : "v1" },
1409+ },
1410+ Edges : map [string ][]string {"v1" : {}},
1411+ },
1412+ },
1413+ },
1414+ },
1415+ secret : & corev1.Secret {Data : map [string ][]byte {
1416+ "datastore_uri" : []byte ("uri" ),
1417+ "migration_datastore_uri" : []byte ("migration-uri" ),
1418+ "preshared_key" : []byte ("psk" ),
1419+ }},
1420+ },
1421+ wantWarnings : []error {fmt .Errorf ("no TLS configured, consider setting \" tlsSecretName\" " )},
1422+ want : & Config {
1423+ MigrationConfig : MigrationConfig {
1424+ MigrationLogLevel : "debug" ,
1425+ DatastoreEngine : "cockroachdb" ,
1426+ DatastoreURI : "uri" ,
1427+ HasMigrationDatastoreURI : true ,
1428+ SpannerCredsSecretRef : "" ,
1429+ TargetSpiceDBImage : "image:v1" ,
1430+ EnvPrefix : "SPICEDB" ,
1431+ SpiceDBCmd : "spicedb" ,
1432+ DatastoreTLSSecretName : "" ,
1433+ TargetMigration : "head" ,
1434+ SpiceDBVersion : & v1alpha1.SpiceDBVersion {
1435+ Name : "v1" ,
1436+ Channel : "cockroachdb" ,
1437+ Attributes : []v1alpha1.SpiceDBVersionAttributes {
1438+ v1alpha1 .SpiceDBVersionAttributesMigration ,
1439+ },
1440+ },
1441+ },
1442+ SpiceConfig : SpiceConfig {
1443+ LogLevel : "info" ,
1444+ SkipMigrations : false ,
1445+ Name : "test" ,
1446+ Namespace : "test" ,
1447+ UID : "1" ,
1448+ Replicas : 2 ,
1449+ PresharedKey : "psk" ,
1450+ EnvPrefix : "SPICEDB" ,
1451+ SpiceDBCmd : "spicedb" ,
1452+ ServiceAccountName : "test" ,
1453+ DispatchEnabled : true ,
1454+ DispatchUpstreamCASecretPath : "tls.crt" ,
1455+ ProjectLabels : true ,
1456+ ProjectAnnotations : true ,
1457+ Passthrough : map [string ]string {
1458+ "datastoreEngine" : "cockroachdb" ,
1459+ "dispatchClusterEnabled" : "true" ,
1460+ "terminationLogPath" : "/dev/termination-log" ,
1461+ },
1462+ },
1463+ },
1464+ wantEnvs : []string {
1465+ "SPICEDB_POD_NAME=FIELD_REF=metadata.name" ,
1466+ "SPICEDB_LOG_LEVEL=info" ,
1467+ "SPICEDB_GRPC_PRESHARED_KEY=preshared_key" ,
1468+ "SPICEDB_DATASTORE_CONN_URI=datastore_uri" ,
1469+ "SPICEDB_DISPATCH_UPSTREAM_ADDR=kubernetes:///test.test:dispatch" ,
1470+ "SPICEDB_DATASTORE_ENGINE=cockroachdb" ,
1471+ "SPICEDB_DISPATCH_CLUSTER_ENABLED=true" ,
1472+ "SPICEDB_TERMINATION_LOG_PATH=/dev/termination-log" ,
1473+ },
1474+ wantPortCount : 4 ,
1475+ },
13911476 {
13921477 name : "disable dispatch" ,
13931478 args : args {
@@ -2341,13 +2426,32 @@ metadata:
23412426 },
23422427 wantJob : expectedJob (),
23432428 },
2429+ {
2430+ name : "uses migration datastore URI when present" ,
2431+ cluster : v1alpha1.ClusterSpec {
2432+ Config : json .RawMessage (`
2433+ {
2434+ "logLevel": "debug",
2435+ "datastoreEngine": "cockroachdb"
2436+ }
2437+ ` ),
2438+ },
2439+ wantJob : expectedJob (func (_ * applybatchv1.JobApplyConfiguration ) {
2440+ // The test below will verify the correct env var is set
2441+ }),
2442+ },
23442443 }
23452444 for _ , tt := range tests {
23462445 t .Run (tt .name , func (t * testing.T ) {
23472446 secret := & corev1.Secret {Data : map [string ][]byte {
23482447 "datastore_uri" : []byte ("uri" ),
23492448 "preshared_key" : []byte ("psk" ),
23502449 }}
2450+
2451+ // Add migration_datastore_uri for specific test
2452+ if tt .name == "uses migration datastore URI when present" {
2453+ secret .Data ["migration_datastore_uri" ] = []byte ("migration-uri" )
2454+ }
23512455 cluster := & v1alpha1.SpiceDBCluster {
23522456 ObjectMeta : metav1.ObjectMeta {
23532457 Name : "test" ,
@@ -2364,7 +2468,28 @@ metadata:
23642468 gotJob , err := json .Marshal (got .MigrationJob ("1" ))
23652469 require .NoError (t , err )
23662470
2367- require .JSONEq (t , string (wantJob ), string (gotJob ))
2471+ // For migration datastore URI test, we check the env var specifically
2472+ if tt .name == "uses migration datastore URI when present" {
2473+ // Verify the migration job uses migration_datastore_uri key
2474+ job := got .MigrationJob ("1" )
2475+ containers := job .Spec .Template .Spec .Containers
2476+ require .Len (t , containers , 1 )
2477+
2478+ var foundDatastoreURI bool
2479+ for _ , env := range containers [0 ].Env {
2480+ if env .Name != nil && * env .Name == "SPICEDB_DATASTORE_CONN_URI" {
2481+ foundDatastoreURI = true
2482+ require .NotNil (t , env .ValueFrom )
2483+ require .NotNil (t , env .ValueFrom .SecretKeyRef )
2484+ require .NotNil (t , env .ValueFrom .SecretKeyRef .Key )
2485+ require .Equal (t , "migration_datastore_uri" , * env .ValueFrom .SecretKeyRef .Key )
2486+ }
2487+ }
2488+ require .True (t , foundDatastoreURI , "SPICEDB_DATASTORE_CONN_URI env var not found" )
2489+ } else {
2490+ // For other tests, use the original JSONEq assertion
2491+ require .JSONEq (t , string (wantJob ), string (gotJob ))
2492+ }
23682493 })
23692494 }
23702495}
0 commit comments