You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cl...@apache.org on 2023/03/29 12:56:13 UTC
[camel-k] branch main updated: Remove additional custom labels utility (#4184)
This is an automated email from the ASF dual-hosted git repository.
claudio4j pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 865ebdb57 Remove additional custom labels utility (#4184)
865ebdb57 is described below
commit 865ebdb57f1c6e6b44d7a1826ad876019f7a0bf3
Author: Claudio Miranda <cl...@claudius.com.br>
AuthorDate: Wed Mar 29 09:56:06 2023 -0300
Remove additional custom labels utility (#4184)
---
pkg/trait/cron.go | 5 +-
pkg/trait/deployment.go | 5 +-
pkg/trait/knative_service.go | 5 +-
pkg/util/label/label.go | 68 --------------------------
pkg/util/label/label_test.go | 113 -------------------------------------------
5 files changed, 9 insertions(+), 187 deletions(-)
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 7e0ffdd71..a5926c50a 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -33,7 +33,6 @@ import (
"github.com/apache/camel-k/v2/pkg/metadata"
"github.com/apache/camel-k/v2/pkg/util"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
- "github.com/apache/camel-k/v2/pkg/util/label"
"github.com/apache/camel-k/v2/pkg/util/uri"
)
@@ -260,7 +259,9 @@ func (t *cronTrait) getCronJobFor(e *Environment) *batchv1.CronJob {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
- Labels: label.AddLabels(e.Integration.Name),
+ Labels: map[string]string{
+ v1.IntegrationLabel: e.Integration.Name,
+ },
Annotations: annotations,
},
Spec: corev1.PodSpec{
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 229760680..3862043d2 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -29,7 +29,6 @@ import (
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
- "github.com/apache/camel-k/v2/pkg/util/label"
)
type deploymentTrait struct {
@@ -158,7 +157,9 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
- Labels: label.AddLabels(e.Integration.Name),
+ Labels: map[string]string{
+ v1.IntegrationLabel: e.Integration.Name,
+ },
Annotations: annotations,
},
Spec: corev1.PodSpec{
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index 9f9da95e3..88aab3c46 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -31,7 +31,6 @@ import (
traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
"github.com/apache/camel-k/v2/pkg/metadata"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
- "github.com/apache/camel-k/v2/pkg/util/label"
)
const (
@@ -262,7 +261,9 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e
ConfigurationSpec: serving.ConfigurationSpec{
Template: serving.RevisionTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
- Labels: label.AddLabels(e.Integration.Name),
+ Labels: map[string]string{
+ v1.IntegrationLabel: e.Integration.Name,
+ },
Annotations: revisionAnnotations,
},
Spec: serving.RevisionSpec{
diff --git a/pkg/util/label/label.go b/pkg/util/label/label.go
deleted file mode 100644
index 0a283c4ad..000000000
--- a/pkg/util/label/label.go
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
-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"
-
- v1 "github.com/apache/camel-k/v2/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 at runtime, just use the value as "token_integration_name"
-// example: myKey1=myValue1,myKey2=token_integration_name
-var AdditionalLabels = ""
-
-var FixedLabels = map[string]string{}
-
-// parses the labels early on and fail fast if there are errors.
-func init() {
- checkAdditionalLabels()
-}
-
-func checkAdditionalLabels() {
- if len(AdditionalLabels) > 0 {
- var err error
- FixedLabels, err = labels.ConvertSelectorToLabelsMap(AdditionalLabels)
- 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", AdditionalLabels, err))
- }
- }
-}
-
-// parses the AdditionalLabels variable and returns as map[string]string.
-func AddLabels(integration string) map[string]string {
- definitiveLabels := labels.Set{
- v1.IntegrationLabel: integration,
- }
- for k, v := range FixedLabels {
- if v == "token_integration_name" {
- definitiveLabels[k] = integration
- } else {
- definitiveLabels[k] = v
- }
- }
- return definitiveLabels
-}
diff --git a/pkg/util/label/label_test.go b/pkg/util/label/label_test.go
deleted file mode 100644
index e19b579ba..000000000
--- a/pkg/util/label/label_test.go
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
-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 (
- "testing"
-
- v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
- "github.com/stretchr/testify/assert"
-)
-
-func TestParseValidEntries(t *testing.T) {
- integration := "test1"
- AdditionalLabels = "k1=v1,k3/k3.k3=v3.v3,k4.k4=v4,k5/k5=v5"
- FixedLabels = map[string]string{}
- checkAdditionalLabels()
- labels := AddLabels(integration)
- expected := map[string]string{
- v1.IntegrationLabel: integration,
- "k1": "v1",
- "k3/k3.k3": "v3.v3",
- "k4.k4": "v4",
- "k5/k5": "v5",
- }
- assert.Equal(t, expected, labels)
-
- AdditionalLabels = "k1=v1"
- FixedLabels = map[string]string{}
- checkAdditionalLabels()
- labels = AddLabels(integration)
- expected = map[string]string{
- v1.IntegrationLabel: integration,
- "k1": "v1",
- }
- assert.Equal(t, expected, labels)
-}
-
-func TestParseEmptyAdditionalLabels(t *testing.T) {
- integration := "test1"
- AdditionalLabels = ""
- FixedLabels = map[string]string{}
- checkAdditionalLabels()
- labels := AddLabels(integration)
- expected := map[string]string{
- v1.IntegrationLabel: integration,
- }
- assert.Equal(t, expected, labels)
-}
-
-func TestParseInvalidEntry(t *testing.T) {
- integration := "test1"
- AdditionalLabels = "k1[=v1,k2)=v2,k@3=v3"
- FixedLabels = map[string]string{}
- assert.Panics(t, func() {
- checkAdditionalLabels()
- AddLabels(integration)
- })
-}
-
-func TestParseIntegrationPlaceholder(t *testing.T) {
- integration := "test1"
- AdditionalLabels = "k1=token_integration_name,k2=v2,k3=v3,k4.k4=v4,k5/k5=v5,rht.subcomp_t=my_subcomp"
- FixedLabels = map[string]string{}
- checkAdditionalLabels()
- labels := AddLabels(integration)
- expected := map[string]string{
- v1.IntegrationLabel: integration,
- "k1": integration,
- "k2": "v2",
- "k3": "v3",
- "k4.k4": "v4",
- "k5/k5": "v5",
- "rht.subcomp_t": "my_subcomp",
- }
- assert.Equal(t, expected, labels)
-
- AdditionalLabels = "k1=v1,k2=v2,k3=token_integration_name"
- FixedLabels = map[string]string{}
- checkAdditionalLabels()
- labels = AddLabels(integration)
- expected = map[string]string{
- v1.IntegrationLabel: integration,
- "k1": "v1",
- "k2": "v2",
- "k3": integration,
- }
- assert.Equal(t, expected, labels)
-
- AdditionalLabels = "k3=token_integration_name"
- FixedLabels = map[string]string{}
- checkAdditionalLabels()
- labels = AddLabels(integration)
- expected = map[string]string{
- v1.IntegrationLabel: integration,
- "k3": integration,
- }
- assert.Equal(t, expected, labels)
-}