Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra resources fails when using selector on field generated by previous step #31

Open
JakobGSvendsen opened this issue Oct 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JakobGSvendsen
Copy link

JakobGSvendsen commented Oct 30, 2024

What happened?

I am trying to use a value from a extra resource to find another extra resource.
Since I couldnt find a way to map it inside one instance of the function in a pipeline, I decided to make a "predeploy" template step that simply reads the value and outputs to "status".

Then after that step I want to run a second extra resroucce step that uses the status value to get the additional extra resource, but it fails.

I thought it worked, but it turned out it only worked cause I updated it on already existing resources that did already have the status set.

For new resource I get:

message: 'cannot compose resources: pipeline step "pull-extra-resources-identity" returned a fatal result: could not build extra resource requirements: cannot get value from field path "status.iitech.shortName": status.iitech: no such field'

Is it not possible to make it like this? I thought it would be as it is a "pipeline".
if not, is there any other way that I can use a value from my "blueprint" extra resource to find my "userassignedIdentity" resource?

How can we reproduce it?

This is my composition, the field I am setting is defined in the compositeresourcedefintion:

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: iitech-mongodb
spec:
  compositeTypeRef:
    apiVersion: iitech.dk/v1
    kind: xMongoDB
  mode: Pipeline
  pipeline:
  - step: pull-extra-resources
    functionRef:
      name: function-extra-resources
    input:
      apiVersion: extra-resources.fn.crossplane.io/v1beta1
      kind: Input
      spec:
        extraResources:
          - kind: Blueprint
            into: blueprint
            apiVersion: iitech.dk/v1alpha1
            type: Selector
            selector:
              maxMatch: 1
              minMatch: 1
              matchLabels:
                - key: "iitech.dk/backstage-catalog-entity"
                  type: FromCompositeFieldPath
                  valueFromFieldPath: spec.snowId
          - kind: ConfigMap
            into: env
            apiVersion: v1
            type: Selector
            selector:
              maxMatch: 1
              minMatch: 1
              matchLabels:
                - key: name
                  type: Value
                  value: env
  - step: go-templates-predeploy
    functionRef:
      name: function-go-templating
    input:
      apiVersion: gotemplating.fn.crossplane.io/v1beta1
      kind: GoTemplate
      source: FileSystem
      fileSystem:
        dirPath: /templates/predeploy.tpl
  - step: pull-extra-resources-identity
    functionRef:
      name: function-extra-resources
    input:
      apiVersion: extra-resources.fn.crossplane.io/v1beta1
      kind: Input
      spec:
        extraResources:
          - kind: Blueprint
            into: blueprint
            apiVersion: iitech.dk/v1alpha1
            type: Selector
            selector:
              maxMatch: 1
              minMatch: 1
              matchLabels:
                - key: "iitech.dk/backstage-catalog-entity"
                  type: FromCompositeFieldPath
                  valueFromFieldPath: spec.snowId
          - kind: ConfigMap
            into: env
            apiVersion: v1
            type: Selector
            selector:
              maxMatch: 1
              minMatch: 1
              matchLabels:
                - key: name
                  type: Value
                  value: env
          - kind: UserAssignedIdentity
            into: identity
            apiVersion: managedidentity.azure.upbound.io/v1beta1
            type: Selector
            selector:
              maxMatch: 1
              minMatch: 1
              matchLabels:
                - key: "iitech.dk/shortName"
                  type: FromCompositeFieldPath
                  valueFromFieldPath: status.iitech.shortName
  - step: go-templates-deploy-rg
    functionRef:
      name: function-go-templating
    input:
      apiVersion: gotemplating.fn.crossplane.io/v1beta1
      kind: GoTemplate
      source: FileSystem
      fileSystem:
        dirPath: /templates/resourcegroup.tpl
  - step: go-templates-deploy-account
    functionRef:
      name: function-go-templating
    input:
      apiVersion: gotemplating.fn.crossplane.io/v1beta1
      kind: GoTemplate
      source: FileSystem
      fileSystem:
        dirPath: /templates/cosmosdb.tpl
  - step: go-templates-deploy-rbac
    functionRef:
      name: function-go-templating
    input:
      apiVersion: gotemplating.fn.crossplane.io/v1beta1
      kind: GoTemplate
      source: FileSystem
      fileSystem:
        dirPath: /templates/cosmosdb-roleassignment.tpl
  - step: automatically-detect-ready-composed-resources
    functionRef:
      name: function-auto-ready

my predeploy template looks like this:

{{/* Extra resources */}}
{{- $blueprint := index (index .context "apiextensions.crossplane.io/extra-resources") "blueprint" 0}}
---
apiVersion: iitech.dk/v1
kind: xMongoDB
metadata:
  annotations:
    gotemplating.fn.crossplane.io/composition-resource-name: status-shortname
status:
  iitech:
    shortName: {{ $blueprint.spec.shortName }} 

What environment did it happen in?

Function version: v0.0.3

@JakobGSvendsen JakobGSvendsen added the bug Something isn't working label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant