crossplane-contrib / crossplane-contrib/function-go-templating
ExtraResources namespace is ignored when using matchLabels
- Dominant language
- Go
- Stars
- 100
- Forks
- 65
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 9
Description
### What happened?
`ExtraResources` with `matchLabels` and `namespace` appears to ignore `namespace`.
```yaml
apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: ExtraResources
requirements:
databaseResource:
apiVersion: mssql.sql.m.crossplane.io/v1alpha1
kind: Database
matchLabels:
app.kubernetes.io/managed-by: crossplane
app.kubernetes.io/component: database
namespace: test
```
ToResourceSelector() returns before setting Namespace when matchLabels is used:
https://github.com/crossplane-contrib/function-go-templating/blob/v0.12.2/extraresources.go#L39-L56
Possible fix:
```
func (e *ExtraResourcesRequirement) ToResourceSelector() *fnv1.ResourceSelector {
out := &fnv1.ResourceSelector{
ApiVersion: e.APIVersion,
Kind: e.Kind,
}
if e.MatchName == "" {
out.Match = &fnv1.ResourceSelector_MatchLabels{
MatchLabels: &fnv1.MatchLabels{Labels: e.MatchLabels},
}
} else {
out.Match = &fnv1.ResourceSelector_MatchName{
MatchName: e.MatchName,
}
}
if e.Namespace != "" {
out.Namespace = &e.Namespace
}
return out
}
```
### How can we reproduce it?
Create matching namespaced resources in two namespaces, then request them with ExtraResources using both matchLabels and namespace.
Expected result: only resources from the requested namespace.
Actual result: resources from other namespaces may be included.
### What environment did it happen in?
Function version:
xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.12.0
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in extraresources.go at ToResourceSelector(), around the referenced lines, and compare the matchLabels path with the namespace assignment. Reproduce the issue with matching namespaced resources in two namespaces; done means a request using matchLabels and namespace returns only resources from the requested namespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100