You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/12/20 18:02:38 UTC

[GitHub] [camel-k] nicolaferraro opened a new pull request #2838: Add support for KEDA

nicolaferraro opened a new pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838


   <!-- Description -->
   
   This adds support for KEDA autoscalers. It supports both manual configuration and fully automated configuration based on Kamelet metadata. In the fully automated scenario, Kamelets are annotated with special KEDA markers to tell the KEDA trait how to configure properties. I've added documentation in the Kamelet dev and user guide.
   
   Everything is developed under addons. The only bits that are added to the main codebase are the roles/bindings for which a major refactoring was needed.
   
   I've not directly pointed to the KEDA repo to import the API since they use a single module. We can ask to provide APIs in a separate module in the future. Until then, we need to sync the APIs from time to time. We only use 2 objects and I've included only fields relevant for us.
   
   The KEDA trait allows configuring multiple triggers for an integration. In order to do it, I had to extend the CLI to support slices of complex objects. KEDA also requires that the resources being scaled have a `spec` -> `replicas` field, that we don't put by default. So, when the KEDA trait is enabled there's a specific hack in place that sets that field explicitly to make KEDA work.
   Among manual configs, the user can indicate a secret per trigger that contains authentication options, other than plain metadata.
   
   Auto-configuration works with Kamelet. By annotating Kamelets/properties with special markers, the trait is able to map Kamelet configuration to KEDA configuration, so that a KameletBinding can automatically create all KEDA resources without additional input from the user.
   
   I've also created some KEDA-enabled Kamelets that I'll publish when this PR gets merged.
   The trick is to add something like this in the Kamelet definition:
   
   ```yaml
       properties:
         topic:
           title: Topic Names
           description: Comma separated list of Kafka topic names
           type: string
           x-descriptors:
           - urn:keda:metadata:topic
           - urn:keda:required
   ```
   
   That tells to the trait that the `topic` Kamelet property corresponds to the `topic` KEDA parameter. There are more sophisticated configuration explained in the dev guide.
   
   So when you bind e.g. a Kafka Source Kamelet to a destination, you need to add a `trait.camel.apache.org/keda.enabled=true` annotation and nothing else and you'll have autoscaling and scaling to zero from Kafka.
   
   I've also added metadata to the AWS-SQS Kamelet and plan to do a demo with both.
   The new Kamelet looks like this:
   
   ```yaml
   # ---------------------------------------------------------------------------
   # Licensed to the Apache Software Foundation (ASF) under one or more
   # contributor license agreements.  See the NOTICE file distributed with
   # this work for additional information regarding copyright ownership.
   # The ASF licenses this file to You under the Apache License, Version 2.0
   # (the "License"); you may not use this file except in compliance with
   # the License.  You may obtain a copy of the License at
   #
   #      http://www.apache.org/licenses/LICENSE-2.0
   #
   # Unless required by applicable law or agreed to in writing, software
   # distributed under the License is distributed on an "AS IS" BASIS,
   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   # See the License for the specific language governing permissions and
   # limitations under the License.
   # ---------------------------------------------------------------------------
   
   apiVersion: camel.apache.org/v1alpha1
   kind: Kamelet
   metadata:
     name: aws-sqs-source
     annotations:
       camel.apache.org/kamelet.support.level: "Preview"
       camel.apache.org/catalog.version: "main-SNAPSHOT"
       camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMTAwIDEwMCIKICAgaGVpZ2h0PSI3Mi4xOTk5OTciCiAgIHZlcnNpb249IjEuMSIKICAgdmlld0JveD0iMCAwIDU5Ljg0OTk5OCA3Mi4xOTk5OTciCiAgIHdpZHRoPSI1OS44NDk5OTgiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiCiAgIGlkPSJzdmcxNDUiCiAgIHNvZGlwb2RpOmRvY25hbWU9ImRvd25sb2FkLnN2ZyIKICAgaW5rc2NhcGU6dmVyc2lvbj0iMS4wLjIgKGU4NmM4NzA4NzksIDIwMjEtMDEtMTUpIj48bWV0YWRhdGEKI
 CAgICBpZD0ibWV0YWRhdGExNTEiPjxyZGY6UkRGPjxjYzpXb3JrCiAgICAgICAgIHJkZjphYm91dD0iIj48ZGM6Zm9ybWF0PmltYWdlL3N2Zyt4bWw8L2RjOmZvcm1hdD48ZGM6dHlwZQogICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL3B1cmwub3JnL2RjL2RjbWl0eXBlL1N0aWxsSW1hZ2UiIC8+PGRjOnRpdGxlPjwvZGM6dGl0bGU+PC9jYzpXb3JrPjwvcmRmOlJERj48L21ldGFkYXRhPjxkZWZzCiAgICAgaWQ9ImRlZnMxNDkiIC8+PHNvZGlwb2RpOm5hbWVkdmlldwogICAgIHBhZ2Vjb2xvcj0iI2ZmZmZmZiIKICAgICBib3JkZXJjb2xvcj0iIzY2NjY2NiIKICAgICBib3JkZXJvcGFjaXR5PSIxIgogICAgIG9iamVjdHRvbGVyYW5jZT0iMTAiCiAgICAgZ3JpZHRvbGVyYW5jZT0iMTAiCiAgICAgZ3VpZGV0b2xlcmFuY2U9IjEwIgogICAgIGlua3NjYXBlOnBhZ2VvcGFjaXR5PSIwIgogICAgIGlua3NjYXBlOnBhZ2VzaGFkb3c9IjIiCiAgICAgaW5rc2NhcGU6d2luZG93LXdpZHRoPSIxOTIwIgogICAgIGlua3NjYXBlOndpbmRvdy1oZWlnaHQ9IjEwMTYiCiAgICAgaWQ9Im5hbWVkdmlldzE0NyIKICAgICBzaG93Z3JpZD0iZmFsc2UiCiAgICAgZml0LW1hcmdpbi10b3A9IjAuMSIKICAgICBmaXQtbWFyZ2luLWxlZnQ9IjAuMSIKICAgICBmaXQtbWFyZ2luLXJpZ2h0PSIwLjEiCiAgICAgZml0LW1hcmdpbi1ib3R0b209IjAuMSIKICAgICBpbmtzY2FwZTp6b29tPSI4LjE5IgogICAgIGlua3NjYXBlOmN4PS
 IyOS45MjUiCiAgICAgaW5rc2NhcGU6Y3k9IjM2LjEiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LXk9IjI3IgogICAgIGlua3NjYXBlOndpbmRvdy1tYXhpbWl6ZWQ9IjEiCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0ic3ZnMTQ1IiAvPjxnCiAgICAgaWQ9IkFtYXpvbl9DbG91ZFNlYXJjaCIKICAgICB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMjAuMDc1LC0xMy45KSI+PGcKICAgICAgIGlkPSJnMTQyIj48cG9seWdvbgogICAgICAgICBmaWxsPSIjZDlhNzQxIgogICAgICAgICBwb2ludHM9IjIzLjk4NywzNi4yMDEgNTQuNDYyLDQwLjQ5NCA1NC40Niw1OS41MDYgMjMuOTg1LDYzLjc5MyAiCiAgICAgICAgIGlkPSJwb2x5Z29uMTIwIiAvPjxwb2x5Z29uCiAgICAgICAgIGZpbGw9IiM4NzY5MjkiCiAgICAgICAgIHBvaW50cz0iNTAuMDAzLDE0IDIwLjE3OSwyOC45MDggMjAuMTc5LDM3LjM0NCA1MC4wMDMsMjguMzk5ICIKICAgICAgICAgaWQ9InBvbHlnb24xMjIiIC8+PHBvbHlnb24KICAgICAgICAgZmlsbD0iIzg3NjkyOSIKICAgICAgICAgcG9pbnRzPSI0OS45OTcsODYgMjAuMTksNzEuMDk0IDIwLjE5LDYyLjY1NCA0OS45OTksNzEuNiAiCiAgICAgICAgIGlkPSJwb2x5Z29uMTI0IiAvPjxwb2x5Z29uCiAgICAgICAgIGZpbGw9IiNkOWE3NDEiCiAgICAgICAgIHBvaW50cz0iNTAuMDAzLDE0IDc5LjgyNSwyOC45MTQgNzkuODIzLDM3LjM1IDUwLjAwMywyOC4zOTk
 gIgogICAgICAgICBpZD0icG9seWdvbjEyNiIgLz48cG9seWdvbgogICAgICAgICBmaWxsPSIjZDlhNzQxIgogICAgICAgICBwb2ludHM9IjQ5Ljk5Nyw4NiA3OS44MDYsNzEuMDk5IDc5LjgwNiw2Mi42NiA0OS45OTksNzEuNiAiCiAgICAgICAgIGlkPSJwb2x5Z29uMTI4IiAvPjxwb2x5Z29uCiAgICAgICAgIGZpbGw9IiM4NzY5MjkiCiAgICAgICAgIHBvaW50cz0iMjAuMTc5LDI4LjkwOCAyMy45ODksMjcuMDA0IDIzLjk4NSw3Mi45OSAyMC4xNzUsNzEuMDg2ICIKICAgICAgICAgaWQ9InBvbHlnb24xMzAiIC8+PHBvbHlnb24KICAgICAgICAgZmlsbD0iIzg3NjkyOSIKICAgICAgICAgcG9pbnRzPSI1MC4wMDEsNDAuODMyIDM5LjAxOSw0Mi4yMjkgMzkuMDE3LDU3Ljc2MiA0OS45OTksNTkuMTYgIgogICAgICAgICBpZD0icG9seWdvbjEzMiIgLz48cG9seWdvbgogICAgICAgICBmaWxsPSIjODc2OTI5IgogICAgICAgICBwb2ludHM9IjM1LjA4Myw0Mi43MjkgMjcuOTU0LDQzLjYzNyAyNy45NTQsNTYuMzU0IDM1LjA4MSw1Ny4yNiAiCiAgICAgICAgIGlkPSJwb2x5Z29uMTM0IiAvPjxwb2x5Z29uCiAgICAgICAgIGZpbGw9IiM2MjRhMWUiCiAgICAgICAgIHBvaW50cz0iNzkuODIzLDM3LjM1IDU0LjQ4MSw0MC40OTYgMjMuOTg3LDM2LjIwMSA1MC4wMDMsMjguMzk5ICIKICAgICAgICAgaWQ9InBvbHlnb24xMzYiIC8+PHBvbHlnb24KICAgICAgICAgZmlsbD0iI2ZhZDc5MSIKICAgICAgICAgcG9pbnRzPSI3OS44
 MDYsNjIuNjYgNTQuNDYsNTkuNTA2IDIzLjk4NSw2My43OTMgNDkuOTk5LDcxLjYgIgogICAgICAgICBpZD0icG9seWdvbjEzOCIgLz48cG9seWdvbgogICAgICAgICBmaWxsPSIjZDlhNzQxIgogICAgICAgICBwb2ludHM9IjUwLjAwMSw0MC44MzIgNzkuODA4LDQ0LjYyOSA3OS44MDgsNTUuMzMgNDkuOTk5LDU5LjA5MiAiCiAgICAgICAgIGlkPSJwb2x5Z29uMTQwIiAvPjwvZz48L2c+PC9zdmc+Cg=="
       camel.apache.org/provider: "Apache Software Foundation"
       camel.apache.org/kamelet.group: "AWS SQS"
       camel.apache.org/keda.type: "aws-sqs-queue"
     labels:
       camel.apache.org/kamelet.type: "source"
   spec:
     definition:
       title: "AWS SQS Source"
       description: |-
         Receive data from AWS SQS.
       required:
         - queueNameOrArn
         - accessKey
         - secretKey
         - region
       type: object
       properties:
         queueNameOrArn:
           title: Queue Name
           description: The SQS Queue Name or ARN
           type: string
           x-descriptors:
           - urn:keda:metadata:queueURL
           - urn:keda:required
         deleteAfterRead:
           title: Auto-delete Messages
           description: Delete messages after consuming them
           type: boolean
           x-descriptors:
           - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
           default: true
         accessKey:
           title: Access Key
           description: The access key obtained from AWS
           type: string
           format: password
           x-descriptors:
           - urn:alm:descriptor:com.tectonic.ui:password
           - urn:camel:group:credentials
           - urn:keda:authentication:awsAccessKeyID
           - urn:keda:required
         secretKey:
           title: Secret Key
           description: The secret key obtained from AWS
           type: string
           format: password
           x-descriptors:
           - urn:alm:descriptor:com.tectonic.ui:password
           - urn:camel:group:credentials
           - urn:keda:authentication:awsSecretAccessKey
           - urn:keda:required
         region:
           title: AWS Region
           description: The AWS region to connect to
           type: string
           example: eu-west-1
           x-descriptors:
           - urn:keda:metadata:awsRegion
           - urn:keda:required
         autoCreateQueue:
           title: Autocreate Queue
           description: Setting the autocreation of the SQS queue. 
           type: boolean
           x-descriptors:
           - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
           default: false
         amazonAWSHost:
           title: AWS Host
           description: The hostname of the Amazon AWS cloud. 
           type: string
         protocol:
           title: Protocol
           description: The underlying protocol used to communicate with SQS
           type: string
           example: http or https
           default: https
     dependencies:
       - "camel:aws2-sqs"
       - "camel:kamelet"
     flow:
       from:
         uri: "aws2-sqs:{{queueNameOrArn}}"
         parameters:
           autoCreateQueue: "{{autoCreateQueue}}"
           secretKey: "{{secretKey}}"
           accessKey: "{{accessKey}}"
           region: "{{region}}"
           deleteAfterRead: "{{deleteAfterRead}}"
           amazonAWSHost: "{{?amazonAWSHost}}"
           protocol: "{{?protocol}}"
         steps:
         - to: "kamelet:sink"
   
   ```
   
   While developing I did a bit of refactoring in the serverside apply part, but later I didn't use it (but kept the refactoring).
   
   <!--
   Enter your extended release note in the below block. If the PR requires
   additional action from users switching to the new release, include the string
   "action required". If no release note is required, write "NONE". 
   
   You can (optionally) mark this PR with labels "kind/bug" or "kind/feature" to make sure
   the text is added to the right section of the release notes. 
   -->
   
   **Release Note**
   ```release-note
   Added support for KEDA autoscalers with automatic configuration when using Kamelets
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r777923238



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Right. I wonder what's the best practice in that case. Ultimately I can see two options:
   - Setting the replicas spec field is optional, then Keda logic that checks the scale sub-resource should be improved, to only fail on 404, at least handling the 500 return code gracefully
   -  Otherwise, it's mandatory, then it may be better to set it as default value in the CRD directly
   
   We could choose the later option anyway, as it makes the default value explicit. WDYT?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784236085



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah this might be seen as an obvious approach, but unfortunately it doesn't work this way. There are certain states where we need to compare the actual number of replicas to multiple values in ScaledObject and act based on the result. It is not just assignig one value as a replica count.
   
   I mean, everything could be done, right? :) So maybe if we refactor to code a lot it could be done, but I am not 100% sure about this. It would definitely make the code less logical.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784185989



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       `.spec.replicas ` and `.status.replicas ` exists and are correctly set as well?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r783859878



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Thanks a lot for the feedback. I'm not sure I read this correctly, but my interpretation of that documentation is that `specReplicasPath` is mandatory in the CustomResourceDefinition, but the field specified by the `specReplicasPath` in the custom resource is not, in which case the `/scale` subresource returns an error on GET.
   
   Similarly, `statusReplicasPath` is mandatory, but the field that's pointed in the custom resource is not, in which case the status replica value in the `/scale` subresource defaults to 0.
   
   That indicates fields are mandatory in the CRD, but the corresponding fields in the custom resources are not. If that interpretation is correct, an error on GET'ing the `/scale` sub resource does not necessary imply the absence of the `/scale` sub resource, it can also imply the field defined by `specReplicasPath` in the custom resource is not set.
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784180717



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       > That indicates fields are mandatory in the CRD, but the corresponding fields in the custom resources are not. If that interpretation is correct, an error on GET'ing the /scale sub resource does not necessary imply the absence of the /scale sub resource, it can also imply the field defined by specReplicasPath in the custom resource is not set.
   
   I missed this paragraph before. I mean that those fields need to point to an actual fields in spec/status that actually return and set the correct number of replicas. So the HPA controller (and KEDA as well) can correctly drive the scaling by modifing and quering the replica count via `/scale` subresource.
   
   Or am I missing anything?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784230293



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Sorry if I'm going to say something too naive, but in that 500 case, the `.spec.replicas` is not set, which means the current scale is not defined, and KEDA can take over and have full control to set it according to the ScaledObject spec.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784180717



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       > That indicates fields are mandatory in the CRD, but the corresponding fields in the custom resources are not. If that interpretation is correct, an error on GET'ing the /scale sub resource does not necessary imply the absence of the /scale sub resource, it can also imply the field defined by specReplicasPath in the custom resource is not set.
   
   I missed this paragraph before. I mean that those fields need to point to an actual fields that actually returns and sets a correct value. So the HPA controller (and KEDA as well) can correctly drive the scaling. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784180717



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       > That indicates fields are mandatory in the CRD, but the corresponding fields in the custom resources are not. If that interpretation is correct, an error on GET'ing the /scale sub resource does not necessary imply the absence of the /scale sub resource, it can also imply the field defined by specReplicasPath in the custom resource is not set.
   
   I missed this paragraph before. I mean that those fields need to point to an actual fields that actually returns and sets a correct number of replicas. So the HPA controller (and KEDA as well) can correctly drive the scaling by modifing and quering the replica count via `/scale` subresource.
   
   Or am I missing anything?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784187074



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Let's use our Integration example. The `specReplicasPath` is set in the CRD:
   
   https://github.com/apache/camel-k/blob/e9553940554ea533aaae2d0074681f37b434e7aa/config/crd/bases/camel.apache.org_integrations.yaml#L5631-L5635
   
   But the corresponding `.spec.replicas` field in the Integration resource is not set by default.
   
   According to the documentation:
   
   > If there is no value under the specReplicasPath in the custom resource, the /scale subresource will return an error on GET.
   
   The following command fails:
   
   ```console
   $ kubectl get --raw /apis/camel.apache.org/v1/namespaces/test/integrations/my-integration/scale | jq
   {
     "kind": "Status",
     "apiVersion": "v1",
     "metadata": {},
     "status": "Failure",
     "message": "Internal error occurred: the spec replicas field \".spec.replicas\" does not exist",
     "reason": "InternalError",
     "details": {
       "causes": [
         {
           "message": "the spec replicas field \".spec.replicas\" does not exist"
         }
       ]
     },
     "code": 500
   }
   ```
   
   Still the resource has a _scale_ sub-resource and is scalable. It can be scaled, for example with `kubectl scale`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti edited a comment on pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti edited a comment on pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#issuecomment-998806851


   I forgot to mention that it seems you've also fixed #1616 in the process, maybe partially though?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773331872



##########
File path: pkg/client/serverside.go
##########
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package client
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"strings"
+	"sync"
+	"sync/atomic"
+
+	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util/patch"
+	"github.com/pkg/errors"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/types"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type ServerOrClientSideApplier struct {
+	Client             ctrl.Client
+	hasServerSideApply atomic.Value
+	tryServerSideApply sync.Once
+}
+
+func (c *defaultClient) ServerOrClientSideApplier() ServerOrClientSideApplier {
+	return ServerOrClientSideApplier{
+		Client: c,
+	}
+}
+
+func (a *ServerOrClientSideApplier) Apply(ctx context.Context, object ctrl.Object) error {
+	once := false
+	var err error
+	// nolint: ifshort
+	needsRetry := false
+	a.tryServerSideApply.Do(func() {
+		once = true
+		if err = a.serverSideApply(ctx, object); err != nil {
+			if isIncompatibleServerError(err) {
+				log.Info("Fallback to client-side apply for installing resources")
+				a.hasServerSideApply.Store(false)
+				err = nil
+			} else {
+				needsRetry = true

Review comment:
       So, the reset was actually replacing the object holding the critical section state with another one (same memory location, different data). When that happened, the finalizer at the exit of the critical section found an inconsistent state and went into panic. Moving it out fixes the issue (even if I'm not sure if it's 100% safe in case of highly concurrent calls)...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784212386



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Right, here is what I'm observing:
   - It is possible to define a CRD with a scale sub-resource, and have instances of that CRD, i.e. custom resources of that CRD, created without values for the corresponding `specReplicasPath` CRD field, e.g. `.spec.replicas`. The API server allows it, and the documentation indicates this is allowed.
   - In that case a GET request to the resource `/scale` endpoint returns 500 with the message `the spec replicas field \".spec.replicas\" does not exist`
   - On the other hand, for a custom resource whose CRD does not define a scale sub-resource, a GET request to the resource `/scale` endpoint returns 404.
   
   In both cases, I find the result sensible:
   - 500 means, the sub-resource exists, and the custom resource is scalable, but the server just cannot determine the current scale value, because it is not set
   - 404 means, the `/scale` resource is not found, the resource is not scalable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784173838



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       How is `specReplicasPath` and `statusReplicasPath` defined in the CRD? In KEDA we are using standra go-client call to check the `/scale` subresource, so I'd like to avoid some hacks that might cause problems with some other CustomResources that we would like to check for scalability.
   Bear in mind that `/scale` subresource is being queried by HPA to drive the scaling, so if it is not correctly defined, then it won't work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r777940971



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       I'm realising setting it in the CRD may not generalise well for Knative, as it'll deactivate autoscaling OOTB. Also it may not really be relevant for CronJob in its current form.
   
   Thinking about the Knative case, I would find it a bit confusing to have a replicas spec set, but an actual replicas status to never eventually converge towards the spec, given the autoscaling. That actually applies to Keda as well. It seems they make the assumption that the replicas spec must be set, for the sole purpose of checking the existence of the `scale` sub-resource.
   
   As a user, I'd be inclined to expect that, when I set the replicas spec, the replicas status eventually converges towards the spec. If that's just me 😃, we can remove the logic that forces that behaviour for Knative, so that it's consistent across auto-scalers. I also wonder how HPA handles this case...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#issuecomment-1010027270


   I think there's something wrong in the new applier. Maybe we can fix it in another PR, wdyt @astefanutti ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784223681



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah, that might be true. But how do we get the current replicas then, if quering `/scale` results in 500 (ie. not set replica count)? Is it 0, 1, 2, 3,...?
   
   Later in the code, KEDA queries this endpoint to find out what is the current state and whether it should modify the replica count. This wouldn't work then.
   
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L64
   ->
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L255
   
   That code linked by your above, is just fail-fast check to find out whether we should proceed in reconciling the resource.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r783918150



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah, that's my understanding as well.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784223681



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah, that might be true. But how do we get the current replicas then, if quering `/scale` results in 500 (ie. not set replica count)?
   
   Later in the code, KEDA queries this endpoint to find out what is the current state and whether it should modify the replica count. This wouldn't work then.
   
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L64
   ->
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L255




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784173838



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       How is `specReplicasPath` and `statusReplicasPath` defined in the CRD? In KEDA we are using standra go-client call to check the `scale` subresource, so I'd like to avoid some hacks that might cause problems with some other resources.
   Bear in mind that `/scale` subresource is being queried by HPA to drive the scaling, so if it is not correctly defined, then it won't work.
   If you think that the CRD is correct and problem is in `client-go` we should try to fix it over there.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784185989



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       `.spec.replicas` and `.status.replicas` exist and are correctly set as well?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784242127



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       > If we don't know the number of replicas in the moment when we create the ScaledObject, we don't know the value that should be used to restore the replicas count, once ScaledObject is deleted.
   
   For that case, it was not set, so it could be unset. It may be a dubious parallel, but it's like a pointer in Golang, when it's needed to differentiate between the default value for the type, and not initialised.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r777940971



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       I'm realising setting it in the CRD may not generalise well for Knative, as it'll deactivate autoscaling. Also it may not really be relevant for CronJob in its current form.
   
   Thinking about the Knative case, I would find it a bit confusing to have a replicas spec set, but an actual replicas status to never eventually converge towards the spec, given the autoscaling. That actually applies to Keda as well. It seems they make the assumption that the replicas spec must be set, for the sole purpose of checking the existence of the `scale` sub-resource.
   
   As a user, I'd be inclined to expect that, when I set the replicas spec, the replicas status eventually converges towards the spec. If that's just me 😃, we can remove the logic that forces that behaviour for Knative, so that it's consistent across auto-scalers. I also wonder how HPA handles this case...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773333488



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       I need to investigate.. yeah I called it "hack" because it smells :)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#issuecomment-998976721


   > I forgot to mention that it seems you've also fixed #1616 in the process, maybe partially though?
   
   Yes, iirc those cases should be covered. I'll add some other tests to verify.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r783859878



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Thanks a lot for the feedback. I'm not sure I read this correctly, but my interpretation of that documentation is that `specReplicasPath` is mandatory in the CustomResourceDefinition, but the field specified by the `specReplicasPath` in the custom resource is not, in which case the `/scale` subresource returns an error on GET.
   
   Similarly, `statusReplicasPath` is mandatory, but the field that's pointed in the custom resource is not, in which case the status replica value in the `/scale` subresource defaults to 0.
   
   That indicates fields are mandatory in the CRD, but the corresponding fields in the custom resources are not. If that interpretation is correct, an error on GET'ing the `/scale` sub resource does not necessary imply the absence of the `/scale` sub resource, it can also implies the field defined by `specReplicasPath` in the custom resource is not set.
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784182912



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       They are defined with:
   https://github.com/apache/camel-k/blob/e9553940554ea533aaae2d0074681f37b434e7aa/config/crd/bases/camel.apache.org_integrations.yaml#L5631-L5635
   
   My understanding is that the detection logic in `checkTargetResourceIsScalable` could be updated to handle the 500 code case with message "the spec replicas field \".spec.replicas\" does not exist", because the resource is scalable in that case:
   
   https://github.com/kedacore/keda/blob/9ac7a0a28e446335376ef8f5e82494cf05456ecb/controllers/keda/scaledobject_controller.go#L293




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784212386



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Right, here is what I'm observing:
   - It is possible to define a CRD with a scale sub-resource, and have instances of that CRD, i.e. custom resources of that CRD, created without values for the corresponding `specReplicasPath` CRD field, e.g. `.spec.replicas`. The API server allows it, and the documentation indicates this is allowed.
   - In that case a GET request to the resource `/scale` endpoint returns 500 with the message `the spec replicas field \".spec.replicas\" does not exist"
   - On the other hand, for a custom resource whose CRD does not define a scale sub-resource, a GET request to the resource `/scale` endpoint returns 404.
   
   In both cases, I find the result sensible:
   - 500 means, the sub-resource exists, and the custom resource is scalable, but the server just cannot determine the current scale value, because it is not set
   - 404 means, the `/scale` resource is not found, the resource is not scalable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784242127



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       > If we don't know the number of replicas in the moment when we create the ScaledObject, we don't know the value that should be used to restore the replicas count, once ScaledObject is deleted.
   For that case, it was not set, so it could be unset. It may be a dubious parallel, but it's like a pointer in Golang, when it's needed to differentiate between the default value for the type, and not initialised.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] lburgazzoli commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
lburgazzoli commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r777928668



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       +1 to make the value explicit




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r783336961



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah, the field is mandatory as per: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#scale-subresource




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r777748132



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       No, the `.status.replicas` field is not considered. Here's a test I ran with a fully deployed klb (with Keda trait disabled).
   
   ```
   $ kubectl get klb sqs-to-telegram -o "jsonpath={.status.replicas}"
   1
   
   $ curl --silent http://localhost:8088/apis/camel.apache.org/v1alpha1/namespaces/test/kameletbindings/sqs-to-telegram/scale | jq
   {
     "kind": "Status",
     "apiVersion": "v1",
     "metadata": {},
     "status": "Failure",
     "message": "Internal error occurred: the spec replicas field \".spec.replicas\" does not exist",
     "reason": "InternalError",
     "details": {
       "causes": [
         {
           "message": "the spec replicas field \".spec.replicas\" does not exist"
         }
       ]
     },
     "code": 500
   }
   ```
   
   So the error comes from the API server.
   Then, if I set the `.spec.replicas` everything goes well:
   
   ```
   $ kubectl get klb sqs-to-telegram -o "jsonpath={.spec.replicas}"
   
   
   $ kubectl scale klb sqs-to-telegram --replicas 1
   kameletbinding.camel.apache.org/sqs-to-telegram scaled
   
   
   $ kubectl get klb sqs-to-telegram -o "jsonpath={.spec.replicas}"
   1
   
   $ curl --silent http://localhost:8088/apis/camel.apache.org/v1alpha1/namespaces/test/kameletbindings/sqs-to-telegram/scale | jq
   {
     "kind": "Scale",
     "apiVersion": "autoscaling/v1",
     "metadata": {
       "name": "sqs-to-telegram",
       "namespace": "test",
       "uid": "0b93916c-72f1-47ae-b2d1-74f9e3f7e5b6",
       "resourceVersion": "512151",
       "creationTimestamp": "2022-01-03T22:56:18Z"
     },
     "spec": {
       "replicas": 1
     },
     "status": {
       "replicas": 1,
       "selector": "camel.apache.org/integration=sqs-to-telegram"
     }
   }
   ```
   
   May it be my version of Kube... it's not latest, but it's a recent one:
   
   ```
   $ kubectl version
   Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
   Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:39:34Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784236085



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah this might be seen as obvious approach, but unfortunately it doesn't work this way. There are certain states where we need to compare the actual number of replicas to multiple values in ScaledObject and act based on the result. It is not just assignig one value as a replica count.
   
   I mean, everything could be done, right? :) So maybe if we refactor to code a lot it could be done, but I am not 100% sure about this. It would definitely make the code less logical.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784249008



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       > Right, sorry to drag you on this. I'm totally OK with KEDA mandating the `.spec.replicas` field to be set. I'm still trying to understand what's the best decision on this in the general case.
   
   Yeah, no worries :) It is always great to discuss stuff, it gives you another perspective.
   
   > For that case, it was not set, so it could be unset. It may be a dubious parallel, but it's like a pointer in Golang, when it's needed to differentiate between the default value for the type, and not initialised.
   
   But behind those numbers (pointers), there are actuall replicas of a workload that needs to be set. I am not sure what unset means in this case :)
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#issuecomment-998806851


   I forgot to mention that it seems you've also fix #1616 in the process, maybe partially though?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773729551



