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 2019/09/23 16:32:27 UTC
[camel-k] branch master updated (cd6cf55 -> 01340f0)
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from cd6cf55 Fix #792: add missing mapping
new 93a85ef Initial test
new 21c7412 Updated references
new 3460363 Making client work inside container
new 599f2e6 Adding full tekton tutorial on website
new a89e54c Adding test to verify kamel inside image
new 6e3a658 Fix repo name in example
new 01340f0 Fix travis build
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
build/Dockerfile | 1 +
docs/README.adoc | 16 +-
.../tekton/camel-k-pipeline-permissions.yaml | 176 +++++++++++++++
.../tekton/camel-k-pipeline-task-definition.yaml | 90 ++++++++
.../tekton/camel-k-pipeline-task-run.yaml | 18 +-
.../images/tekton/tekton-pipeline-definition.png | Bin 0 -> 23836 bytes
.../images/tekton/tekton-pipeline-result.png | Bin 0 -> 31685 bytes
.../assets/images/tekton/tekton-pipeline-run.png | Bin 0 -> 21832 bytes
docs/modules/ROOT/nav.adoc | 2 +
.../ROOT/pages/tutorials/tekton/tekton.adoc | 237 +++++++++++++++++++++
docs/modules/ROOT/pages/tutorials/tutorials.adoc | 6 +
docs/package.json | 2 +-
docs/{site.yml => site-dev.yml} | 2 +-
e2e/{test_staging_hooks.go => tekton_test.go} | 32 ++-
e2e/test_staging_hooks.go | 18 +-
e2e/test_support.go | 66 +++++-
examples/tekton/README.md | 5 +
.../tekton/hello.groovy | 4 +-
pkg/client/client.go | 36 ++++
script/Makefile | 2 +
script/travis_build.sh | 1 +
21 files changed, 669 insertions(+), 45 deletions(-)
create mode 100644 docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-permissions.yaml
create mode 100644 docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-definition.yaml
copy examples/knative/messages-channel.yaml => docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-run.yaml (79%)
create mode 100644 docs/modules/ROOT/assets/images/tekton/tekton-pipeline-definition.png
create mode 100644 docs/modules/ROOT/assets/images/tekton/tekton-pipeline-result.png
create mode 100644 docs/modules/ROOT/assets/images/tekton/tekton-pipeline-run.png
create mode 100644 docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc
create mode 100644 docs/modules/ROOT/pages/tutorials/tutorials.adoc
copy docs/{site.yml => site-dev.yml} (93%)
copy e2e/{test_staging_hooks.go => tekton_test.go} (58%)
create mode 100644 examples/tekton/README.md
copy e2e/files/knativech2.groovy => examples/tekton/hello.groovy (91%)
[camel-k] 03/07: Making client work inside container
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 3460363f251deb10988e367c3505dbf6275da9a8
Author: nferraro <ni...@gmail.com>
AuthorDate: Thu Sep 19 12:39:53 2019 +0200
Making client work inside container
---
examples/tekton/camel-k-pipeline-permissions.yaml | 176 +++++++++++++++++++++
examples/tekton/camel-k-pipeline-run.yaml | 54 -------
.../tekton/camel-k-pipeline-task-definition.yaml | 92 +++++++++++
examples/tekton/camel-k-pipeline-task-run.yaml | 30 ++++
pkg/client/client.go | 36 +++++
5 files changed, 334 insertions(+), 54 deletions(-)
diff --git a/examples/tekton/camel-k-pipeline-permissions.yaml b/examples/tekton/camel-k-pipeline-permissions.yaml
new file mode 100644
index 0000000..bf80376
--- /dev/null
+++ b/examples/tekton/camel-k-pipeline-permissions.yaml
@@ -0,0 +1,176 @@
+# ---------------------------------------------------------------------------
+# 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: v1
+kind: ServiceAccount
+metadata:
+ name: camel-k-pipeline
+---
+kind: Role
+apiVersion: rbac.authorization.k8s.io/v1beta1
+metadata:
+ name: camel-k-pipeline
+rules:
+ - apiGroups:
+ - camel.apache.org
+ resources:
+ - "*"
+ verbs:
+ - "*"
+ - apiGroups:
+ - ""
+ resources:
+ - pods
+ - services
+ - endpoints
+ - persistentvolumeclaims
+ - configmaps
+ - secrets
+ - serviceaccounts
+ verbs:
+ - create
+ - delete
+ - deletecollection
+ - get
+ - list
+ - patch
+ - update
+ - watch
+ - apiGroups:
+ - rbac.authorization.k8s.io
+ resources:
+ - roles
+ - rolebindings
+ verbs:
+ - create
+ - delete
+ - deletecollection
+ - get
+ - list
+ - patch
+ - update
+ - watch
+ - apiGroups:
+ - ""
+ resources:
+ - events
+ verbs:
+ - get
+ - list
+ - watch
+ - apiGroups:
+ - apps
+ resources:
+ - deployments
+ - replicasets
+ - statefulsets
+ verbs:
+ - create
+ - delete
+ - deletecollection
+ - get
+ - list
+ - patch
+ - update
+ - watch
+ - apiGroups:
+ - apps
+ attributeRestrictions: null
+ resources:
+ - daemonsets
+ verbs:
+ - get
+ - list
+ - watch
+ - apiGroups:
+ - ""
+ - "build.openshift.io"
+ resources:
+ - buildconfigs
+ - buildconfigs/webhooks
+ - builds
+ verbs:
+ - create
+ - delete
+ - deletecollection
+ - get
+ - list
+ - patch
+ - update
+ - watch
+ - apiGroups:
+ - ""
+ - "image.openshift.io"
+ resources:
+ - imagestreamimages
+ - imagestreammappings
+ - imagestreams
+ - imagestreams/secrets
+ - imagestreamtags
+ verbs:
+ - create
+ - delete
+ - deletecollection
+ - get
+ - list
+ - patch
+ - update
+ - watch
+ - apiGroups:
+ - ""
+ - build.openshift.io
+ attributeRestrictions: null
+ resources:
+ - buildconfigs/instantiate
+ - buildconfigs/instantiatebinary
+ - builds/clone
+ verbs:
+ - create
+ - apiGroups:
+ - ""
+ - "route.openshift.io"
+ resources:
+ - routes
+ verbs:
+ - create
+ - delete
+ - deletecollection
+ - get
+ - list
+ - patch
+ - update
+ - watch
+ - apiGroups:
+ - ""
+ - route.openshift.io
+ resources:
+ - routes/custom-host
+ verbs:
+ - create
+---
+kind: RoleBinding
+apiVersion: rbac.authorization.k8s.io/v1beta1
+metadata:
+ name: camel-k-pipeline
+subjects:
+ - kind: ServiceAccount
+ name: camel-k-pipeline
+roleRef:
+ kind: Role
+ name: camel-k-pipeline
+ apiGroup: rbac.authorization.k8s.io
diff --git a/examples/tekton/camel-k-pipeline-run.yaml b/examples/tekton/camel-k-pipeline-run.yaml
deleted file mode 100644
index bd57dbe..0000000
--- a/examples/tekton/camel-k-pipeline-run.yaml
+++ /dev/null
@@ -1,54 +0,0 @@
----
-apiVersion: tekton.dev/v1alpha1
-kind: PipelineResource
-metadata:
- name: camel-k-examples-git
-spec:
- type: git
- params:
- - name: revision
- value: tekton
- - name: url
- value: https://github.com/nicolaferraro/camel-k
----
-apiVersion: tekton.dev/v1alpha1
-kind: Task
-metadata:
- name: camel-k-install-operator
-spec:
- steps:
- - name: install
- image: nferraro/camel-k:1.0.0-M2-SNAPSHOT
- command:
- - kamel
- args:
- - "install"
- - "--skip-cluster-setup"
- - "--operator-image"
- - "nferraro/camel-k:1.0.0-M2-SNAPSHOT"
----
-apiVersion: tekton.dev/v1alpha1
-kind: Pipeline
-metadata:
- name: camel-k-pipeline
-spec:
- resources:
- - name: source-repo
- type: git
- tasks:
- - name: install-operator
- taskRef:
- name: camel-k-install-operator
----
-apiVersion: tekton.dev/v1alpha1
-kind: PipelineRun
-metadata:
- name: camel-k-pipeline-run-1
-spec:
- pipelineRef:
- name: camel-k-pipeline
- serviceAccount: 'default'
- resources:
- - name: source-repo
- resourceRef:
- name: camel-k-examples-git
diff --git a/examples/tekton/camel-k-pipeline-task-definition.yaml b/examples/tekton/camel-k-pipeline-task-definition.yaml
new file mode 100644
index 0000000..0c0ceb2
--- /dev/null
+++ b/examples/tekton/camel-k-pipeline-task-definition.yaml
@@ -0,0 +1,92 @@
+# ---------------------------------------------------------------------------
+# 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: tekton.dev/v1alpha1
+kind: PipelineResource
+metadata:
+ name: camel-k-examples-git
+spec:
+ type: git
+ params:
+ - name: revision
+ value: tekton
+ - name: url
+ value: https://github.com/nicolaferraro/camel-k
+---
+apiVersion: tekton.dev/v1alpha1
+kind: Task
+metadata:
+ name: camel-k-install-operator
+spec:
+ steps:
+ - name: install
+ image: nferraro/camel-k:1.0.0-M2-SNAPSHOT-v1
+ command:
+ - kamel
+ args:
+ - "install"
+ - "--skip-cluster-setup"
+ - "--operator-image"
+ - "nferraro/camel-k:1.0.0-M2-SNAPSHOT-v1"
+---
+apiVersion: tekton.dev/v1alpha1
+kind: Task
+metadata:
+ name: camel-k-run-integration
+spec:
+ inputs:
+ resources:
+ - name: repository
+ type: git
+ params:
+ - name: file
+ description: The integration file to run
+ steps:
+ - name: run-integration
+ image: nferraro/camel-k:1.0.0-M2-SNAPSHOT-v1
+ workingDir: /workspace/repository
+ command:
+ - kamel
+ args:
+ - "run"
+ - "--wait"
+ - "${inputs.params.file}"
+---
+apiVersion: tekton.dev/v1alpha1
+kind: Pipeline
+metadata:
+ name: camel-k-pipeline
+spec:
+ resources:
+ - name: source-repo
+ type: git
+ tasks:
+ - name: install-operator
+ taskRef:
+ name: camel-k-install-operator
+ - name: run-integration
+ runAfter: [install-operator]
+ taskRef:
+ name: camel-k-run-integration
+ resources:
+ inputs:
+ - name: repository
+ resource: source-repo
+ params:
+ - name: file
+ value: "examples/tekton/hello.groovy"
diff --git a/examples/tekton/camel-k-pipeline-task-run.yaml b/examples/tekton/camel-k-pipeline-task-run.yaml
new file mode 100644
index 0000000..263a99a
--- /dev/null
+++ b/examples/tekton/camel-k-pipeline-task-run.yaml
@@ -0,0 +1,30 @@
+# ---------------------------------------------------------------------------
+# 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: tekton.dev/v1alpha1
+kind: PipelineRun
+metadata:
+ name: camel-k-pipeline-run-13
+spec:
+ pipelineRef:
+ name: camel-k-pipeline
+ serviceAccount: 'camel-k-pipeline'
+ resources:
+ - name: source-repo
+ resourceRef:
+ name: camel-k-examples-git
diff --git a/pkg/client/client.go b/pkg/client/client.go
index eebbd28..dd0f06d 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -26,6 +26,7 @@ import (
"github.com/apache/camel-k/pkg/apis"
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -39,6 +40,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)
+const inContainerNamespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
+
// Client is an abstraction for a k8s client
type Client interface {
controller.Client
@@ -132,6 +135,13 @@ func FromManager(manager manager.Manager) (Client, error) {
// init initialize the k8s client for usage outside the cluster
func initialize(kubeconfig string) {
if kubeconfig == "" {
+ // skip out-of-cluster initialization if inside the container
+ if kc, err := runningInKubernetesContainer(); kc && err == nil {
+ return
+ } else if err != nil {
+ logrus.Errorf("could not determine if running in a container: %v", err)
+ }
+
kubeconfig = getDefaultKubeConfigFile()
}
os.Setenv(k8sutil.KubeConfigEnvVar, kubeconfig)
@@ -148,6 +158,15 @@ func getDefaultKubeConfigFile() string {
// GetCurrentNamespace --
func GetCurrentNamespace(kubeconfig string) (string, error) {
if kubeconfig == "" {
+ kubeContainer, err := runningInKubernetesContainer()
+ if err != nil {
+ return "", err
+ }
+ if kubeContainer {
+ return getNamespaceFromKubernetesContainer()
+ }
+ }
+ if kubeconfig == "" {
kubeconfig = getDefaultKubeConfigFile()
}
if kubeconfig == "" {
@@ -174,3 +193,20 @@ func GetCurrentNamespace(kubeconfig string) (string, error) {
ns, _, err := cc.Namespace()
return ns, err
}
+
+func runningInKubernetesContainer() (bool, error) {
+ _, err := os.Stat(inContainerNamespaceFile)
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return true, err
+}
+
+func getNamespaceFromKubernetesContainer() (string, error) {
+ var nsba []byte
+ var err error
+ if nsba, err = ioutil.ReadFile(inContainerNamespaceFile); err != nil {
+ return "", err
+ }
+ return string(nsba), nil
+}
[camel-k] 01/07: Initial test
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 93a85ef45cc6f85a980ecde9ec57a68f56cbae8b
Author: nferraro <ni...@gmail.com>
AuthorDate: Wed Sep 18 17:39:08 2019 +0200
Initial test
---
build/Dockerfile | 1 +
examples/tekton/camel-k-pipeline-run.yaml | 52 +++++++++++++++++++++++++++++++
examples/tekton/hello.groovy | 19 +++++++++++
3 files changed, 72 insertions(+)
diff --git a/build/Dockerfile b/build/Dockerfile
index c2fd9d2..6ded515 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -25,3 +25,4 @@ USER 1000
ADD build/_output/bin/camel-k /usr/local/bin/camel-k
ADD build/_output/bin/builder /usr/local/bin/camel-k-builder
+ADD build/_output/bin/kamel /usr/local/bin/kamel
diff --git a/examples/tekton/camel-k-pipeline-run.yaml b/examples/tekton/camel-k-pipeline-run.yaml
new file mode 100644
index 0000000..f50df36
--- /dev/null
+++ b/examples/tekton/camel-k-pipeline-run.yaml
@@ -0,0 +1,52 @@
+---
+apiVersion: tekton.dev/v1alpha1
+kind: PipelineResource
+metadata:
+ name: camel-k-examples-git
+spec:
+ type: git
+ params:
+ - name: revision
+ value: tekton
+ - name: url
+ value: https://github.com/nicolaferraro/camel-k
+---
+apiVersion: tekton.dev/v1alpha1
+kind: Task
+metadata:
+ name: camel-k-install-operator
+spec:
+ steps:
+ - name: install
+ image: apache/camel-k:1.0.0-M1
+ command:
+ - kamel
+ args:
+ - "install"
+ - "--skip-cluster-setup"
+---
+apiVersion: tekton.dev/v1alpha1
+kind: Pipeline
+metadata:
+ name: camel-k-pipeline
+spec:
+ resources:
+ - name: source-repo
+ type: git
+ tasks:
+ - name: install-operator
+ taskRef:
+ name: camel-k-install-operator
+---
+apiVersion: tekton.dev/v1alpha1
+kind: PipelineRun
+metadata:
+ name: camel-k-pipeline-run-1
+spec:
+ pipelineRef:
+ name: camel-k-pipeline
+ serviceAccount: 'default'
+ resources:
+ - name: source-repo
+ resourceRef:
+ name: camel-k-examples-git
diff --git a/examples/tekton/hello.groovy b/examples/tekton/hello.groovy
new file mode 100644
index 0000000..39d23f6
--- /dev/null
+++ b/examples/tekton/hello.groovy
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+from('timer:groovy?period=1s')
+ .log('Hello Camel K from Tekton pipelines')
[camel-k] 02/07: Updated references
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 21c7412b22a750b2caa55e6a6dcd7bde50c7fcd3
Author: nferraro <ni...@gmail.com>
AuthorDate: Wed Sep 18 17:45:40 2019 +0200
Updated references
---
examples/tekton/camel-k-pipeline-run.yaml | 4 +++-
script/Makefile | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/examples/tekton/camel-k-pipeline-run.yaml b/examples/tekton/camel-k-pipeline-run.yaml
index f50df36..bd57dbe 100644
--- a/examples/tekton/camel-k-pipeline-run.yaml
+++ b/examples/tekton/camel-k-pipeline-run.yaml
@@ -18,12 +18,14 @@ metadata:
spec:
steps:
- name: install
- image: apache/camel-k:1.0.0-M1
+ image: nferraro/camel-k:1.0.0-M2-SNAPSHOT
command:
- kamel
args:
- "install"
- "--skip-cluster-setup"
+ - "--operator-image"
+ - "nferraro/camel-k:1.0.0-M2-SNAPSHOT"
---
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
diff --git a/script/Makefile b/script/Makefile
index 55a4c0f..c09462c 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -161,12 +161,14 @@ images: test
mkdir -p build/_maven_output
mkdir -p build/_output/bin
cp builder build/_output/bin
+ cp kamel build/_output/bin
operator-sdk build $(IMAGE_NAME):$(VERSION)
images-dev: test package-artifacts
mkdir -p build/_maven_output
mkdir -p build/_output/bin
cp builder build/_output/bin
+ cp kamel build/_output/bin
operator-sdk build $(IMAGE_NAME):$(VERSION)
images-push:
[camel-k] 07/07: Fix travis build
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 01340f0b05228e9948719ff41da631c95c10a9f0
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Sep 20 10:21:34 2019 +0200
Fix travis build
---
script/travis_build.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/script/travis_build.sh b/script/travis_build.sh
index 70b0272..215613e 100755
--- a/script/travis_build.sh
+++ b/script/travis_build.sh
@@ -72,6 +72,7 @@ echo "Copying binary file to docker dir"
mkdir -p ./build/_output/bin
cp ./camel-k ./build/_output/bin/
cp ./builder ./build/_output/bin/
+cp ./kamel ./build/_output/bin/
echo "Building the images"
export IMAGE=docker.io/apache/camel-k:$(make version)
[camel-k] 06/07: Fix repo name in example
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 6e3a658e1caf28e59501ddf36e161f6063bb42cc
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Sep 20 09:59:36 2019 +0200
Fix repo name in example
---
docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc b/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc
index 7865d86..4e31497 100644
--- a/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc
+++ b/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc
@@ -128,7 +128,7 @@ metadata:
spec:
steps:
- name: install
- image: nferraro/camel-k:1.0.0-M2
+ image: apache/camel-k:1.0.0-M2
command:
- kamel
args:
[camel-k] 05/07: Adding test to verify kamel inside image
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a89e54c467c4ed4761b0ec5705afe29527ee9548
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Sep 20 09:27:44 2019 +0200
Adding test to verify kamel inside image
---
e2e/{test_staging_hooks.go => tekton_test.go} | 32 ++++++++-----
e2e/test_staging_hooks.go | 18 +++++---
e2e/test_support.go | 66 +++++++++++++++++++++++----
3 files changed, 89 insertions(+), 27 deletions(-)
diff --git a/e2e/test_staging_hooks.go b/e2e/tekton_test.go
similarity index 58%
copy from e2e/test_staging_hooks.go
copy to e2e/tekton_test.go
index f85998b..dd4d7dc 100644
--- a/e2e/test_staging_hooks.go
+++ b/e2e/tekton_test.go
@@ -1,4 +1,4 @@
-// +build integration knative
+// +build integration
// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
@@ -21,15 +21,25 @@ limitations under the License.
package e2e
-func init() {
- // this hook can be used to test a released version of the operator, e.g. the staging version during a voting period
- // Uncomment the following lines and change references to enable the hook
- kamelHooks = append(kamelHooks, func(cmd []string) []string {
- //if len(cmd) > 0 && cmd[0] == "install" {
- // cmd = append(cmd, "--operator-image=docker.io/camelk/camel-k:1.0.0-M1")
- // cmd = append(cmd, "--maven-repository=https://repository.apache.org/content/repositories/orgapachecamel-1145")
- //}
- return cmd
- })
+import (
+ "testing"
+
+ . "github.com/onsi/gomega"
+)
+
+// TestTektonLikeBehavior verifies that the kamel binary can be invoked from within the Camel K image.
+// This feature is used in Tekton pipelines.
+func TestTektonLikeBehavior(t *testing.T) {
+ withNewTestNamespace(func(ns string) {
+ RegisterTestingT(t)
+ Expect(createOperatorServiceAccount(ns)).Should(BeNil())
+ Expect(createOperatorRole(ns)).Should(BeNil())
+ Expect(createOperatorRoleBinding(ns)).Should(BeNil())
+
+ Eventually(operatorPod(ns)).Should(BeNil())
+ Expect(createKamelPod(ns, "tekton-task", "install")).Should(BeNil())
+
+ Eventually(operatorPod(ns)).ShouldNot(BeNil())
+ })
}
diff --git a/e2e/test_staging_hooks.go b/e2e/test_staging_hooks.go
index f85998b..a441084 100644
--- a/e2e/test_staging_hooks.go
+++ b/e2e/test_staging_hooks.go
@@ -24,12 +24,16 @@ package e2e
func init() {
// this hook can be used to test a released version of the operator, e.g. the staging version during a voting period
// Uncomment the following lines and change references to enable the hook
- kamelHooks = append(kamelHooks, func(cmd []string) []string {
- //if len(cmd) > 0 && cmd[0] == "install" {
- // cmd = append(cmd, "--operator-image=docker.io/camelk/camel-k:1.0.0-M1")
- // cmd = append(cmd, "--maven-repository=https://repository.apache.org/content/repositories/orgapachecamel-1145")
- //}
- return cmd
- })
+
+ //testImageName = "docker.io/camelk/camel-k"
+ //testImageVersion = "1.0.0-M2-SNAPSHOT"
+
+ //kamelHooks = append(kamelHooks, func(cmd []string) []string {
+ // if len(cmd) > 0 && cmd[0] == "install" {
+ // cmd = append(cmd, "--operator-image=docker.io/camelk/camel-k:1.0.0-M2-SNAPSHOT")
+ // cmd = append(cmd, "--maven-repository=https://repository.apache.org/content/repositories/orgapachecamel-1145")
+ // }
+ // return cmd
+ //})
}
diff --git a/e2e/test_support.go b/e2e/test_support.go
index c5db056..38e92bf 100644
--- a/e2e/test_support.go
+++ b/e2e/test_support.go
@@ -25,16 +25,17 @@ import (
"context"
"errors"
"fmt"
+ "io/ioutil"
"os"
"os/exec"
"strings"
"time"
- "io/ioutil"
-
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/cmd"
+ "github.com/apache/camel-k/pkg/install"
+ "github.com/apache/camel-k/pkg/util/defaults"
"github.com/apache/camel-k/pkg/util/log"
"github.com/apache/camel-k/pkg/util/openshift"
"github.com/google/uuid"
@@ -55,7 +56,10 @@ var testContext context.Context
var testClient client.Client
// kamelHooks contains hooks useful to add option to kamel commands at runtime
-var kamelHooks []func([]string)[]string
+var kamelHooks []func([]string) []string
+
+var testImageName = defaults.ImageName
+var testImageVersion = defaults.Version
func init() {
var err error
@@ -442,25 +446,70 @@ func scaleOperator(ns string, replicas int32) func() error {
}
/*
+ Tekton
+*/
+
+func createOperatorServiceAccount(ns string) error {
+ return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-service-account.yaml")
+}
+
+func createOperatorRole(ns string) error {
+ return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-openshift.yaml")
+}
+
+func createOperatorRoleBinding(ns string) error {
+ return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-binding.yaml")
+}
+
+func createKamelPod(ns string, name string, command ...string) error {
+ args := command
+ for _, hook := range kamelHooks {
+ args = hook(args)
+ }
+ pod := v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: v1.SchemeGroupVersion.String(),
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: ns,
+ Name: name,
+ },
+ Spec: v1.PodSpec{
+ ServiceAccountName: "camel-k-operator",
+ RestartPolicy: v1.RestartPolicyNever,
+ Containers: []v1.Container{
+ {
+ Name: "kamel-runner",
+ Image: testImageName + ":" + testImageVersion,
+ Command: append([]string{"kamel"}, args...),
+ },
+ },
+ },
+ }
+ return testClient.Create(testContext, &pod)
+}
+
+/*
Knative
- */
+*/
func createKnativeChannel(ns string, name string) func() error {
return func() error {
channel := eventing.Channel{
TypeMeta: metav1.TypeMeta{
- Kind: "Channel",
+ Kind: "Channel",
APIVersion: eventing.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
- Name: name,
+ Name: name,
},
Spec: eventing.ChannelSpec{
Provisioner: &v1.ObjectReference{
APIVersion: "eventing.knative.dev/v1alpha1",
- Kind: "ClusterChannelProvisioner",
- Name: "in-memory",
+ Kind: "ClusterChannelProvisioner",
+ Name: "in-memory",
},
},
}
@@ -468,7 +517,6 @@ func createKnativeChannel(ns string, name string) func() error {
}
}
-
/*
Namespace testing functions
*/
[camel-k] 04/07: Adding full tekton tutorial on website
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 599f2e6e11edf44ed2690b280be274d38d81a937
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Sep 20 00:59:55 2019 +0200
Adding full tekton tutorial on website
---
docs/README.adoc | 16 +-
.../tekton/camel-k-pipeline-permissions.yaml | 0
.../tekton/camel-k-pipeline-task-definition.yaml | 6 +-
.../tekton/camel-k-pipeline-task-run.yaml | 4 +-
.../images/tekton/tekton-pipeline-definition.png | Bin 0 -> 23836 bytes
.../images/tekton/tekton-pipeline-result.png | Bin 0 -> 31685 bytes
.../assets/images/tekton/tekton-pipeline-run.png | Bin 0 -> 21832 bytes
docs/modules/ROOT/nav.adoc | 2 +
.../ROOT/pages/tutorials/tekton/tekton.adoc | 237 +++++++++++++++++++++
docs/modules/ROOT/pages/tutorials/tutorials.adoc | 6 +
docs/package.json | 2 +-
docs/site-dev.yml | 15 ++
examples/tekton/README.md | 5 +
13 files changed, 279 insertions(+), 14 deletions(-)
diff --git a/docs/README.adoc b/docs/README.adoc
index a91e1ee..19accc0 100644
--- a/docs/README.adoc
+++ b/docs/README.adoc
@@ -9,22 +9,24 @@ To setup the environment you need to execute the following command once (and eve
yarn install
```
-== Build the Documentation Website
+== Local development
-To generate the documentation website, execute:
+To build the local copy of the website and preview it, execute:
```
-yarn build
+yarn dev
```
-To preview it in the local browser, execute:
+== Build the Documentation Website
+
+To generate the documentation website from the remote repository branch, execute:
```
-yarn preview
+yarn build
```
-To both build and preview, execute:
+To preview it in the local browser, execute:
```
-yarn dev
+yarn preview
```
diff --git a/examples/tekton/camel-k-pipeline-permissions.yaml b/docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-permissions.yaml
similarity index 100%
rename from examples/tekton/camel-k-pipeline-permissions.yaml
rename to docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-permissions.yaml
diff --git a/examples/tekton/camel-k-pipeline-task-definition.yaml b/docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-definition.yaml
similarity index 92%
rename from examples/tekton/camel-k-pipeline-task-definition.yaml
rename to docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-definition.yaml
index 0c0ceb2..9d66e22 100644
--- a/examples/tekton/camel-k-pipeline-task-definition.yaml
+++ b/docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-definition.yaml
@@ -35,14 +35,12 @@ metadata:
spec:
steps:
- name: install
- image: nferraro/camel-k:1.0.0-M2-SNAPSHOT-v1
+ image: apache/camel-k:1.0.0-M2
command:
- kamel
args:
- "install"
- "--skip-cluster-setup"
- - "--operator-image"
- - "nferraro/camel-k:1.0.0-M2-SNAPSHOT-v1"
---
apiVersion: tekton.dev/v1alpha1
kind: Task
@@ -58,7 +56,7 @@ spec:
description: The integration file to run
steps:
- name: run-integration
- image: nferraro/camel-k:1.0.0-M2-SNAPSHOT-v1
+ image: apache/camel-k:1.0.0-M2
workingDir: /workspace/repository
command:
- kamel
diff --git a/examples/tekton/camel-k-pipeline-task-run.yaml b/docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-run.yaml
similarity index 97%
rename from examples/tekton/camel-k-pipeline-task-run.yaml
rename to docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-run.yaml
index 263a99a..db9f2ca 100644
--- a/examples/tekton/camel-k-pipeline-task-run.yaml
+++ b/docs/modules/ROOT/assets/attachments/tekton/camel-k-pipeline-task-run.yaml
@@ -15,11 +15,11 @@
# limitations under the License.
# ---------------------------------------------------------------------------
----
+
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
- name: camel-k-pipeline-run-13
+ name: camel-k-pipeline-run-1
spec:
pipelineRef:
name: camel-k-pipeline
diff --git a/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-definition.png b/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-definition.png
new file mode 100644
index 0000000..0d5b282
Binary files /dev/null and b/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-definition.png differ
diff --git a/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-result.png b/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-result.png
new file mode 100644
index 0000000..ef70759
Binary files /dev/null and b/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-result.png differ
diff --git a/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-run.png b/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-run.png
new file mode 100644
index 0000000..f8be6b8
Binary files /dev/null and b/docs/modules/ROOT/assets/images/tekton/tekton-pipeline-run.png differ
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index dc2578a..42da5ef 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -16,6 +16,8 @@
** xref:languages/javascript.adoc[JavaScript]
** xref:languages/java.adoc[Java]
** xref:languages/xml.adoc[XML]
+* xref:tutorials/tutorials.adoc[Tutorials]
+** xref:tutorials/tekton/tekton.adoc[Tekton Pipelines]
* xref:traits.adoc[Traits]
* xref:uninstalling.adoc[Uninstalling]
* xref:developers.adoc[Contributing to Camel K]
diff --git a/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc b/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc
new file mode 100644
index 0000000..7865d86
--- /dev/null
+++ b/docs/modules/ROOT/pages/tutorials/tekton/tekton.adoc
@@ -0,0 +1,237 @@
+[[tutorials-tekton]]
+= Camel K in Tekton Pipelines
+
+[[tutorials-tekton-introduction]]
+== Introduction
+
+NOTE: Available from Camel K 1.0.0-M2
+
+Camel K can be directly used in https://github.com/tektoncd/pipeline[Tekton Pipelines] tasks since it's container image ships the `kamel` CLI tool, that
+can be used to create all needed resources by interacting with the Kubernetes cluster.
+
+For example, the following Tekton pipeline task can be used to run an integration:
+
+[#camel-k-task-run-integration]
+[source,yaml]
+----
+apiVersion: tekton.dev/v1alpha1
+kind: Task
+metadata:
+ name: camel-k-run-integration
+spec:
+ inputs:
+ resources:
+ - name: repository
+ type: git
+ params:
+ - name: file
+ description: The integration file to run
+ steps:
+ - name: run-integration
+ image: apache/camel-k:1.0.0-M2 //<1>
+ workingDir: /workspace/repository
+ command:
+ - kamel
+ args:
+ - "run"
+ - "--wait"
+ - "${inputs.params.file}" //<2>
+----
+
+TIP: Tekton Pipelines 0.6+ support also the $() syntax for variable substitution
+
+<1> The base image for the step is `apache/camel-k:1.0.0-M2`
+<2> It executes command `kamel run --wait ${inputs.params.file}`, with file to run received as parameter
+
+When executed, such task creates an integration resource from the given file (which is supposed to be contained in the input git repository) and waits for the integration to be fully running before completing.
+
+This task is a building block for more complex scenarios that can be composed in Tekton pipelines.
+If you want to learn more, just follow the remainder of the tutorial.
+
+[[tutorials-tekton-prerequisites]]
+== Prerequisites
+
+This tutorial assumes the following requirements are met:
+
+* OpenShift (or OKD) 4+ cluster (works also on "vanilla" Kubernetes with some adjustment) and `oc` binary tool
+* Tekton Pipelines 0.5.2 (different versions may need adjustments)
+* Camel K Client Tools 1.0.0-M2 (`kamel` binary tool)
+
+[[tutorials-tekton-cluster-setup]]
+== Cluster Setup
+
+This tutorial assumes that **Tekton Pipelines are already installed** in the cluster. Refer to the https://github.com/tektoncd/pipeline[Tekton documentation]
+to learn how to install them.
+
+Camel K cluster resources need to be installed on the cluster:
+
+[source,bash]
+----
+# Use the oc tool to login as cluster admin to the target cluster, then
+kamel install --cluster-setup
+----
+
+This will install the Camel K CRD (custom resource definitions) and roles to access them.
+You can switch to a standard user after doing this operation.
+
+[[tutorials-tekton-creating-the-pipeline]]
+== Creating the Pipeline
+
+We're going to create a pipeline on a new namespace. The first step is to create the namespace:
+
+[source,bash]
+----
+oc new-project camel-pipelines
+----
+
+=== Setting up a ServiceAccount
+
+Any running container that needs to interact with the Kubernetes API (in our case, to create deployment and integration resources) must
+have special permissions granted to its service account.
+
+Download the link:{attachmentsdir}/tekton/camel-k-pipeline-permissions.yaml[camel-k-pipeline-permissions.yaml] file and save it into a directory in your hard drive.
+Then install it using the `oc` client tool:
+
+[source,bash]
+----
+oc apply -f camel-k-pipeline-permissions.yaml
+----
+
+This creates a https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/[Kubernetes ServiceAccount] named `camel-k-pipeline`
+that is authorized to create the same kind of resources that the Camel K operator needs to create. We'll use that service account to run our pipeline.
+
+=== Creating the Pipeline Definition
+
+Let's now create the pipeline definition. Download the link:{attachmentsdir}/tekton/camel-k-pipeline-task-definition.yaml[camel-k-pipeline-task-definition.yaml] file
+and apply it to the cluster:
+
+[source,bash]
+----
+oc apply -f camel-k-pipeline-task-definition.yaml
+----
+
+This creates a series of resources, including a pipeline definition that you can immediately see on the OpenShift developer console.
+
+image::tekton/tekton-pipeline-definition.png[View of the Camel K Tekton pipeline in the OpenShift developer console]
+
+The pipeline just created is composed of two tasks.
+
+The last task (`camel-k-run-integration`) is the one we've <<camel-k-task-run-integration,already described in the introduction>>, while the first task just installs the operator in the current namespace.
+The definition of the first task is shown in the following excerpt:
+
+[source,yaml]
+----
+apiVersion: tekton.dev/v1alpha1
+kind: Task
+metadata:
+ name: camel-k-install-operator
+spec:
+ steps:
+ - name: install
+ image: nferraro/camel-k:1.0.0-M2
+ command:
+ - kamel
+ args:
+ - "install"
+ - "--skip-cluster-setup"
+----
+
+As you see, it's just doing a `kamel install --skip-cluster-setup` (we've already done the cluster setup in the <<tutorials-tekton-cluster-setup,preparation phase>>).
+
+
+Both tasks are executed in sequence in the pipeline that is shown below.
+
+[source,yaml]
+----
+apiVersion: tekton.dev/v1alpha1
+kind: Pipeline
+metadata:
+ name: camel-k-pipeline
+spec:
+ resources:
+ - name: source-repo
+ type: git
+ tasks:
+ - name: install-operator
+ taskRef:
+ name: camel-k-install-operator
+ - name: run-integration
+ runAfter: [install-operator]
+ taskRef:
+ name: camel-k-run-integration
+ resources:
+ inputs:
+ - name: repository
+ resource: source-repo
+ params:
+ - name: file
+ value: "examples/tekton/hello.groovy"
+----
+
+The integration file to be executed is set to `examples/tekton/hello.groovy` that is a simple "Hello World" integration contained in the Camel K
+github repository https://github.com/apache/camel-k/tree/master/example/tekton[example/tekton directory].
+
+In order to specify the actual source repository, the definition file contains also the following resource:
+
+[source,yaml]
+----
+apiVersion: tekton.dev/v1alpha1
+kind: PipelineResource
+metadata:
+ name: camel-k-examples-git
+spec:
+ type: git
+ params:
+ - name: revision
+ value: master
+ - name: url
+ value: https://github.com/apache/camel-k
+----
+
+The repo will be now used as input for the <<camel-k-task-run-integration,run-integration task>> in the pipeline.
+
+=== Triggering a Pipeline Execution
+
+Everything is now ready to be executed and the last thing missing is a trigger. Download the link:{attachmentsdir}/tekton/camel-k-pipeline-task-run.yaml[camel-k-pipeline-task-run.yaml] file
+and apply it to the cluster:
+
+[source,bash]
+----
+oc apply -f camel-k-pipeline-task-run.yaml
+----
+
+The file contains only a PipelineRun resource:
+
+[source,yaml]
+----
+apiVersion: tekton.dev/v1alpha1
+kind: PipelineRun
+metadata:
+ name: camel-k-pipeline-run-1
+spec:
+ pipelineRef:
+ name: camel-k-pipeline
+ serviceAccount: 'camel-k-pipeline' //<1>
+ resources:
+ - name: source-repo
+ resourceRef:
+ name: camel-k-examples-git //<2>
+----
+
+<1> The PipelineRun binds the pipeline to the service account previously created
+<2> It also binds the pipeline to the Camel K repository containing the examples
+
+The creation of the file starts the execution of the pipeline and its progress can be monitored on the OpenShift developer console.
+
+image::tekton/tekton-pipeline-run.png[View of the Camel K Tekton pipeline execution in the OpenShift developer console]
+
+CAUTION: To execute the PipelineRun again, delete previous runs before re-applying
+
+The result of the pipeline execution is the Camel K operator and an integration named `hello` running on the cluster:
+
+image::tekton/tekton-pipeline-result.png[Result of the Camel K Tekton pipeline execution]
+
+There are certainly other ways to trigger an execution of a pipeline, like as reaction to a change in the git repository,
+but this is left to you as exercise ;)
+
+Refer to the https://github.com/tektoncd/pipeline[Tekton repository] for more information.
diff --git a/docs/modules/ROOT/pages/tutorials/tutorials.adoc b/docs/modules/ROOT/pages/tutorials/tutorials.adoc
new file mode 100644
index 0000000..3d1b4d9
--- /dev/null
+++ b/docs/modules/ROOT/pages/tutorials/tutorials.adoc
@@ -0,0 +1,6 @@
+[[tutorials]]
+= Camel K Tutorials
+
+This section contains a collection of tutorials that dig inside specific Camel K features.
+
+* xref:tutorials/tekton/tekton.adoc[Camel K in Tekton Pipelines]
diff --git a/docs/package.json b/docs/package.json
index 3ec0734..d02e6ab 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -12,7 +12,7 @@
"scripts": {
"preview": "cd public && lite-server",
"build": "yarn antora --stacktrace site.yml",
- "dev": "yarn build && yarn preview",
+ "dev": "yarn antora --stacktrace site-dev.yml && yarn preview",
"checks": "yarn antora --generator @antora/xref-validator site.yml"
}
}
diff --git a/docs/site-dev.yml b/docs/site-dev.yml
new file mode 100644
index 0000000..96004a6
--- /dev/null
+++ b/docs/site-dev.yml
@@ -0,0 +1,15 @@
+site:
+ title: Camel K
+ url: https://camel.apache.org/
+ start_page: camel-k::index.adoc
+content:
+ sources:
+ - url: ../
+ branches: HEAD
+ start_path: docs
+ui:
+ bundle:
+ url: https://gitlab.com/antora/antora-ui-default/-/jobs/artifacts/master/raw/build/ui-bundle.zip?job=bundle-stable
+ snapshot: true
+output:
+ dir: ./public
diff --git a/examples/tekton/README.md b/examples/tekton/README.md
new file mode 100644
index 0000000..86d1e87
--- /dev/null
+++ b/examples/tekton/README.md
@@ -0,0 +1,5 @@
+# Example: Camel K in Tekton Pipelines
+
+This example is part of a tutorial about running Camel K on Tekton pipelines.
+
+You can find the tutorial at https://camel.apache.org/camel-k/latest/tutorials/tekton/tekton.html