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

Passing data from component to trait #6484

Open
raphdom opened this issue Mar 18, 2024 · 0 comments
Open

Passing data from component to trait #6484

raphdom opened this issue Mar 18, 2024 · 0 comments

Comments

@raphdom
Copy link

raphdom commented Mar 18, 2024

Describe the bug
I am using kubevela to wrap my Crossplane Compositions in order to give a better experience to the developers to define Applications. But I have many dependencies inside the compositions.
I need to read a component status parameter from the trait, after the component has been created:

To Reproduce

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: restapi
  namespace: playground-dev
spec:
  components:
    - name: restapi
      type: aws-apigateway-restapi
      traits:
        - type: aws-restapi-method
          properties:
            name: process-request
            component: processing-request-lambda
"aws-apigateway-restapi": {
    attributes: workload: definition: {
        apiVersion: "aws.example.eu/v1alpha1"
        kind:       "AwsApiGatewayRestApiClaim"
    }
    description: "ApiGateway RestAPI Using Crossplane"
    type: "component"
}

template: {
    import ("strings")
    output: {
        spec: {
            name: context.name
	    project: strings.Split(context.namespace,"-")[0]
	    environment: strings.Split(context.namespace,"-")[1]
        }
        apiVersion: "aws.example.eu/v1alpha1"
	kind:       "AwsApiGatewayRestApiClaim"
    }
}

This crossplane composition has an output value from the status of the provider, it is the rootResourceId

        - type: ToCompositeFieldPath
          fromFieldPath: status.atProvider.rootResourceId
          toFieldPath: spec.rootResourceId

I need to inject this in the trait to create the method in AWS

"aws-restapi-method": {
	attributes: {
		appliesToWorkloads: ["aws-apigateway-restapi"]
	}
	description: "RestAPI Method"
	type: "trait"
}

template: {
  outputs: method: {
    apiVersion: "aws.example.eu/v1alpha1"
    kind:       "AwsApiGatewayRestApiMethodClaim"
    spec: {
      name: context.name
      project: context.output.spec.project
      environment: context.output.spec.environment
      restApiName: context.output.spec.name
      lambdaFunctionName: parameter.component
      rootResourceId: context.output.rootResourceId <-- HERE IS NOT WORKING
    }
  }
  parameter: {
    component: string
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant