@@ -1876,7 +1876,6 @@ func Test_objectMoverService_ensureNamespaces(t *testing.T) {
1876
1876
expectedNamespaces : []string {"namespace-1" , "namespace-2" },
1877
1877
},
1878
1878
{
1879
-
1880
1879
name : "ensureNamespaces moves namespace-2 to target which already has namespace-1" ,
1881
1880
fields : fields {
1882
1881
objs : cluster2 .Objs (),
@@ -1956,6 +1955,7 @@ func Test_createTargetObject(t *testing.T) {
1956
1955
fromProxy Proxy
1957
1956
toProxy Proxy
1958
1957
node * node
1958
+ mutators []ResourceMutatorFunc
1959
1959
}
1960
1960
1961
1961
tests := []struct {
@@ -2075,6 +2075,52 @@ func Test_createTargetObject(t *testing.T) {
2075
2075
g .Expect (c .Annotations ).To (BeEmpty ())
2076
2076
},
2077
2077
},
2078
+ {
2079
+ name : "updates object whose namespace is mutated, if it already exists and the object is not Global/GlobalHierarchy" ,
2080
+ args : args {
2081
+ fromProxy : test .NewFakeProxy ().WithObjs (
2082
+ & clusterv1.Cluster {
2083
+ ObjectMeta : metav1.ObjectMeta {
2084
+ Name : "foo" ,
2085
+ Namespace : "ns1" ,
2086
+ },
2087
+ },
2088
+ ),
2089
+ toProxy : test .NewFakeProxy ().WithObjs (
2090
+ & clusterv1.Cluster {
2091
+ ObjectMeta : metav1.ObjectMeta {
2092
+ Name : "foo" ,
2093
+ Namespace : "mutatedns1" ,
2094
+ Annotations : map [string ]string {"foo" : "bar" },
2095
+ },
2096
+ },
2097
+ ),
2098
+ node : & node {
2099
+ identity : corev1.ObjectReference {
2100
+ Kind : "Cluster" ,
2101
+ Namespace : "ns1" ,
2102
+ Name : "foo" ,
2103
+ APIVersion : "cluster.x-k8s.io/v1beta1" ,
2104
+ },
2105
+ },
2106
+ mutators : []ResourceMutatorFunc {
2107
+ func (u * unstructured.Unstructured ) error {
2108
+ return unstructured .SetNestedField (u .Object ,
2109
+ "mutatedns1" ,
2110
+ "metadata" , "namespace" )
2111
+ },
2112
+ },
2113
+ },
2114
+ want : func (g * WithT , toClient client.Client ) {
2115
+ c := & clusterv1.Cluster {}
2116
+ key := client.ObjectKey {
2117
+ Namespace : "mutatedns1" ,
2118
+ Name : "foo" ,
2119
+ }
2120
+ g .Expect (toClient .Get (context .Background (), key , c )).ToNot (HaveOccurred ())
2121
+ g .Expect (c .Annotations ).To (BeEmpty ())
2122
+ },
2123
+ },
2078
2124
{
2079
2125
name : "should not update Global objects" ,
2080
2126
args : args {
@@ -2163,7 +2209,7 @@ func Test_createTargetObject(t *testing.T) {
2163
2209
fromProxy : tt .args .fromProxy ,
2164
2210
}
2165
2211
2166
- err := mover .createTargetObject (ctx , tt .args .node , tt .args .toProxy , nil , sets .New [string ]())
2212
+ err := mover .createTargetObject (ctx , tt .args .node , tt .args .toProxy , tt . args . mutators , sets .New [string ]())
2167
2213
if tt .wantErr {
2168
2214
g .Expect (err ).To (HaveOccurred ())
2169
2215
return
0 commit comments