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 Oct 27, 2023
1 parent e5372dd commit 1f615b4
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 30 deletions.
36 changes: 36 additions & 0 deletions config/rbac/knative/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ---------------------------------------------------------------------------
# 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
namespace: my-ns
# Required in order to perform namespace replacement below
resources:
- operator-service-account.yaml
- operator-role-knative.yaml
- operator-role-binding-knative.yaml
- operator-cluster-role-binding-custom-resource-definitions.yaml
replacements:
- source:
fieldPath: metadata.namespace
kind: ServiceAccount
name: camel-k-operator
targets:
- fieldPaths:
- subjects.[name=camel-k-operator].namespace
select:
kind: ClusterRoleBinding
name: camel-k-operator-custom-resource-definitions
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
File renamed without changes.
23 changes: 23 additions & 0 deletions config/rbac/knative/operator-service-account.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: v1
kind: ServiceAccount
metadata:
name: camel-k-operator
labels:
app: "camel-k"
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
33 changes: 33 additions & 0 deletions docs/modules/ROOT/pages/installation/knative.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
= 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. Something else you need to know is that, by default, that configuration above will use `default` namespace. 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
kustomize edit set namespace <my-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]).
26 changes: 0 additions & 26 deletions pkg/install/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/apache/camel-k/v2/pkg/client"
"github.com/apache/camel-k/v2/pkg/resources"
"github.com/apache/camel-k/v2/pkg/util/envvar"
"github.com/apache/camel-k/v2/pkg/util/knative"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
"github.com/apache/camel-k/v2/pkg/util/minikube"
"github.com/apache/camel-k/v2/pkg/util/openshift"
Expand Down Expand Up @@ -283,24 +282,6 @@ func OperatorOrCollect(ctx context.Context, cmd *cobra.Command, c client.Client,
return err
}

// Additionally, install Knative resources (roles and bindings)
isKnative, err := knative.IsInstalled(c)
if err != nil {
return err
}
if isKnative {
if err := installKnative(ctx, c, cfg.Namespace, customizer, collection, force); err != nil {
return err
}
if err := installClusterRoleBinding(ctx, c, collection, cfg.Namespace, "camel-k-operator-bind-addressable-resolver", "/rbac/operator-cluster-role-binding-addressable-resolver.yaml"); err != nil {
if k8serrors.IsForbidden(err) {
fmt.Fprintln(cmd.ErrOrStderr(), "Warning: the operator will not be able to bind Knative addressable-resolver ClusterRole. Try installing the operator as cluster-admin.")
} else {
return err
}
}
}

if err = installEvents(ctx, c, cfg.Namespace, customizer, collection, force); err != nil {
if k8serrors.IsAlreadyExists(err) {
return err
Expand Down Expand Up @@ -512,13 +493,6 @@ func installKedaBindings(ctx context.Context, c client.Client, namespace string,
)
}

func installKnative(ctx context.Context, c client.Client, namespace string, customizer ResourceCustomizer, collection *kubernetes.Collection, force bool) error {
return ResourcesOrCollect(ctx, c, namespace, collection, force, customizer,
"/rbac/operator-role-knative.yaml",
"/rbac/operator-role-binding-knative.yaml",
)
}

func installEvents(ctx context.Context, c client.Client, namespace string, customizer ResourceCustomizer, collection *kubernetes.Collection, force bool) error {
return ResourcesOrCollect(ctx, c, namespace, collection, force, customizer,
"/rbac/operator-role-events.yaml",
Expand Down

0 comments on commit 1f615b4

Please sign in to comment.