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 Nov 7, 2023
1 parent 31e0f39 commit 73e32ea
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 78 deletions.
45 changes: 26 additions & 19 deletions config/manifests/bases/camel-k.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
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
23 changes: 23 additions & 0 deletions config/rbac/knative/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ---------------------------------------------------------------------------
# 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: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- operator-role-knative.yaml
- operator-role-binding-knative.yaml
- operator-cluster-role-binding-custom-resource-definitions.yaml
namespace: test-611551d1-a98e-4391-8486-804cc2658830
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: camel-k-operator-custom-resource-definitions
labels:
app: "camel-k"
subjects:
- kind: ServiceAccount
name: camel-k-operator
namespace: placeholder
roleRef:
kind: ClusterRole
name: camel-k-operator-custom-resource-definitions
apiGroup: rbac.authorization.k8s.io
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
File renamed without changes.
2 changes: 0 additions & 2 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ kind: Kustomization
resources:
- user-cluster-role.yaml
- 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-local-registry.yaml
- operator-role-binding-podmonitors.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
35 changes: 35 additions & 0 deletions docs/modules/ROOT/pages/installation/knative.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
= 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 natively 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 perform the following action:

```bash
kubectl apply -k https://github.com/apache/camel-k/tree/main/config/rbac/knative?ref=v2.1.0
```

The configuration above is using the released version `2.1.0`. You may want to use instead another version or the latest development available on `main` branch. Before continuing with the configuration, you need to make sure to know which are the namespaces on which the Operator is running and on which your Integration is going to run (they could be the same). In order to change it, you must perform some customization locally in a similar fashion:

```bash
git clone https://github.com/apache/camel-k.git
cd camel-k/config/rbac/knative
sed -i "s/namespace: placeholder/namespace: $OPERATOR_NAMESPACE/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: placeholder/namespace: $OPERATOR_NAMESPACE/" operator-role-binding-knative.yaml
kustomize edit set namespace $IT_NAMESPACE
kubectl apply -k .
```

NOTE: you will need `kustomize` CLI available.

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]).
4 changes: 2 additions & 2 deletions e2e/install/kustomize/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ 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
ExpectedKubePromoteRoles = 7
ExpectedKubePromoteRoles = 6

// camel-k-edit
// camel-k-operator-custom-resource-definitions
Expand Down
28 changes: 25 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,26 @@ 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/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/knative")
ExpectExecSucceed(t, replaceORBKCmd)
replaceOCRBCRDCmd := exec.Command(
"sed", "-i", fmt.Sprintf("s/namespace: .*/namespace: %s/", ns), "operator-cluster-role-binding-custom-resource-definitions.yaml",
)
replaceOCRBCRDCmd.Dir = path.Join(testDir, "config/rbac/knative")
ExpectExecSucceed(t, replaceOCRBCRDCmd)
kubectlApplyCmd := exec.Command("kubectl", "apply", "-k", ".")
kubectlApplyCmd.Dir = path.Join(testDir, "config/rbac/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
22 changes: 22 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,23 @@ func TestKNativeCamelKInstallStartup(t *testing.T) {
Eventually(Platform(ns.GetName())).ShouldNot(BeNil())
Eventually(PlatformConditionStatus(ns.GetName(), v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort).
Should(Equal(corev1.ConditionTrue))

testDir := "../../../"
// Configure Knative RBAC
kustomizeCmd := exec.Command("kustomize", "edit", "set", "namespace", ns.GetName())
kustomizeCmd.Dir = path.Join(testDir, "config/rbac/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/knative")
ExpectExecSucceed(t, replaceORBKCmd)
replaceOCRBCRDCmd := exec.Command(
"sed", "-i", fmt.Sprintf("s/namespace: .*/namespace: %s/", ns.GetName()), "operator-cluster-role-binding-custom-resource-definitions.yaml",
)
replaceOCRBCRDCmd.Dir = path.Join(testDir, "config/rbac/knative")
ExpectExecSucceed(t, replaceOCRBCRDCmd)
kubectlApplyCmd := exec.Command("kubectl", "apply", "-k", ".")
kubectlApplyCmd.Dir = path.Join(testDir, "config/rbac/knative")
ExpectExecSucceed(t, kubectlApplyCmd)
}
7 changes: 7 additions & 0 deletions e2e/yaks/common/kamelet-binding-broker/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ config:
namespace:
temporary: true
pre:
- name: knative configuration
run: |
cd ../../../../config/rbac/knative
sed -i "s/namespace: .*/namespace: default/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: .*/namespace: default/" operator-role-binding-knative.yaml
kustomize edit set namespace $YAKS_NAMESPACE
kubectl apply -k .
- name: installation
run: |
kubectl apply -f sample-broker.yaml -n $YAKS_NAMESPACE
Expand Down
7 changes: 7 additions & 0 deletions e2e/yaks/common/kamelet-binding-http/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ config:
namespace:
temporary: true
pre:
- name: knative configuration
run: |
cd ../../../../config/rbac/knative
sed -i "s/namespace: .*/namespace: default/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: .*/namespace: default/" operator-role-binding-knative.yaml
kustomize edit set namespace $YAKS_NAMESPACE
kubectl apply -k .
- name: installation
run: |
kubectl apply -f timer-source.kamelet.yaml -n $YAKS_NAMESPACE
Expand Down
7 changes: 7 additions & 0 deletions e2e/yaks/common/kamelet-binding/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ config:
namespace:
temporary: true
pre:
- name: knative configuration
run: |
cd ../../../../config/rbac/knative
sed -i "s/namespace: .*/namespace: default/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: .*/namespace: default/" operator-role-binding-knative.yaml
kustomize edit set namespace $YAKS_NAMESPACE
kubectl apply -k .
- name: installation
run: |
kubectl apply -f messages-channel.yaml -n $YAKS_NAMESPACE
Expand Down
8 changes: 8 additions & 0 deletions e2e/yaks/common/knative-broker/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
config:
namespace:
temporary: true
pre:
- name: knative configuration
run: |
cd ../../../../config/rbac/knative
sed -i "s/namespace: .*/namespace: default/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: .*/namespace: default/" operator-role-binding-knative.yaml
kustomize edit set namespace $YAKS_NAMESPACE
kubectl apply -k .
post:
- name: print dump
if: env:CI=true && failure()
Expand Down
7 changes: 7 additions & 0 deletions e2e/yaks/common/knative-sinkbinding-http/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ config:
namespace:
temporary: true
pre:
- name: knative configuration
run: |
cd ../../../../config/rbac/knative
sed -i "s/namespace: .*/namespace: default/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: .*/namespace: default/" operator-role-binding-knative.yaml
kustomize edit set namespace $YAKS_NAMESPACE
kubectl apply -k .
- name: installation
run: |
kubectl -n knative-eventing set env deployments eventing-webhook --containers="eventing-webhook" SINK_BINDING_SELECTION_MODE=inclusion
Expand Down
7 changes: 7 additions & 0 deletions e2e/yaks/common/knative-sinkbinding/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ config:
namespace:
temporary: true
pre:
- name: knative configuration
run: |
cd ../../../../config/rbac/knative
sed -i "s/namespace: .*/namespace: default/" operator-cluster-role-binding-custom-resource-definitions.yaml
sed -i "s/namespace: .*/namespace: default/" operator-role-binding-knative.yaml
kustomize edit set namespace $YAKS_NAMESPACE
kubectl apply -k .
- name: installation
run: |
kubectl apply -n $YAKS_NAMESPACE -f messages-channel.yaml
Expand Down
Loading

0 comments on commit 73e32ea

Please sign in to comment.