citrusframework / yaks

YAKS is a platform to enable Cloud Native BDD testing on Kubernetes
Apache License 2.0
82 stars 28 forks source link

yaks run does not work on Camel K routes with traits config #362

Closed zhiminglim closed 2 years ago

zhiminglim commented 2 years ago

Hello, thanks for your work on yaks. I'm looking at writing automated testing for Camel K and came across this project which seems to have a lot of potential.

I have been tinkering around with the framework, but I'm running into some issues. (Disclaimer: I'm using Camel K version 1.7.0 with yaks version 0.7.0)

So I have a feature file (camelk-groovy-config.feature) as such:

Feature: CamelK Groovy Config

  Scenario: Print Camel K groovy integration
    Given create Camel-K integration helloworld.groovy with configuration:
      | traits       | quarkus.native=true,quarkus.enabled=true,route.enabled=true |
      | source       | from('timer:tick?period=1000').setBody().constant('Hello world from Camel K!').to('log:info') |
    Given Camel-K integration helloworld is running
    Then Camel-K integration helloworld should print Hello world from Camel K!

I then execute yaks run camelk-groovy-config.feature -n camel-k-integrations with the operation logs returning me below: (Full stacktrace at stacktrace.log)

Test 'camelk-groovy-config' created
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] Monitoring pod test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  | ------------------------------------------------------------------------
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |        .__  __
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |   ____ |__|/  |________ __ __  ______
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  | _/ ___\|  \   __\_  __ \  |  \/  ___/
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  | \  \___|  ||  |  |  | \/  |  /\___ \
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |  \___  >__||__|  |__|  |____//____  >
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |      \/                           \/
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  | C I T R U S  T E S T S  3.1.0
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  | ------------------------------------------------------------------------
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] INFO  |
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1] Scenario: Print Camel K groovy integration                                   # org/citrusframework/yaks/camelk-groovy-config.feature:3
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]   Given create Camel-K integration helloworld.groovy with configuration:     # org.citrusframework.yaks.camelk.CamelKSteps.createIntegration(java.lang.String,java.lang.String,java.util.Map<java.lang.String, java.lang.String>)
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]   Given Camel-K integration helloworld is running                            # org.citrusframework.yaks.camelk.CamelKSteps.integrationShouldBeRunning(java.lang.String)
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]       com.consol.citrus.exceptions.TestCaseFailedException: Action timeout after 300000 milliseconds.
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]   at com.consol.citrus.DefaultTestCase.executeAction(DefaultTestCase.java:144)
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]   at com.consol.citrus.DefaultTestCaseRunner.run(DefaultTestCaseRunner.java:125)
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]   at org.citrusframework.yaks.camelk.CamelKSteps.integrationShouldBeRunning(CamelKSteps.java:174)
[test-camelk-groovy-config-c7f55ugqd9mueblms5r0-rvwws test-1]   at ✽.Camel-K integration helloworld is running(classpath:org/citrusframework/yaks/camelk-groovy-config.feature:7)
...
...


Upon closer inspection, it seems that the blockage was due to an error while building the Camel K Integration

kubectl describe integration -n camel-k-integrations helloworld

Name:         helloworld
Namespace:    camel-k-integrations
Labels:       <none>
Annotations:  <none>
API Version:  camel.apache.org/v1
Kind:         Integration
Metadata:
  Creation Timestamp:  2022-01-12T04:17:00Z
  Generation:          1
  Managed Fields:
    API Version:  camel.apache.org/v1
    Fields Type:  FieldsV1
    fieldsV1:
      f:spec:
        .:
        f:sources:
        f:traits:
          .:
          f:quarkus:
            .:
            f:configuration:
              .:
              f:enabled:
              f:native:
          f:route:
            .:
            f:configuration:
              .:
              f:enabled:
    Manager:         okhttp
    Operation:       Update
    Time:            2022-01-12T04:17:00Z
  Resource Version:  94907165
  UID:               388aa716-0525-4c4a-8e58-a9e45581f5ff
Spec:
  Sources:
    Content:  from('timer:tick?period=1000').setBody().constant('Hello world from Camel K!').to('log:info')
    Name:     helloworld.groovy
  Traits:
    Quarkus:
      Configuration:
        Enabled:  true
        Native:   true
    Route:
      Configuration:
        Enabled:  true
Events:
  Type     Reason            Age                From                            Message
  ----     ------            ----               ----                            -------
  Warning  IntegrationError  63s (x6 over 65s)  camel-k-integration-controller  Cannot reconcile Integration helloworld: error during trait customization: json: cannot unmarshal string into Go struct field routeTrait.enabled of type bool
  Warning  IntegrationError  21s (x8 over 64s)  camel-k-integration-controller  Cannot reconcile Integration helloworld: error during trait customization: json: cannot unmarshal string into Go struct field quarkusTrait.enabled of type bool

The Integration manifest generated seems to have created traits with type:string instead of type:bool.

kubectl get integration -n camel-k-integrations helloworld -o yaml                                                                                                                                         

apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  creationTimestamp: "2022-01-12T04:17:00Z"
  generation: 1
  name: helloworld
  namespace: camel-k-integrations
  resourceVersion: "94907165"
  uid: 388aa716-0525-4c4a-8e58-a9e45581f5ff
spec:
  sources:
  - content: from('timer:tick?period=1000').setBody().constant('Hello world from Camel
      K!').to('log:info')
    name: helloworld.groovy
  traits:
    quarkus:
      configuration:
        enabled: "true"
        native: "true"
    route:
      configuration:
        enabled: "true"


May be related to issue #335 but for now, is there anything I can do or change about my Camel K test code?

christophd commented 2 years ago

That's a bug, thanks for reporting!

as a workaround you can try to provide the integration as a custom resource via yaml file resource instead. You can load the integration.yaml resource in the test via

    Given create Kubernetes custom resource in integrations.camel.apache.org
"""
apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  name: helloworld
  [...]
"""

or via external file resource

    Given load Kubernetes custom resource helloworld.yaml in integrations.camel.apache.org

The external file resource helloworld.yaml has to be added in the yaks-config.yaml then as a test resource.

config:
  runtime:
    resources:
      - helloworld.yaml

hope this helps

zhiminglim commented 2 years ago

Perfect! Appreciate the help, your solution works :)

I have no more questions now, will be closing this issue.