@@ -1337,6 +1337,78 @@ func TestDeploy_BasicRedeployPipelinesCorrectNamespace(t *testing.T) {
13371337 }
13381338}
13391339
1340+ // TestDeploy_NamespaceChangePreservesExternalRegistry ensures that changing
1341+ // namespace on OpenShift does not overwrite an external registry (e.g.
1342+ // docker.io/user) with the internal OpenShift registry.
1343+ // Regression test for https://github.com/knative/func/issues/2172
1344+ func TestDeploy_NamespaceChangePreservesExternalRegistry (t * testing.T ) {
1345+ root := FromTempDirectory (t )
1346+
1347+ cleanup := k8s .SetOpenShiftForTest (true )
1348+ defer cleanup ()
1349+
1350+ // Create a function deployed to "ns1" with an external registry
1351+ f := fn.Function {
1352+ Runtime : "go" ,
1353+ Root : root ,
1354+ Registry : "docker.io/user" ,
1355+ Deploy : fn.DeploySpec {Namespace : "ns1" },
1356+ }
1357+ f , err := fn .New ().Init (f )
1358+ if err != nil {
1359+ t .Fatal (err )
1360+ }
1361+
1362+ // Deploy to a different namespace
1363+ cmd := NewDeployCmd (NewTestClient (fn .WithDeployer (mock .NewDeployer ())))
1364+ cmd .SetArgs ([]string {"--namespace=ns2" })
1365+ if err := cmd .Execute (); err != nil {
1366+ t .Fatal (err )
1367+ }
1368+
1369+ // Reload and verify the external registry was preserved
1370+ f , _ = fn .NewFunction (root )
1371+ if f .Registry != "docker.io/user" {
1372+ t .Errorf ("expected registry 'docker.io/user' to be preserved, got %q" , f .Registry )
1373+ }
1374+ }
1375+
1376+ // TestDeploy_NamespaceChangeUpdatesInternalRegistry ensures that changing
1377+ // namespace on OpenShift DOES update the registry when the function uses
1378+ // the internal OpenShift registry (the namespace is part of the registry path).
1379+ func TestDeploy_NamespaceChangeUpdatesInternalRegistry (t * testing.T ) {
1380+ root := FromTempDirectory (t )
1381+
1382+ cleanup := k8s .SetOpenShiftForTest (true )
1383+ defer cleanup ()
1384+
1385+ // Create a function deployed to "ns1" using the internal registry
1386+ f := fn.Function {
1387+ Runtime : "go" ,
1388+ Root : root ,
1389+ Registry : "image-registry.openshift-image-registry.svc:5000/ns1" ,
1390+ Deploy : fn.DeploySpec {Namespace : "ns1" },
1391+ }
1392+ f , err := fn .New ().Init (f )
1393+ if err != nil {
1394+ t .Fatal (err )
1395+ }
1396+
1397+ // Deploy to a different namespace
1398+ cmd := NewDeployCmd (NewTestClient (fn .WithDeployer (mock .NewDeployer ())))
1399+ cmd .SetArgs ([]string {"--namespace=ns2" })
1400+ if err := cmd .Execute (); err != nil {
1401+ t .Fatal (err )
1402+ }
1403+
1404+ // Reload and verify the internal registry was updated to the new namespace
1405+ f , _ = fn .NewFunction (root )
1406+ expected := "image-registry.openshift-image-registry.svc:5000/ns2"
1407+ if f .Registry != expected {
1408+ t .Errorf ("expected registry to update to %q, got %q" , expected , f .Registry )
1409+ }
1410+ }
1411+
13401412// TestDeploy_Registry ensures that a function's registry member is kept in
13411413// sync with the image tag.
13421414// During normal operation (using the client API) a function's state on disk
0 commit comments