##########
File path: pkg/client/apply.go
##########
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package client
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"strings"
+	"sync"
+	"sync/atomic"
+
+	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util/patch"
+	"github.com/pkg/errors"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/types"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type ServerOrClientSideApplier struct {
+	Client             ctrl.Client
+	hasServerSideApply atomic.Value
+	tryServerSideApply sync.Once
+}
+
+func (c *defaultClient) ServerOrClientSideApplier() ServerOrClientSideApplier {
+	return ServerOrClientSideApplier{
+		Client: c,
+	}
+}
+
+func (a *ServerOrClientSideApplier) Apply(ctx context.Context, object ctrl.Object) error {
+	once := false
+	var err error
+	// nolint: ifshort
+	needsRetry := false
+	a.tryServerSideApply.Do(func() {
+		once = true
+		if err = a.serverSideApply(ctx, object); err != nil {
+			if isIncompatibleServerError(err) {
+				log.Info("Fallback to client-side apply for installing resources")
+				a.hasServerSideApply.Store(false)
+				err = nil
+			} else {
+				needsRetry = true
+			}
+		} else {
+			a.hasServerSideApply.Store(true)
+		}
+	})
+	if needsRetry {
+		a.tryServerSideApply = sync.Once{}

Review comment:
       Could that be done in the `if` statement below, and simply rely on the `err` variable instead of introducing another one?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784187074



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Let's use our Integration example. The `specReplicasPath` is set in the CRD:
   
   https://github.com/apache/camel-k/blob/e9553940554ea533aaae2d0074681f37b434e7aa/config/crd/bases/camel.apache.org_integrations.yaml#L5631-L5635
   
   But the `.spec.replicas` in the Integration resource is not set by default.
   
   According to the documentation:
   
   > If there is no value under the specReplicasPath in the custom resource, the /scale subresource will return an error on GET.
   
   The following command fails:
   
   ```console
   $ kubectl  --raw /apis/camel.apache.org/v1/namespaces/test/integrations/my-integration/scale | jq
   {
     "kind": "Status",
     "apiVersion": "v1",
     "metadata": {},
     "status": "Failure",
     "message": "Internal error occurred: the spec replicas field \".spec.replicas\" does not exist",
     "reason": "InternalError",
     "details": {
       "causes": [
         {
           "message": "the spec replicas field \".spec.replicas\" does not exist"
         }
       ]
     },
     "code": 500
   }
   ```
   
   Still the resource has a _scale_ sub-resource and is scalable. It can be scaled, for example with `kubectl scale`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784185989



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       `.spec.replicas` and `.status.replicas ` exist and are correctly set as well?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773332929



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.

Review comment:
       Right, maybe we can simply remove the restriction in the CLI for second-level config and get rid of this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773461134



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Turns out that the error is thrown by Kube: error 500 when KEDA tries to get the scale subresource: https://github.com/kedacore/keda/blob/9ac7a0a28e446335376ef8f5e82494cf05456ecb/controllers/keda/scaledobject_controller.go#L293.
   
   I've already seen this in the past...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784238705



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Okay, I thought about it more and it cannot be done, there are certain KEDA features that won't work. For example there's an optional setting to reset replica count back to original number, once ScaledObject is deleted. If we don't know the number of replicas in the moment when we create the ScaledObject, we don't know the value that should be used to restore the replicas count, once ScaledObject is deleted. 
   And there definitely other things, that would be broken.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784239420



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Right, sorry to drag you on this. I'm totally OK with KEDA mandating the `.spec.replicas` field to be set. I'm still trying to understand what's the best decision on this in the general case. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r783859878



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Thanks a lot for the feedback. I'm not sure I read this correctly, but my interpretation of that documentation is that `specReplicasPath` is mandatory in the CustomResourceDefinition, but the field specified by the `specReplicasPath` in the custom resource is not, in which case the `/scale` subresource returns an error on GET.
   
   Similarly, `statusReplicasPath` is mandatory, but the field that's pointed in the custom resource is not, in which case the status replica value in the `/scale` subresource defaults to 0.
   
   That indicates fields are mandatory in the CRD, but the corresponding fields in the custom resources are not. If that interpretation is correct, an error on GET'ing the `/scale` sub resource does not necessary implies the absence of the `/scale` sub resource, it can also implies the field defined by `specReplicasPath` in the custom resource is not set.
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#issuecomment-1010048444


   @nicolaferraro sure, we can figure it out later. I was about to suggest you exactly that also for the point about the scale sub-resource detection.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784173838



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       How is `specReplicasPath` and `statusReplicasPath` defined in the CRD? In KEDA we are using standra go-client call to check the `scale` subresource, so I'd like to avoid some hacks that might cause problems with some other resources.
   Bear in mind that `/scale` subresource is being queried by HPA to drive the scaling, so if it is not correctly defined, then it won't work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784173838



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       How is `specReplicasPath` and `statusReplicasPath` defined in the CRD? In KEDA we are using standra go-client call to check the `/scale` subresource, so I'd like to avoid some hacks that might cause problems with some other resources.
   Bear in mind that `/scale` subresource is being queried by HPA to drive the scaling, so if it is not correctly defined, then it won't work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773726233



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Would it be possible that the Integration hasn't been reconciled yet and the `.status.replicas` field hasn't been set when the Keda controller reconciles the ScaledObject? If that is the case, maybe we could have it set by default earlier, either when the Integration is created, or even possibly defaulted in the CRD?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773124441



##########
File path: pkg/client/serverside.go
##########
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package client
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"strings"
+	"sync"
+	"sync/atomic"
+
+	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util/patch"
+	"github.com/pkg/errors"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/types"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type ServerOrClientSideApplier struct {

Review comment:
       nit: I'd suggest to rename the file to `apply.go` as it's not restricted to server-side (even if it's the intent).

##########
File path: pkg/client/serverside.go
##########
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package client
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"strings"
+	"sync"
+	"sync/atomic"
+
+	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util/patch"
+	"github.com/pkg/errors"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/types"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type ServerOrClientSideApplier struct {
+	Client             ctrl.Client
+	hasServerSideApply atomic.Value
+	tryServerSideApply sync.Once
+}
+
+func (c *defaultClient) ServerOrClientSideApplier() ServerOrClientSideApplier {
+	return ServerOrClientSideApplier{
+		Client: c,
+	}
+}
+
+func (a *ServerOrClientSideApplier) Apply(ctx context.Context, object ctrl.Object) error {
+	once := false
+	var err error
+	// nolint: ifshort
+	needsRetry := false
+	a.tryServerSideApply.Do(func() {
+		once = true
+		if err = a.serverSideApply(ctx, object); err != nil {
+			if isIncompatibleServerError(err) {
+				log.Info("Fallback to client-side apply for installing resources")
+				a.hasServerSideApply.Store(false)
+				err = nil
+			} else {
+				needsRetry = true

Review comment:
       Out of curiosity, what is the reason behind moving the reset out of the critical section?

##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.

Review comment:
       Are they really kebab-cased? It's true for top-level keys, but the hierarchical ones are unstructured and arbitrary?

##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       I'm sure you've come to the conclusion it's necessary, but that smells for an outside reader. My understand from the Keda documentation is that the only requirement for custom resources to be Keda-scalable is to declare a `scale` sub-resource. Also, the path to the replicas spec is variable, and abstracted by the `scale` sub-resource. Does that mean Keda access the replicas spec directly, rather than via the `scale` endpoint?   

##########
File path: pkg/client/serverside.go
##########
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package client
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"strings"
+	"sync"
+	"sync/atomic"
+
+	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util/patch"
+	"github.com/pkg/errors"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/types"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type ServerOrClientSideApplier struct {
+	Client             ctrl.Client
+	hasServerSideApply atomic.Value
+	tryServerSideApply sync.Once
+}
+
+func (c *defaultClient) ServerOrClientSideApplier() ServerOrClientSideApplier {

Review comment:
       Maybe it could also be used in the _deployer_ trait while we are at it?

##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.
+	HackControllerReplicas *bool `property:"hack-controller-replicas" json:"hackControllerReplicas,omitempty"`
+	// Interval (seconds) to check each trigger on (minimum 10 seconds).
+	PollingInterval *int32 `property:"polling-interval" json:"pollingInterval,omitempty"`
+	// The wait period between the last active trigger reported and scaling the resource back to 0.
+	CooldownPeriod *int32 `property:"cooldown-period" json:"cooldownPeriod,omitempty"`
+	// Enabling this property allows KEDA to scale the resource down to the specified number of replicas.
+	IdleReplicaCount *int32 `property:"idle-replica-count" json:"idleReplicaCount,omitempty"`
+	// Minimum number of replicas.
+	MinReplicaCount *int32 `property:"min-replica-count" json:"minReplicaCount,omitempty"`
+	// Maximum number of replicas.
+	MaxReplicaCount *int32 `property:"max-replica-count" json:"maxReplicaCount,omitempty"`
+	// Definition of triggers according to the KEDA format. Each trigger must contain `type` field corresponding
+	// to the name of a KEDA autoscaler and a key/value map named `metadata` containing specific trigger options.
+	// An optional `authentication-secret` can be declared per trigger and the operator will link each entry of
+	// the secret to a KEDA authentication parameter.
+	Triggers []kedaTrigger `property:"triggers" json:"triggers,omitempty"`
+}
+
+type kedaTrigger struct {
+	Type                 string            `property:"type" json:"type,omitempty"`
+	Metadata             map[string]string `property:"metadata" json:"metadata,omitempty"`
+	AuthenticationSecret string            `property:"authentication-secret" json:"authenticationSecret,omitempty"`
+	authentication       map[string]string
+}
+
+// NewKedaTrait --.
+func NewKedaTrait() trait.Trait {
+	return &kedaTrait{
+		BaseTrait: trait.NewBaseTrait("keda", trait.TraitOrderPostProcessResources),
+	}
+}
+
+func (t *kedaTrait) Configure(e *trait.Environment) (bool, error) {
+	if t.Enabled == nil || !*t.Enabled {
+		return false, nil
+	}
+
+	if !e.IntegrationInPhase(camelv1.IntegrationPhaseInitialization) && !e.IntegrationInRunningPhases() {
+		return false, nil
+	}
+
+	if t.Auto == nil || *t.Auto {
+		if err := t.populateTriggersFromKamelets(e); err != nil {
+			return false, err
+		}
+	}
+
+	return len(t.Triggers) > 0, nil
+}
+
+func (t *kedaTrait) Apply(e *trait.Environment) error {
+	if e.IntegrationInPhase(camelv1.IntegrationPhaseInitialization) {
+		if t.HackControllerReplicas == nil || *t.HackControllerReplicas {
+			if err := t.hackControllerReplicas(e); err != nil {
+				return err
+			}
+		}
+	} else if e.IntegrationInRunningPhases() {
+		if err := t.addScalingResources(e); err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
+func (t *kedaTrait) addScalingResources(e *trait.Environment) error {
+	if len(t.Triggers) == 0 {
+		return nil
+	}
+
+	obj := kedav1alpha1.NewScaledObject(e.Integration.Namespace, e.Integration.Name)
+	obj.Spec.ScaleTargetRef = t.getTopControllerReference(e)
+	if t.PollingInterval != nil {
+		obj.Spec.PollingInterval = t.PollingInterval
+	}
+	if t.CooldownPeriod != nil {
+		obj.Spec.CooldownPeriod = t.CooldownPeriod
+	}
+	if t.IdleReplicaCount != nil {
+		obj.Spec.IdleReplicaCount = t.IdleReplicaCount
+	}
+	if t.MinReplicaCount != nil {
+		obj.Spec.MinReplicaCount = t.MinReplicaCount
+	}
+	if t.MaxReplicaCount != nil {
+		obj.Spec.MaxReplicaCount = t.MaxReplicaCount
+	}
+	for idx, trigger := range t.Triggers {
+		meta := make(map[string]string)
+		for k, v := range trigger.Metadata {
+			kk := k
+			if t.CamelCaseConversion != nil && *t.CamelCaseConversion {
+				kk = scase.LowerCamelCase(k)
+			}
+			meta[kk] = v
+		}
+		var authenticationRef *kedav1alpha1.ScaledObjectAuthRef
+		if len(trigger.authentication) > 0 && trigger.AuthenticationSecret != "" {
+			return errors.New("an authentication secret cannot be provided for auto-configured triggers")
+		}
+		extConfigName := fmt.Sprintf("%s-keda-%d", e.Integration.Name, idx)
+		if len(trigger.authentication) > 0 {
+			// Save all authentication config in a secret
+			secret := v1.Secret{
+				TypeMeta: metav1.TypeMeta{
+					Kind:       "Secret",
+					APIVersion: v1.SchemeGroupVersion.String(),
+				},
+				ObjectMeta: metav1.ObjectMeta{
+					Namespace: e.Integration.Namespace,
+					Name:      extConfigName,
+				},
+				StringData: trigger.authentication,
+			}
+			e.Resources.Add(&secret)
+
+			// Link the secret using a TriggerAuthentication
+			triggerAuth := kedav1alpha1.TriggerAuthentication{
+				TypeMeta: metav1.TypeMeta{
+					Kind:       "TriggerAuthentication",
+					APIVersion: kedav1alpha1.SchemeGroupVersion.String(),
+				},
+				ObjectMeta: metav1.ObjectMeta{
+					Namespace: e.Integration.Namespace,
+					Name:      extConfigName,
+				},
+			}
+			for _, k := range util.SortedStringMapKeys(trigger.authentication) {
+				triggerAuth.Spec.SecretTargetRef = append(triggerAuth.Spec.SecretTargetRef, kedav1alpha1.AuthSecretTargetRef{
+					Parameter: k,
+					Name:      extConfigName,
+					Key:       k,
+				})
+			}
+			e.Resources.Add(&triggerAuth)
+			authenticationRef = &kedav1alpha1.ScaledObjectAuthRef{
+				Name: extConfigName,
+			}
+		} else if trigger.AuthenticationSecret != "" {
+			s := v1.Secret{}
+			key := ctrl.ObjectKey{
+				Namespace: e.Integration.Namespace,
+				Name:      trigger.AuthenticationSecret,
+			}
+			if err := e.Client.Get(e.Ctx, key, &s); err != nil {
+				return errors.Wrapf(err, "could not load secret named %q in namespace %q", trigger.AuthenticationSecret, e.Integration.Namespace)
+			}
+			// Fill a TriggerAuthentication from the secret
+			triggerAuth := kedav1alpha1.TriggerAuthentication{
+				TypeMeta: metav1.TypeMeta{
+					Kind:       "TriggerAuthentication",
+					APIVersion: kedav1alpha1.SchemeGroupVersion.String(),
+				},
+				ObjectMeta: metav1.ObjectMeta{
+					Namespace: e.Integration.Namespace,
+					Name:      extConfigName,
+				},
+			}
+			sortedKeys := make([]string, 0, len(s.Data))
+			for k := range s.Data {
+				sortedKeys = append(sortedKeys, k)
+			}
+			sort.Strings(sortedKeys)
+			for _, k := range sortedKeys {
+				triggerAuth.Spec.SecretTargetRef = append(triggerAuth.Spec.SecretTargetRef, kedav1alpha1.AuthSecretTargetRef{
+					Parameter: k,
+					Name:      s.Name,
+					Key:       k,
+				})
+			}
+			e.Resources.Add(&triggerAuth)
+			authenticationRef = &kedav1alpha1.ScaledObjectAuthRef{
+				Name: extConfigName,
+			}
+		}
+
+		st := kedav1alpha1.ScaleTriggers{
+			Type:              trigger.Type,
+			Metadata:          meta,
+			AuthenticationRef: authenticationRef,
+		}
+		obj.Spec.Triggers = append(obj.Spec.Triggers, st)
+	}
+	e.Resources.Add(&obj)
+	return nil
+}
+
+func (t *kedaTrait) hackControllerReplicas(e *trait.Environment) error {
+	ctrlRef := t.getTopControllerReference(e)
+	if ctrlRef.Kind == camelv1alpha1.KameletBindingKind {
+		// Update the KameletBinding directly (do not add it to env resources, it's the integration parent)
+		key := ctrl.ObjectKey{
+			Namespace: e.Integration.Namespace,
+			Name:      ctrlRef.Name,
+		}
+		klb := camelv1alpha1.KameletBinding{}
+		if err := e.Client.Get(e.Ctx, key, &klb); err != nil {
+			return err
+		}
+		if klb.Spec.Replicas == nil {
+			one := int32(1)
+			klb.Spec.Replicas = &one
+			if err := e.Client.Update(e.Ctx, &klb); err != nil {
+				return err
+			}
+		}
+	} else if e.Integration.Spec.Replicas == nil {
+		one := int32(1)
+		e.Integration.Spec.Replicas = &one
+		// Update the Integration directly as the spec section is not merged by default

Review comment:
       nit: Maybe patching the `scale` endpoint could be used instead, rather than updating the whole resource:
   
   https://github.com/apache/camel-k/blob/fef775de02b3a59b9c844ba8bf9c418bf8a708b7/e2e/common/scale_integration_test.go#L79




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] nicolaferraro merged pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
nicolaferraro merged pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784187074



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Let's use our Integration example. The `specReplicasPath` is set in the CRD:
   
   https://github.com/apache/camel-k/blob/e9553940554ea533aaae2d0074681f37b434e7aa/config/crd/bases/camel.apache.org_integrations.yaml#L5631-L5635
   
   But the `.spec.replicas` in the Integration resource is not set by default.
   
   According to the documentation:
   
   > If there is no value under the specReplicasPath in the custom resource, the /scale subresource will return an error on GET.
   
   The following command fails:
   
   ```console
   $ kubectl get --raw /apis/camel.apache.org/v1/namespaces/test/integrations/my-integration/scale | jq
   {
     "kind": "Status",
     "apiVersion": "v1",
     "metadata": {},
     "status": "Failure",
     "message": "Internal error occurred: the spec replicas field \".spec.replicas\" does not exist",
     "reason": "InternalError",
     "details": {
       "causes": [
         {
           "message": "the spec replicas field \".spec.replicas\" does not exist"
         }
       ]
     },
     "code": 500
   }
   ```
   
   Still the resource has a _scale_ sub-resource and is scalable. It can be scaled, for example with `kubectl scale`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784203554



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       OK, gotcha. 
   
   But I still think that the real problem is here:
   > But the .spec.replicas in the Integration resource is not set by default.
   
   Doing a workaround on KEDA side or anywhere else is just hacking imho.
   
   Let's forget Camel-K CRDs for now, what if some CRD doesn't define `spec.replica` field correctly, but still for some reason has `/scale` subresource. How would we then check that the resource is scalable? How are we going to distinguish it from "just not initialized" field?
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784079215



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       If we follow that reasoning, would the ideal solution be that Keda amends it's _scale_ sub-resource detection logic, to better handle the case where GET'ing the `/scale` endpoint errors because the field defined by `specReplicasPath` has no value, and not because the resource does not have the _scale_ sub-resource defined in its CRD?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] astefanutti commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
astefanutti commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784212386



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Right, here is what I'm observing:
   - It is possible to define a CRD with a scale sub-resource, and have instances of that CRD, i.e. custom resources of that CRD, created without values for the corresponding `specReplicasPath` CRD field, e.g. `.spec.replicas`. The API server allows it, and the documentation indicates this is allowed.
   - In that case a GET request to the resource `/scale` endpoint returns 500 with the message `the spec replicas field \".spec.replicas\" does not exist`
   - On the other hand, for a custom resource whose CRD does not define a scale sub-resource, a GET request to the resource `/scale` endpoint returns 404.
   
   In both cases, I find the result sensible:
   - 500 means, the `/scale` sub-resource exists, and the custom resource is scalable, but the server just cannot determine the current scale value, because it is not set
   - 404 means, the `/scale` sub-resource is not found, the resource is not scalable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784223681



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah, that might be true. But how do we get the current replicas then, if quering `/scale` results in 500 (ie. not set replica count)? Is it 0, 1, 2, 3,...?
   
   Later in the code, KEDA queries this endpoint to find out what is the current state and whether it should modify the replica count. This wouldn't work then.
   
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L64
   ->
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L255
   
   That KEDA controller code linked by you above is just a fail-fast check, to find out whether we should proceed in reconciling the resource or not.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784223681



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Yeah, that might be true. But how do we get the current replicas then, if quering `/scale` results in 500 (ie. not set replica count)? Is it 0, 1, 2, 3,...?
   
   Later in the code, KEDA queries this endpoint to find out what is the current state and whether it should modify the replica count. This wouldn't work then.
   
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L64
   ->
   https://github.com/kedacore/keda/blob/53a81e9f12e9c1833b66e2e0e6fe514db1e9e47e/pkg/scaling/executor/scale_scaledobjects.go#L255




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-k] zroubalik commented on a change in pull request #2838: Add support for KEDA

Posted by GitBox <gi...@apache.org>.
zroubalik commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r784238705



##########
File path: addons/keda/keda.go
##########
@@ -0,0 +1,551 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package keda
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"sort"
+	"strings"
+	"text/template"
+
+	kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/apache/camel-k/pkg/kamelet/repository"
+	"github.com/apache/camel-k/pkg/metadata"
+	"github.com/apache/camel-k/pkg/platform"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/property"
+	"github.com/apache/camel-k/pkg/util/source"
+	"github.com/apache/camel-k/pkg/util/uri"
+	"github.com/pkg/errors"
+	scase "github.com/stoewer/go-strcase"
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+const (
+	// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
+	kameletURNMetadataPrefix = "urn:keda:metadata:"
+	// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
+	kameletURNAuthenticationPrefix = "urn:keda:authentication:"
+	// kameletURNRequiredTag is used to mark properties required by KEDA.
+	kameletURNRequiredTag = "urn:keda:required"
+
+	// kameletAnnotationType indicates the scaler type associated to a Kamelet.
+	kameletAnnotationType = "camel.apache.org/keda.type"
+	// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
+	kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
+	// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
+	kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
+)
+
+// The KEDA trait can be used for automatic integration with KEDA autoscalers.
+// The trait can be either manually configured using the `triggers` option or automatically configured
+// via markers in the Kamelets.
+//
+// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
+// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
+// If you want to create Kamelets that contain KEDA metadata, refer to
+// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
+//
+// The KEDA trait is disabled by default.
+//
+// +camel-k:trait=keda.
+type kedaTrait struct {
+	trait.BaseTrait `property:",squash"`
+	// Enables automatic configuration of the trait. Allows the trait to infer KEDA triggers from the Kamelets.
+	Auto *bool `property:"auto" json:"auto,omitempty"`
+	// Convert metadata properties to camelCase (needed because Camel K trait properties use kebab-case from command line). Disabled by default.
+	CamelCaseConversion *bool `property:"camel-case-conversion" json:"camelCaseConversion,omitempty"`
+	// Set the spec->replicas field on the top level controller to an explicit value if missing, to allow KEDA to recognize it as a scalable resource.

Review comment:
       Okay, I thought about it more and it cannot be done, there are certain KEDA features that won't work. For example there's setting to reset replica count back to original number, once ScaledObject is deleted. If we don't know the number of replicas in the moment when we create the ScaledObject, we don't know the value that we should use once ScaledObject is deleted. 
   And there definitely other things, that would be broken.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org