Skip to content

ExtraResources.matchName doesn't find my XR but matchLabels does #501

@mattupstate

Description

@mattupstate

What happened?

With Crossplane 2 I'm trying to get a reference to an existing instance of a custom XR. I'm trying to reference it like so:

apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: ExtraResources
requirements:
  serviceStacks:
    apiVersion: stacks.example.acme.com/v1alpha1
    kind: ServiceStack
    matchName: {{ .observed.composite.resource.spec.stackRef.name }}

But the slice, referenced through getExtraResources . "serviceStacks", is always empty. However, if I query labels added by Crossplane the slice is not empty, like so:

apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: ExtraResources
requirements:
  serviceStacks:
    apiVersion: stacks.example.acme.com/v1alpha2
    kind: ServiceStack
    matchLabels:
      crossplane.io/composite: {{ .observed.composite.resource.spec.stackRef.name }}

The slice contains one element. However, and this makes no sense to me, I can't get at it through a slice index. I have no issues seeing the reference if I iterate the slice like so:

---
apiVersion: v1
kind: ConfigMap
metadata:
  annotations:
    {{ setResourceNameAnnotation "debug-cm" }}
data:
  {{- $someExtraResources := getExtraResources . "serviceStacks" }}
  {{- range $i, $extraResource := $someExtraResources }}
  item-{{ $i }}: "{{ $extraResource.resource.metadata.name }}"
  {{- end }}

The resulting ConfigMap looks like this:

apiVersion: v1
kind: ConfigMap
data:
  item-0: acme-example-service

But using index like so:

apiVersion: v1
kind: ConfigMap
metadata:
  annotations:
    {{ setResourceNameAnnotation "debug-cm" }}
data:
  {{- $someExtraResources := getExtraResources . "serviceStacks" }}
  {{- $extraResource := (index $someExtraResources 0) }}
  item: "{{ $extraResource.resource.metadata.name }}"

I always get an out of range error:

cannot compose resources: pipeline step "render-templates" returned a fatal result: cannot execute template: template: manifests:50:25: executing "manifests" at <index $someExtraResources 0>: error calling index: reflect: slice index out of range

What on earth am I misunderstanding?

Is this maybe a side effect of the underlying Crossplane SDK in the function pinned to a 1.X version? Perhaps similar to #483?

What environment did it happen in?

Crossplane 2. Latest version of function.

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