What happened?
ExtraResources with matchLabels and namespace appears to ignore namespace.
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
What happened?
ExtraResourceswithmatchLabelsandnamespaceappears to ignorenamespace.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:
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