Skip to content

ExtraResources namespace is ignored when using matchLabels #600

Description

@YuriiBudnyi

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions