astefanutti commented on a change in pull request #2646: URL: https://github.com/apache/camel-k/pull/2646#discussion_r711952252
########## File path: pkg/util/label/label.go ########## @@ -0,0 +1,60 @@ +/* +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 ( + "regexp" + "strings" + + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" + "github.com/apache/camel-k/pkg/util/property" +) + +// The AdditionalLabels is a map of string:string 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 semicolon ; +// 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 = "" + +var labelRegexp = regexp.MustCompile(`(([A-Za-z0-9_@.][-A-Za-z0-9_@.]){1,64}={1}([A-Za-z0-9_@.][-A-Za-z0-9_@.]){1,64}){1}`) + +// parses the AdditionalLabels variable and returns as map[string]string +func AddLabels(integration string) map[string]string { + labels := map[string]string{ + v1.IntegrationLabel: integration, + } + delim := ";" + line := strings.TrimSpace(AdditionalLabels) + if len(line) > 0 { + labelArr := strings.Split(line, delim) + for _, entry := range labelArr { + if strings.Count(entry, "=") == 1 && labelRegexp.MatchString(entry) { + k, v := property.SplitPropertyFileEntry(entry) + if v == "@integration@" { Review comment: Is that feature as strong requirement? There is already an hard-coded label that provides the name of the integration, so label selection can already be performed per integration. I'd rather keep that simple than introducing some form of language here. -- 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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org