crossplane-contrib / crossplane-contrib/function-go-templating

Matchlabel criteria excludes namespace on ExtraResource

Open
#597 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
100
Forks
65
Avg merge
2d 6h
Merged PRs (30d)
9

Description

### What happened?

During development of a feature, we encoutered unexpected behaviour from the ExtraResource function.
The goal was to populate a Listenerset using httproutes from its namespace, and so we used extraresource to fecth httproutes by namespace and label (we only use a specific route type).

```
{{- $xr := getCompositeResource . }}
{{- $namespace := get $xr.metadata "namespace" }}
---
apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: ExtraResources
requirements:
routes:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
namespace: {{ $namespace }}
matchLabels:
routetype: "prj-hostname"
```

Only this combination of criteria returns HttpRoutes with label "prj-hostname" from all namespaces.
It seems to stem from the way the [search specs are used](https://github.com/crossplane-contrib/function-go-templating/blob/9222efc18ca5ed8f47782025fc3024551ded13b9/extraresources.go#L47).

The question is then, is this behaviour intentional? The namespace parameter in extraresource is not yet part of the documentation, and we were wondering if it will enventually be possible to search by label in a specific namespace.

### How can we reproduce it?
The specified example and two Httproutes in different namespaces should be enough to reproduce this behaviour.

### What environment did it happen in?
Function version: 0.12.2
Crossplane 2.2.0
Cluster: Azure AKS
Kube 1.35.3

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with extraresources.go at the linked search-spec handling and reproduce the report using two HTTPRoutes in different namespaces with the provided template. Check how namespace and matchLabels are combined, then verify that the intended namespace-scoped label behavior is covered by the resulting behavior and documented semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.