astefanutti commented on a change in pull request #2646:
URL: https://github.com/apache/camel-k/pull/2646#discussion_r713292666



##########
File path: pkg/util/label/label.go
##########
@@ -0,0 +1,52 @@
+/*
+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 label
+
+import (
+       "fmt"
+       "strings"
+
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "k8s.io/apimachinery/pkg/labels"
+)
+
+// The AdditionalLabels is a big string consisting of key=value, set at build 
time
+// when set are to be added to Deployments, CronJob and KNativeService whose 
pods
+// should expose these labels
+
+// AdditionalLabels are labels=values, they MUST be set as key=value separated 
by comma ,
+// example: myKey1=myValue1,myKey2=myValue2
+// Also it supports replacing a value for the integration name, just put @ 
around it
+// example: myKey1=myValue1,myKey2=@integration@
+var AdditionalLabels = ""
+
+// parses the AdditionalLabels variable and returns as map[string]string
+func AddLabels(integration string) map[string]string {
+       strLabels := strings.ReplaceAll(AdditionalLabels, "@integration@", 
integration)
+       if len(AdditionalLabels) > 0 {
+               strLabels = fmt.Sprintf("%s=%s,%s", v1.IntegrationLabel, 
integration, strLabels)
+       } else {
+               strLabels = fmt.Sprintf("%s=%s", v1.IntegrationLabel, 
integration)
+       }
+       lbls, err := labels.ConvertSelectorToLabelsMap(strLabels)
+       if err != nil {
+               // as this should be used only in build time, it's ok to fail 
fast
+               panic(fmt.Sprintf("Error parsing AdditionalLabels %s, Error: 
%s\n", strLabels, err))

Review comment:
       Sorry I may nto have been clear, but I wasn't suggesting to panic here. 
The idea I suggested is to do the parsing in an init function to set a labels 
map variables, and panic if the parsing fails there. The parsing only needs to 
happen once, at start time, and it fails fast if the additional labels string 
isn't valid.

##########
File path: pkg/util/label/label.go
##########
@@ -0,0 +1,52 @@
+/*
+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 label
+
+import (
+       "fmt"
+       "strings"
+
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "k8s.io/apimachinery/pkg/labels"
+)
+
+// The AdditionalLabels is a big string consisting of key=value, set at build 
time
+// when set are to be added to Deployments, CronJob and KNativeService whose 
pods
+// should expose these labels
+
+// AdditionalLabels are labels=values, they MUST be set as key=value separated 
by comma ,
+// example: myKey1=myValue1,myKey2=myValue2
+// Also it supports replacing a value for the integration name, just put @ 
around it
+// example: myKey1=myValue1,myKey2=@integration@
+var AdditionalLabels = ""
+
+// parses the AdditionalLabels variable and returns as map[string]string
+func AddLabels(integration string) map[string]string {
+       strLabels := strings.ReplaceAll(AdditionalLabels, "@integration@", 
integration)
+       if len(AdditionalLabels) > 0 {
+               strLabels = fmt.Sprintf("%s=%s,%s", v1.IntegrationLabel, 
integration, strLabels)
+       } else {
+               strLabels = fmt.Sprintf("%s=%s", v1.IntegrationLabel, 
integration)
+       }
+       lbls, err := labels.ConvertSelectorToLabelsMap(strLabels)
+       if err != nil {
+               // as this should be used only in build time, it's ok to fail 
fast
+               panic(fmt.Sprintf("Error parsing AdditionalLabels %s, Error: 
%s\n", strLabels, err))

Review comment:
       Sorry I may not have been clear, but I wasn't suggesting to panic here. 
The idea I suggested is to do the parsing in an init function to set a labels 
map variables, and panic if the parsing fails there. The parsing only needs to 
happen once, at start time, and it fails fast if the additional labels string 
isn't valid.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to