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

Declaring multiple traits in KameletBinding fails badly #3458

Closed
oscerd opened this issue Jul 19, 2022 · 9 comments · Fixed by #3493
Closed

Declaring multiple traits in KameletBinding fails badly #3458

oscerd opened this issue Jul 19, 2022 · 9 comments · Fixed by #3493
Assignees
Labels
area/traits kind/bug Something isn't working

Comments

@oscerd
Copy link
Contributor

oscerd commented Jul 19, 2022

If you try something like:

apiVersion: [camel.apache.org/v1alpha1](https://camel.apache.org/v1alpha1)
kind: KameletBinding
metadata:
  name: test
spec:
  integration:
    traits:
      camel:
        configuration:
          properties:
           - "camel.aws.vault.accessKey=access"
           - "camel.aws.vault.secretKey=secret"
           - "camel.aws.vault.region=region"
      builder:
        configuration:
          properties:
           - "quarkus.camel.service.discovery.include-patterns=META-INF/services/org/apache/camel/properties-function/*"
  source:
    ref:
      kind: Kamelet
      apiVersion: [camel.apache.org/v1alpha1](https://camel.apache.org/v1alpha1)
      name: timer-source
    properties:
      period: "5000"
      message: '"Invocation"'
  steps:
  - ref:
      kind: Kamelet
      apiVersion: [camel.apache.org/v1alpha1](https://camel.apache.org/v1alpha1)
      name: http-sink
    properties:
      url: "https://finnhub.io/api/v1/quote?symbol=AAPL&token={{aws:finnhub-token}}"
  sink:
    ref:
      kind: Kamelet
      apiVersion: [camel.apache.org/v1alpha1](https://camel.apache.org/v1alpha1)
      name: log-sink

This will fail with:

{"level":"error","ts":1658164253.419387,"logger":"controller.integration-controller","msg":"Reconciler error","reconciler group":"camel.apache.org","reconciler kind":"Integration","name":"test","namespace":"default","error":"error executing post actions: error during apply resource: default/test: failed to create typed patch object (default/test; apps/v1, Kind=Deployment): errors:\n .spec.template.spec.containers[name=\"integration\"].volumeMounts: duplicate entries for key [mountPath=\"/etc/camel/conf.d/user.properties\"]\n .spec.template.spec.volumes: duplicate entries for key [name=\"user-properties\"]","errorVerbose":"error during apply resource: default/test: failed to create typed patch object (default/test; apps/v1, Kind=Deployment): errors:\n .spec.template.spec.containers[name=\"integration\"].volumeMounts: duplicate entries for key [mountPath=\"/etc/camel/conf.d/user.properties\"]\n .spec.template.spec.volumes: duplicate entries for key [name=\"user-properties\"]\nerror executing post actions\ngithub.com/apache/camel-k/pkg/trait.Apply\n\tgithub.com/apache/camel-k/pkg/trait/trait.go:55\ngithub.com/apache/camel-k/pkg/controller/integration.(*monitorAction).Handle\n\tgithub.com/apache/camel-k/pkg/controller/integration/monitor.go:118\ngithub.com/apache/camel-k/pkg/controller/integration.(*reconcileIntegration).Reconcile\n\tgithub.com/apache/camel-k/pkg/controller/integration/integration_controller.go:309\ngithub.com/apache/camel-k/pkg/util/monitoring.(*instrumentedReconciler).Reconcile\n\tgithub.com/apache/camel-k/pkg/util/monitoring/controller.go:70\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:114\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:311\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227\nruntime.goexit\n\truntime/asm_amd64.s:1371","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227"}

I don't know if the declaration is wrong, but I prefer open an issue to track.

@squakez
Copy link
Contributor

squakez commented Jul 19, 2022

Yeah, I think the problem is the declaration, as the format expected may be this one:

if you need to specify an array of values, the syntax will be trait.camel.apache.org/trait.conf: "["opt1", "opt2", …​]"

from https://camel.apache.org/camel-k/1.9.x/kamelets/kamelets-user.html#_trait_via_annotations

please, try that and let us know how it goes.

@squakez
Copy link
Contributor

squakez commented Jul 19, 2022

Just noticing that one would be for annotations. Probably it is anyhow the preferred way to add traits to KameletBindings.

@oscerd
Copy link
Contributor Author

oscerd commented Jul 19, 2022

If I go with

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
  name: daje-101
  annotations:
    trait.camel.apache.org/camel.properties: ["camel.aws.vault.accessKey=xxxx","camel.aws.vault.secretKey=yyyy","camel.aws.vault.region=region"]
    trait.camel.apache.org/builder.properties: ["quarkus.camel.service.discovery.include-patterns=META-INF/services/org/apache/camel/properties-function/*"]
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1alpha1
      name: timer-source
    properties:
      period: "5000"
      message: '"Invocation"'
  steps:
  - ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1alpha1
      name: http-sink
    properties:
      url: "https://finnhub.io/api/v1/quote?symbol=AAPL&token={{aws:finnhub-token}}"
  sink:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1alpha1
      name: log-sink

This will fail with

error validating data: [ValidationError(KameletBinding.metadata.annotations.trait.camel.apache.org/builder.properties): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2.annotations: got "array", expected "string", ValidationError(KameletBinding.metadata.annotations.trait.camel.apache.org/camel.properties): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2.annotations: got "array", expected "string"]; if you choose to ignore these errors, turn validation off with --validate=false

@oscerd
Copy link
Contributor Author

oscerd commented Jul 19, 2022

Ok, it needs to be escaped. Let's see if it works or not.

@oscerd
Copy link
Contributor Author

oscerd commented Jul 19, 2022

Same error
{"level":"error","ts":1658224752.5068548,"logger":"controller.integration-controller","msg":"Reconciler error","reconciler group":"camel.apache.org","reconciler kind":"Integration","name":"daje-101","namespace":"default","error":"error executing post actions: error during apply resource: default/daje-101: failed to create typed patch object (default/daje-101; apps/v1, Kind=Deployment): errors:\n .spec.template.spec.containers[name=\"integration\"].volumeMounts: duplicate entries for key [mountPath=\"/etc/camel/conf.d/user.properties\"]\n .spec.template.spec.volumes: duplicate entries for key [name=\"user-properties\"]","errorVerbose":"error during apply resource: default/daje-101: failed to create typed patch object (default/daje-101; apps/v1, Kind=Deployment): errors:\n .spec.template.spec.containers[name=\"integration\"].volumeMounts: duplicate entries for key [mountPath=\"/etc/camel/conf.d/user.properties\"]\n .spec.template.spec.volumes: duplicate entries for key [name=\"user-properties\"]\nerror executing post actions\ngithub.com/apache/camel-k/pkg/trait.Apply\n\tgithub.com/apache/camel-k/pkg/trait/trait.go:55\ngithub.com/apache/camel-k/pkg/controller/integration.(*monitorAction).Handle\n\tgithub.com/apache/camel-k/pkg/controller/integration/monitor.go:118\ngithub.com/apache/camel-k/pkg/controller/integration.(*reconcileIntegration).Reconcile\n\tgithub.com/apache/camel-k/pkg/controller/integration/integration_controller.go:309\ngithub.com/apache/camel-k/pkg/util/monitoring.(*instrumentedReconciler).Reconcile\n\tgithub.com/apache/camel-k/pkg/util/monitoring/controller.go:70\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:114\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:311\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227\nruntime.goexit\n\truntime/asm_amd64.s:1371","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227"}

@squakez
Copy link
Contributor

squakez commented Jul 19, 2022

Marking it as a bug, it may be an issue in the camel trait as I see it tries to mount several times the same volume.

@squakez squakez added kind/bug Something isn't working area/traits labels Jul 19, 2022
@squakez
Copy link
Contributor

squakez commented Jul 19, 2022

As a temporary workaround you can use the deprecated .spec.configuration property:

Configuration []ConfigurationSpec `json:"configuration,omitempty"`

@oscerd
Copy link
Contributor Author

oscerd commented Jul 19, 2022

It's not really critical at this time, but supporting vault for loading properties, means being able to essentially inject either camel properties or env variables and adding the camel component JAR for the vaults used.. I think this should be possible in all the way we are offering and for the moment it seems to be working only through Kamel run.

@squakez squakez self-assigned this Jul 26, 2022
@squakez
Copy link
Contributor

squakez commented Jul 26, 2022

It seems the problem is happening when there is both a camel.properties trait enabled and a Kamelet property configured. Probably we're trying to mount twice the same user.properties instead of merging them into one unique (or 2 property file with different name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/traits kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants