You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/08/18 16:54:01 UTC

[camel-k] 01/01: fix: properly set annotations and labels to kamelets

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch 3473/allow-uninstall-kameletes
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 927e9fd0152e1e960c14d64edce6190b429bf67f
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Thu Aug 18 18:53:35 2022 +0200

    fix: properly set annotations and labels to kamelets
---
 pkg/install/kamelets.go                        | 19 +++++----
 pkg/install/kamelets_test.go                   | 39 +++++++++++++++++++
 pkg/install/testdata/timer-source.kamelet.yaml | 54 ++++++++++++++++++++++++++
 pkg/resources/resources.go                     | 16 ++++----
 4 files changed, 113 insertions(+), 15 deletions(-)

diff --git a/pkg/install/kamelets.go b/pkg/install/kamelets.go
index 5e877b928..10fb1cd54 100644
--- a/pkg/install/kamelets.go
+++ b/pkg/install/kamelets.go
@@ -187,16 +187,21 @@ func loadKamelet(path string, namespace string) (ctrl.Object, error) {
 
 	kamelet.SetNamespace(namespace)
 
-	if kamelet.GetAnnotations() == nil {
-		kamelet.SetAnnotations(make(map[string]string))
+	annotations := kamelet.GetAnnotations()
+	if annotations == nil {
+		annotations = make(map[string]string)
 	}
-	kamelet.GetAnnotations()[kamelVersionAnnotation] = defaults.Version
+	annotations[kamelVersionAnnotation] = defaults.Version
+	kamelet.SetAnnotations(annotations)
 
-	if kamelet.GetLabels() == nil {
-		kamelet.SetLabels(make(map[string]string))
+	labels := kamelet.GetLabels()
+	if labels == nil {
+		labels = make(map[string]string)
 	}
-	kamelet.GetLabels()[v1alpha1.KameletBundledLabel] = "true"
-	kamelet.GetLabels()[v1alpha1.KameletReadOnlyLabel] = "true"
+	labels[v1alpha1.KameletBundledLabel] = "true"
+	labels[v1alpha1.KameletReadOnlyLabel] = "true"
+
+	kamelet.SetLabels(labels)
 
 	return kamelet, nil
 }
diff --git a/pkg/install/kamelets_test.go b/pkg/install/kamelets_test.go
new file mode 100644
index 000000000..3a459e592
--- /dev/null
+++ b/pkg/install/kamelets_test.go
@@ -0,0 +1,39 @@
+/*
+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 install
+
+import (
+	"testing"
+
+	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestLoadKamelet(t *testing.T) {
+	kamelet, err := loadKamelet("testdata/timer-source.kamelet.yaml", "some-namespace")
+
+	assert.NotNil(t, kamelet)
+	assert.Nil(t, err)
+	assert.Equal(t, "timer-source", kamelet.GetName())
+	assert.Equal(t, "some-namespace", kamelet.GetNamespace())
+	assert.Equal(t, 3, len(kamelet.GetLabels()))
+	assert.Equal(t, "true", kamelet.GetLabels()[v1alpha1.KameletBundledLabel])
+	assert.Equal(t, "true", kamelet.GetLabels()[v1alpha1.KameletReadOnlyLabel])
+	assert.Equal(t, 2, len(kamelet.GetAnnotations()))
+	assert.NotNil(t, kamelet.GetAnnotations()[kamelVersionAnnotation])
+}
diff --git a/pkg/install/testdata/timer-source.kamelet.yaml b/pkg/install/testdata/timer-source.kamelet.yaml
new file mode 100644
index 000000000..64759fa34
--- /dev/null
+++ b/pkg/install/testdata/timer-source.kamelet.yaml
@@ -0,0 +1,54 @@
+# ---------------------------------------------------------------------------
+# 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: timer-source
+  annotations:
+    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gU3ZnIFZlY3RvciBJY29ucyA6IGh0dHA6Ly93d3cub25saW5ld2ViZm9udHMuY29tL2ljb24gLS0+DQo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm [...]
+  labels:
+    camel.apache.org/kamelet.type: "source"
+spec:
+  definition:
+    title: "Timer Source"
+    description: "Produces periodic events with a custom payload"
+    required:
+      - message
+    properties:
+      period:
+        title: Period
+        description: The interval between two events
+        type: integer
+        default: 1000
+      message:
+        title: Message
+        description: The message to generate
+        type: string
+        example: "hello world"
+  types:
+    out:
+      mediaType: text/plain
+  template:
+    from:
+      uri: timer:tick
+      parameters:
+        period: "{{period}}"
+      steps:
+      - set-body:
+          constant: "{{message}}"
+      - to: "kamelet:sink"
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index 44e677f71..807193a2e 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -138,23 +138,23 @@ var assets = func() http.FileSystem {
 		"/crd/bases/camel.apache.org_integrationplatforms.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_integrationplatforms.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 174371,
+			uncompressedSize: 177069,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\xdb\x36\xb6\x30\xfe\x7f\x3e\x05\xc6\xfd\x23\x4e\xc6\x92\x9b\xdd\xdb\xdd\x5e\xdf\xe9\x3c\x8f\xd7\x49\x5b\x37\x71\xec\x6b\x39\xb9\x77\xa7\xed\x54\x10\x79\x24\x21\x22\x01\x2e\x00\xca\x51\x7f\xfb\xfb\xee\xcf\xe0\x00\x20\x29\x89\x04\x29\xc9\x6f\x6d\xc4\xce\xec\xc6\x36\x01\x1e\x1c\x1c\x9c\x37\x9c\x97\xaf\x48\xef\xee\x9e\x67\x5f\x91\x77\x2c\x02\xae\x20\x26\x5a\x10\x3d\x05\x72\x9a\xd1\x68\x0a\x64\x20\xc6\xfa\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\xdb\x36\xb6\x30\x8e\xff\x9e\xbf\x02\xe3\xce\x9d\x38\x19\x4b\x4e\xba\xb7\xbb\xbd\x7e\xa6\xf3\x3c\xae\x93\xb6\x6e\xe2\xd8\xd7\x72\x72\xef\x4e\xdb\xa9\x20\xf2\x48\x42\x44\x02\x5c\x00\x94\xa3\x7e\xf7\xfb\xbf\x7f\x06\x07\x00\x49\x49\x24\x48\x49\x7e\x49\x1b\xb1\x33\xbb\xb1\x4d\x80\x07\x07\x07\xe7\x0d\xe7\xe5\x2b\xd2\xbb\xbb\xe7\xc9\x57\xe4\x2d\x8b\x80\x2b\x88\x89\x16\x44\x4f\x81\x9c\x66\x34\x9a\x02\x19\x88\x [...]
 		},
 		"/crd/bases/camel.apache.org_integrations.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_integrations.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 470929,
+			uncompressedSize: 472278,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x37\xf6\x28\xf8\xbf\x3f\x05\x4a\x49\x5d\x49\x13\x91\xb2\x33\x73\x53\xbf\xf1\x4e\xdd\x94\x46\x92\x13\x6d\x6c\x99\x65\x29\xc9\x4d\x39\x9e\x04\xec\x06\x49\x5c\x35\x81\x1e\x00\x4d\x89\xbf\xf5\x7e\xf7\x2d\x1c\x00\xfd\xe0\xab\x0f\x5a\xa2\xe3\xcc\x36\xa6\x6a\x62\x52\xec\xd3\x78\x1c\x9c\xf7\xe3\x0b\x32\x78\xba\xf1\xec\x0b\xf2\x9a\x27\x4c\x68\x96\x12\x23\x89\x99\x31\x72\x96\xd3\x64\xc6\xc8\x8d\x9c\x98\x7b\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x37\xf6\x28\xf8\xbf\x3f\x05\x4a\x49\x5d\x49\x13\x91\xb2\x33\x73\x53\xbf\xf1\x4e\xdd\x94\x46\x92\x13\x6d\x6c\x99\x65\x29\xc9\x4d\x39\x9e\x04\xec\x06\x49\x5c\x35\x81\x1e\x00\x4d\x89\xbf\xf5\x7e\xf7\x2d\x1c\x00\xfd\xe0\xab\x0f\x5a\xa2\xe3\xcc\x36\xa6\x6a\x62\x52\xec\xd3\x78\x1c\x9c\xf7\xe3\x0b\x32\x78\xba\xf1\xec\x0b\xf2\x9a\x27\x4c\x68\x96\x12\x23\x89\x99\x31\x72\x96\xd3\x64\xc6\xc8\x8d\x9c\x98\x7b\x [...]
 		},
 		"/crd/bases/camel.apache.org_kameletbindings.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_kameletbindings.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 543879,
+			uncompressedSize: 545316,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\x1b\x37\xb2\x2f\x8c\xff\xee\xbf\x02\x25\xa7\xae\xa4\x13\x92\xb2\xb3\xbb\xa9\xb3\xfe\x6e\xdd\x94\x56\x96\x13\x7d\x63\xcb\x2c\x4b\x71\x6e\xca\xc9\x49\xc0\x19\x90\xc4\xd5\x10\x98\x05\x30\x94\xb8\x8f\x9f\xff\xfd\x29\x34\x80\x79\xe1\x9b\xd0\x43\x51\x51\x36\x83\x53\x75\x36\x92\x35\x3d\x18\x00\xdd\xe8\xee\x4f\xbf\x3c\x27\xfd\x87\x1b\xcf\x9e\x93\xb7\x3c\x61\x42\xb3\x94\x18\x49\xcc\x94\x91\xd3\x9c\x26\x53\x46\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\x1b\x37\xb2\x2f\x8c\xff\xee\xbf\x02\x25\xa7\xae\xa4\x13\x92\xb2\xb3\xbb\xa9\xb3\xfe\x6e\xdd\x94\x56\x96\x13\x7d\x63\xcb\x2c\x4b\x71\x6e\xca\xc9\x49\xc0\x19\x90\xc4\xd5\x10\x98\x05\x30\x94\xb8\x8f\x9f\xff\xfd\x29\x34\x80\x79\xe1\x9b\xd0\x43\x51\x51\x36\x83\x53\x75\x36\x92\x35\x3d\x18\x00\xdd\xe8\xee\x4f\xbf\x3c\x27\xfd\x87\x1b\xcf\x9e\x93\xb7\x3c\x61\x42\xb3\x94\x18\x49\xcc\x94\x91\xd3\x9c\x26\x53\x46\x [...]
 		},
 		"/crd/bases/camel.apache.org_kamelets.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_kamelets.yaml",
@@ -604,9 +604,9 @@ var assets = func() http.FileSystem {
 		"/traits.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "traits.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 51862,
+			uncompressedSize: 52743,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfb\x73\x1b\xb9\xd1\xe0\xef\xfb\x57\xa0\x94\xab\xb2\xa4\x22\x29\xef\xe6\x4b\xb2\xa7\xbb\xfd\x72\x5a\xdb\x9b\x68\xd7\x0f\x9d\xa5\xdd\x7c\x29\x9f\x2b\x04\x67\x9a\x24\xcc\x21\x30\x01\x30\x92\x99\xcb\xfd\xef\x57\xe8\x6e\x3c\x86\x0f\x89\xb2\xad\xbd\xe8\xea\xcb\x56\xc5\x22\x39\x03\x34\x1a\xdd\x8d\x7e\xc3\x5b\xa9\xbc\x3b\xfd\x6a\x28\xb4\x5c\xc2\xa9\xf8\xad\xab\x64\x03\x5f\x09\xd1\x36\xd2\x4f\x8d\x5d\x9e\x8a\xa9\x6c\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\xff\x73\x1b\xb9\xb1\x20\xfe\xfb\xfe\x15\x28\xbd\xcf\x2b\x4b\x2e\x92\xf2\x6e\xde\xe6\xed\x47\x77\xfb\x72\x5a\xdb\x9b\x68\xd7\x5f\x74\x96\x77\xf3\x52\x3e\x57\x08\xce\x34\x49\x98\x43\x60\x02\x60\x24\x33\x97\xfb\xdf\xaf\xd0\xdd\xf8\x32\xe4\x48\xa2\x6c\x6b\x2f\xba\xba\x6c\x55\x2c\x92\x33\x40\xa3\xd1\xdd\xe8\xef\xf0\x56\x2a\xef\x4e\xbe\x1a\x0b\x2d\xd7\x70\x22\x7e\xe7\x2a\xd9\xc0\x57\x42\xb4\x8d\xf4\x73\x63\xd7\x27\x [...]
 		},
 	}
 	fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{