@@ -200,7 +200,7 @@ func TestRunFunctionSimple(t *testing.T) {
200200 },
201201 },
202202 },
203- "ExtraResources " : {
203+ "ExtraResourcesClusterScoped " : {
204204 reason : "The Function should return the desired composite with extra resources." ,
205205 args : args {
206206 req : & fnv1.RunFunctionRequest {
@@ -211,11 +211,11 @@ func TestRunFunctionSimple(t *testing.T) {
211211 "metadata": {
212212 "name": "basic"
213213 },
214- "spec": {
215- "target": "Default",
216- "source": "items = [\n{\n apiVersion: \"meta.krm.kcl.dev/v1alpha1\"\n kind: \"ExtraResources\"\n requirements = {\n \"cool-extra-resource\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchName: \"cool-extra-resource\"\n }\n }\n},\n{\n apiVersion: \"meta.krm.kcl.dev/v1alpha1\"\n kind: \"ExtraResources\"\n requirements = {\n \"another-cool-extra-resource\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchLabels = {\n key: \"value\"\n }\n }\n \"yet-another-cool-extra-resource\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchName: \"foo\"\n }\n }\n},\n{\n apiVersion: \"meta.krm.kcl.dev/v1alpha1\"\n kind: \"ExtraResources\"\n requirements = {\n \"all-cool-resources\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchLabels = {}\n }\n }\n}\n]\n"
217- }
218- }` ),
214+ "spec": {
215+ "target": "Default",
216+ "source": "items = [\n{\n apiVersion: \"meta.krm.kcl.dev/v1alpha1\"\n kind: \"ExtraResources\"\n requirements = {\n \"cool-extra-resource\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchName: \"cool-extra-resource\"\n }\n }\n},\n{\n apiVersion: \"meta.krm.kcl.dev/v1alpha1\"\n kind: \"ExtraResources\"\n requirements = {\n \"another-cool-extra-resource\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchLabels = {\n key: \"value\"\n }\n }\n \"yet-another-cool-extra-resource\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchName: \"foo\"\n }\n }\n},\n{\n apiVersion: \"meta.krm.kcl.dev/v1alpha1\"\n kind: \"ExtraResources\"\n requirements = {\n \"all-cool-resources\" = {\n apiVersion: \"example.org/v1\"\n kind: \"CoolExtraResource\"\n matchLabels = {}\n }\n }\n}\n]\n"
217+ }
218+ }` ),
219219 Observed : & fnv1.State {
220220 Composite : & fnv1.Resource {
221221 Resource : resource .MustStructJSON (xr ),
@@ -286,6 +286,67 @@ func TestRunFunctionSimple(t *testing.T) {
286286 },
287287 },
288288 },
289+ "ExtraResourcesNamespaced" : {
290+ reason : "The Function should pass through a single extra resource with matchName and matchNamespace" ,
291+ args : args {
292+ req : & fnv1.RunFunctionRequest {
293+ Meta : & fnv1.RequestMeta {Tag : "extra-resources-namespace-matchname" },
294+ Input : resource .MustStructJSON (`{
295+ "apiVersion": "krm.kcl.dev/v1alpha1",
296+ "kind": "KCLInput",
297+ "metadata": {"name": "basic"},
298+ "spec": {
299+ "target": "Default",
300+ "source": "items = [{ apiVersion: \"meta.krm.kcl.dev/v1alpha1\", kind: \"ExtraResources\", requirements = { \"cool-ns-resource-matchname\" = { apiVersion: \"example.org/v1\", kind: \"CoolExtraResource\", matchNamespace: \"cool-ns-scoped-ns\", matchName: \"cool-ns-scoped-resource\" } } }]"
301+ }
302+ }` ),
303+ Observed : & fnv1.State {
304+ Composite : & fnv1.Resource {Resource : resource .MustStructJSON (xr )},
305+ },
306+ Desired : & fnv1.State {
307+ Composite : & fnv1.Resource {Resource : resource .MustStructJSON (xr )},
308+ },
309+ },
310+ },
311+ want : want {
312+ rsp : & fnv1.RunFunctionResponse {
313+ Meta : & fnv1.ResponseMeta {Tag : "extra-resources-namespace-matchname" , Ttl : durationpb .New (response .DefaultTTL )},
314+ Results : []* fnv1.Result {},
315+ Requirements : & fnv1.Requirements {
316+ ExtraResources : map [string ]* fnv1.ResourceSelector {
317+ "cool-ns-resource-matchname" : {
318+ ApiVersion : "example.org/v1" ,
319+ Kind : "CoolExtraResource" ,
320+ Namespace : ptr.To [string ]("cool-ns-scoped-ns" ),
321+ Match : & fnv1.ResourceSelector_MatchName {MatchName : "cool-ns-scoped-resource" },
322+ },
323+ },
324+ },
325+ Desired : & fnv1.State {Composite : & fnv1.Resource {Resource : resource .MustStructJSON (xr )}},
326+ },
327+ },
328+ },
329+ "ExtraResourcesNamespacedWithLabels" : {
330+ reason : "The Function should pass with a single extra resource with matchLabels and matchNamespace" ,
331+ args : args {
332+ req : & fnv1.RunFunctionRequest {
333+ Meta : & fnv1.RequestMeta {Tag : "extra-resources-namespace-labels" },
334+ Input : resource .MustStructJSON (`{
335+ "apiVersion":"krm.kcl.dev/v1alpha1","kind":"KCLInput","metadata":{"name":"basic"},"spec":{"target":"Default","source":"items=[{ apiVersion:\"meta.krm.kcl.dev/v1alpha1\", kind:\"ExtraResources\", requirements={ \"cool-resource-match-ns-match-labels\"={ apiVersion:\"example.org/v1\", kind:\"CoolExtraResource\", matchNamespace:\"cool-ns\", matchLabels={\"cool-key\":\"cool-value\"} }}}]"}
336+ }` ),
337+ Observed : & fnv1.State {Composite : & fnv1.Resource {Resource : resource .MustStructJSON (xr )}},
338+ },
339+ },
340+ want : want {
341+ rsp : & fnv1.RunFunctionResponse {
342+ Meta : & fnv1.ResponseMeta {Tag : "extra-resources-namespace-labels" , Ttl : durationpb .New (response .DefaultTTL )},
343+ Requirements : & fnv1.Requirements {ExtraResources : map [string ]* fnv1.ResourceSelector {
344+ "cool-resource-match-ns-match-labels" : {ApiVersion : "example.org/v1" , Kind : "CoolExtraResource" , Namespace : ptr.To [string ]("cool-ns" ), Match : & fnv1.ResourceSelector_MatchLabels {MatchLabels : & fnv1.MatchLabels {Labels : map [string ]string {"cool-key" : "cool-value" }}}},
345+ }},
346+ Desired : & fnv1.State {Composite : & fnv1.Resource {Resource : resource .MustStructJSON (`{"apiVersion":"example.org/v1","kind":"XR"}` )}},
347+ },
348+ },
349+ },
289350 "ExtraResourcesIn" : {
290351 reason : "The Function should return the extra resources from the request." ,
291352 args : args {
0 commit comments