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