Skip to content

Commit

Permalink
feat(knative): make installation explicit
Browse files Browse the repository at this point in the history
Instead of letting the CLI perfom the installation, we need to make it explicit in order to use the same approach for any other installation methodology.

Closes #4716
  • Loading branch information
squakez committed Dec 15, 2023
1 parent 467c126 commit b9b5298
Show file tree
Hide file tree
Showing 33 changed files with 270 additions and 118 deletions.
47 changes: 27 additions & 20 deletions config/manifests/bases/camel-k.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
categories: Integration & Delivery
certified: "false"
containerImage: docker.io/apache/camel-k:2.2.0-SNAPSHOT
createdAt: 2023-10-24T07:48:33Z
createdAt: 2023-12-15T09:52:30Z
description: Apache Camel K is a lightweight integration platform, born on Kubernetes,
with serverless superpowers.
operators.operatorframework.io/builder: operator-sdk-v1.16.0
Expand Down Expand Up @@ -87,10 +87,12 @@ spec:
Apache Camel K
==============
Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless superpowers.
Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless superpowers:
the easiest way to build and manage your Camel applications on Kubernetes.
## Installation
You may need to specify the container registry where to store the container images created for the Camel applications.
To start using Camel K, install the operator and then create the following `IntegrationPlatform`:
```
apiVersion: camel.apache.org/v1
Expand All @@ -99,34 +101,39 @@ spec:
name: camel-k
labels:
app: "camel-k"
spec:
build:
registry:
address: docker.io/my-org
```
An `IntegrationPlatform` resource is automatically created by default on OpenShift, so you can skip this step.
Also, You can edit the `IntegrationPlatform`, to configure Camel K.
The configuration from the `IntegrationPlatform` will apply to the Camel integrations created in the same namespace/project.
An `IntegrationPlatform` resource is automatically created by default on OpenShift, so you can skip this step when using Openshift cluster.
## Running an Integration
After the initial setup, you can run a Camel integration on the cluster by creating an example `Integration`, e.g.:
Run a Camel application on the cluster by creating a sample `Integration`, e.g.:
```
apiVersion: camel.apache.org/v1
kind: Integration
metadata:
name: example
annotations:
camel.apache.org/operator.id: camel-k
name: test
spec:
sources:
- name: Example.java
content: |
import org.apache.camel.builder.RouteBuilder;
public class Example extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:tick")
.setBody(constant("Hello World!"))
.to("log:info?skipBodyLineSeparator=false");
}
}
flows:
- from:
parameters:
period: "1000"
steps:
- setBody:
simple: Hello Camel from ${routeId}
- log: ${body}
uri: timer:yaml
```
Log the result of the running application:
```
kubectl wait --for=condition=ready integration test --timeout=180s
kubectl logs deployment/test -f
```
displayName: Camel K Operator
icon:
Expand Down
27 changes: 27 additions & 0 deletions config/rbac/descoped/knative/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

#
# rbac resources applicable for all kubernetes platforms - global operator
#
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- operator-cluster-role-knative.yaml
- operator-cluster-role-binding-knative.yaml

2 changes: 0 additions & 2 deletions config/rbac/descoped/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ kind: Kustomization

resources:
- operator-cluster-role-events.yaml
- operator-cluster-role-knative.yaml
- operator-cluster-role.yaml
- operator-cluster-role-keda.yaml
- operator-cluster-role-leases.yaml
- operator-cluster-role-podmonitors.yaml
- operator-cluster-role-strimzi.yaml
- operator-cluster-role-binding-events.yaml
- operator-cluster-role-binding-keda.yaml
- operator-cluster-role-binding-knative.yaml
- operator-cluster-role-binding-leases.yaml
- operator-cluster-role-binding-podmonitors.yaml
- operator-cluster-role-binding-strimzi.yaml
Expand Down
26 changes: 26 additions & 0 deletions config/rbac/namespaced/knative/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

#
# rbac resources applicable for all kubernetes platforms - namespaced operator
#
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- operator-role-knative.yaml
- operator-role-binding-knative.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: camel-k-operator
namespace: placeholder
roleRef:
kind: Role
name: camel-k-operator-knative
Expand Down
2 changes: 0 additions & 2 deletions config/rbac/namespaced/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ kind: Kustomization

resources:
- operator-role-events.yaml
- operator-role-knative.yaml
- operator-role.yaml
- operator-role-keda.yaml
- operator-role-leases.yaml
- operator-role-podmonitors.yaml
- operator-role-strimzi.yaml
- operator-role-binding-events.yaml
- operator-role-binding-keda.yaml
- operator-role-binding-knative.yaml
- operator-role-binding-leases.yaml
- operator-role-binding-podmonitors.yaml
- operator-role-binding-strimzi.yaml
Expand Down
5 changes: 3 additions & 2 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* xref:installation/installation.adoc[Installation]
** xref:installation/advanced/maven.adoc[Configuring Maven]
** xref:installation/registry/registry.adoc[Configuring Registry]
** xref:installation/advanced/maven.adoc[Configure Maven]
** xref:installation/registry/registry.adoc[Configure Registry]
** xref:installation/knative.adoc[Configure Knative]
** xref:contributing/upgrade.adoc[Upgrade]
** xref:contributing/uninstalling.adoc[Uninstalling]
** xref:installation/advanced/advanced.adoc[Advanced]
Expand Down
42 changes: 42 additions & 0 deletions docs/modules/ROOT/pages/installation/knative.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
= Knative installation

"https://knative.dev[Knative] is an Open-Source Enterprise-level solution to build Serverless and Event Driven Applications. The effort done in this project is a great complement to Camel K, which can leverage some feature offered by Knative. In particular, Camel K will be able to leverage "scale to 0" (hence, serverless) feature offered by Knative.

NOTE: Knative is an optional configuration. It is not required to run Camel K.

[[install-knative]]
== Knative roles configuration

Camel K needs to have certain privileges to use the resources used by Knative. We have identified them, so, it follows a few configuration that you will need to apply in order to make Camel K work with Knative.

NOTE: We assume you have already both the Knative operator and the Camel K operator up and running. If not, the first step is to install both operator. See the guide on xref:installation/installation.adoc[how to install Camel K] and the guide on https://knative.dev/docs/install/[how to install Knative] respectively.

Once all the resources are installed in the cluster, you'll need to provide the required privileges for Camel K operator to work with Knative resources.

NOTE: you will need `kustomize` CLI available.

=== Global operator (descoped)

```bash
git clone --depth 1 --branch v2.1.0 https://github.com/apache/camel-k.git
cd camel-k/config/rbac/descoped/knative
sed -i "s/namespace: placeholder/namespace: $OPERATOR_NAMESPACE/" operator-cluster-role-binding-knative.yaml
kustomize edit set namespace $OPERATOR_NAMESPACE
kubectl apply -k .
```

=== Namespaced operator

```bash
git clone --depth 1 --branch v2.1.0 https://github.com/apache/camel-k.git
cd camel-k/config/rbac/namespaced/knative
sed -i "s/namespace: placeholder/namespace: $OPERATOR_NAMESPACE/" operator-role-binding-knative.yaml
kustomize edit set namespace $OPERATOR_NAMESPACE
kubectl apply -k .
```

NOTE: in this example we've used the released `2.1.0` version. Make sure to use the same version of your installed operator.

As the installation procedure can vary depending on the cluster and the methodology you use (Helm, OLM, Kustomize, ...), feel free to customize in the way that it results more convenient. In the `/config/rbac/knative` you will already find the basic `kustomization.yaml` on top of which you may provide any further level of customization.

From now on you should be able to run some Camel application leveraging Knative with Camel K (see https://github.com/apache/camel-k-examples/tree/main/generic-examples/knative[examples]).
23 changes: 20 additions & 3 deletions e2e/knative/knative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package knative

import (
"fmt"
"os/exec"
"path"
"testing"
"time"

Expand All @@ -46,13 +48,13 @@ func TestKnative(t *testing.T) {
t.Run("Service combo", func(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "files/knative2.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "knative2"), TestTimeoutLong).Should(Equal(v1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "knative2", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationConditionStatus(ns, "knative2", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue))
Expect(KamelRunWithID(operatorID, ns, "files/knative3.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "knative3"), TestTimeoutLong).Should(Equal(v1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "knative3", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationConditionStatus(ns, "knative3", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue))
Expect(KamelRunWithID(operatorID, ns, "files/knative1.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "knative1"), TestTimeoutLong).Should(Equal(v1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "knative1", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationConditionStatus(ns, "knative1", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue))
// Correct logs
Eventually(IntegrationLogs(ns, "knative1"), TestTimeoutMedium).Should(ContainSubstring("Received from 2: Hello from knative2"))
Eventually(IntegrationLogs(ns, "knative1"), TestTimeoutMedium).Should(ContainSubstring("Received from 3: Hello from knative3"))
Expand Down Expand Up @@ -142,6 +144,21 @@ func TestRunBroker(t *testing.T) {
WithNewTestNamespaceWithKnativeBroker(t, func(ns string) {
operatorID := fmt.Sprintf("camel-k-%s", ns)
Expect(KamelInstallWithID(operatorID, ns, "--trait-profile", "knative").Execute()).To(Succeed())

// We must include namespace privileges to manage Knative objects
testDir := "../../"
kustomizeCmd := exec.Command("kustomize", "edit", "set", "namespace", ns)
kustomizeCmd.Dir = path.Join(testDir, "config/rbac/namespaced/knative")
ExpectExecSucceed(t, kustomizeCmd)
replaceORBKCmd := exec.Command(
"sed", "-i", fmt.Sprintf("s/namespace: .*/namespace: %s/", ns), "operator-role-binding-knative.yaml",
)
replaceORBKCmd.Dir = path.Join(testDir, "config/rbac/namespaced/knative")
ExpectExecSucceed(t, replaceORBKCmd)
kubectlApplyCmd := exec.Command("kubectl", "apply", "-k", ".")
kubectlApplyCmd.Dir = path.Join(testDir, "config/rbac/namespaced/knative")
ExpectExecSucceed(t, kubectlApplyCmd)

Expect(KamelRunWithID(operatorID, ns, "files/knativeevt1.groovy").Execute()).To(Succeed())
Expect(KamelRunWithID(operatorID, ns, "files/knativeevt2.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "knativeevt1"), TestTimeoutLong).Should(Equal(v1.PodRunning))
Expand Down
4 changes: 2 additions & 2 deletions e2e/knative/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestPodTraitWithKnative(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "files/podtest-knative2.groovy",
"--pod-template", "files/template-knative.yaml").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "podtest-knative2"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "podtest-knative2", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationConditionStatus(ns, "podtest-knative2", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
Expect(KamelRunWithID(operatorID, ns, "files/podtest-knative1.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "podtest-knative1"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "podtest-knative1", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationConditionStatus(ns, "podtest-knative1", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "podtest-knative1"), TestTimeoutShort).Should(ContainSubstring("hello from the template"))

Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
Expand Down
17 changes: 17 additions & 0 deletions e2e/knative/support/startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ limitations under the License.
package support

import (
"fmt"
"os/exec"
"path"
"testing"

. "github.com/onsi/gomega"
Expand All @@ -48,4 +51,18 @@ func TestKNativeCamelKInstallStartup(t *testing.T) {
Eventually(Platform(ns.GetName())).ShouldNot(BeNil())
Eventually(PlatformConditionStatus(ns.GetName(), v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort).
Should(Equal(corev1.ConditionTrue))

// We must include namespace privileges to manage Knative objects
testDir := "../../../"
kustomizeCmd := exec.Command("kustomize", "edit", "set", "namespace", ns.GetName())
kustomizeCmd.Dir = path.Join(testDir, "config/rbac/namespaced/knative")
ExpectExecSucceed(t, kustomizeCmd)
replaceORBKCmd := exec.Command(
"sed", "-i", fmt.Sprintf("s/namespace: .*/namespace: %s/", ns.GetName()), "operator-role-binding-knative.yaml",
)
replaceORBKCmd.Dir = path.Join(testDir, "config/rbac/namespaced/knative")
ExpectExecSucceed(t, replaceORBKCmd)
kubectlApplyCmd := exec.Command("kubectl", "apply", "-k", ".")
kubectlApplyCmd.Dir = path.Join(testDir, "config/rbac/namespaced/knative")
ExpectExecSucceed(t, kubectlApplyCmd)
}
4 changes: 2 additions & 2 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ const ciPID = "/tmp/ci-k8s-pid"
const ExpectedCRDs = 8

// camel-k-operator, camel-k-operator-events,
// camel-k-operator-knative, camel-k-operator-leases,
// camel-k-operator-leases,
// camel-k-operator-podmonitors, camel-k-operator-strimzi,
// camel-k-operator-keda
const ExpectedKubePromoteRoles = 7
const ExpectedKubePromoteRoles = 6

// camel-k-edit
// camel-k-operator-custom-resource-definitions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Camel K can bind Kamelets to the broker

Background:
Given Camel K resource polling configuration
| maxAttempts | 40 |
| delayBetweenAttempts | 3000 |

Scenario: Sending event to the custom broker with KameletBinding
Given Camel K integration logger-sink-binding-br is running
Then Camel K integration logger-sink-binding-br should print message: Hello Custom Event from sample-broker

Scenario: Remove resources
Given delete Camel K integration timer-source-binding-br
Given delete Camel K integration logger-sink-binding-br
14 changes: 0 additions & 14 deletions e2e/yaks/common/kamelet-binding-broker/kamelet.feature

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: logger-sink-binding
name: logger-sink-binding-br
spec:
source:
ref:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: timer-source-binding
name: timer-source-binding-br
spec:
source:
ref:
Expand Down
Loading

0 comments on commit b9b5298

Please sign in to comment.