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 2020/03/30 15:56:57 UTC

[camel-k] 01/02: Fix #1379: make download link available also when installing from operator hub

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 7c32ff72106d6c262107252a77ef3b44ab33c582
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Mon Mar 30 16:40:29 2020 +0200

    Fix #1379: make download link available also when installing from operator hub
---
 ...el-k.v1.0.0-snapshot.clusterserviceversion.yaml | 24 +++++++++++++
 deploy/olm-catalog/csv-config.yaml                 |  1 +
 ...-config.yaml => operator-role-olm-cluster.yaml} | 29 +++++++++++-----
 deploy/resources.go                                | 16 ++++++---
 pkg/cmd/operator/operator.go                       |  9 +++++
 pkg/install/cluster.go                             |  2 +-
 pkg/install/openshift.go                           | 39 ++++++++++++++--------
 7 files changed, 93 insertions(+), 27 deletions(-)

diff --git a/deploy/olm-catalog/camel-k/1.0.0-snapshot/camel-k.v1.0.0-snapshot.clusterserviceversion.yaml b/deploy/olm-catalog/camel-k/1.0.0-snapshot/camel-k.v1.0.0-snapshot.clusterserviceversion.yaml
index 24748f7..55cbed7 100644
--- a/deploy/olm-catalog/camel-k/1.0.0-snapshot/camel-k.v1.0.0-snapshot.clusterserviceversion.yaml
+++ b/deploy/olm-catalog/camel-k/1.0.0-snapshot/camel-k.v1.0.0-snapshot.clusterserviceversion.yaml
@@ -154,6 +154,22 @@ spec:
     mediatype: image/svg+xml
   install:
     spec:
+      clusterPermissions:
+      - rules:
+        - apiGroups:
+          - console.openshift.io
+          resources:
+          - consoleclidownloads
+          verbs:
+          - create
+          - delete
+          - deletecollection
+          - get
+          - list
+          - patch
+          - update
+          - watch
+        serviceAccountName: camel-k-operator
       deployments:
       - name: camel-k-operator
         spec:
@@ -385,6 +401,14 @@ spec:
           - patch
           - update
           - watch
+        - apiGroups:
+          - rbac.authorization.k8s.io
+          resourceNames:
+          - system:image-builder
+          resources:
+          - clusterroles
+          verbs:
+          - bind
         serviceAccountName: camel-k-operator
     strategy: deployment
   installModes:
diff --git a/deploy/olm-catalog/csv-config.yaml b/deploy/olm-catalog/csv-config.yaml
index 04a26a6..3075a7a 100644
--- a/deploy/olm-catalog/csv-config.yaml
+++ b/deploy/olm-catalog/csv-config.yaml
@@ -24,3 +24,4 @@ crd-cr-paths:
   - deploy/crd-integration-platform.yaml
 role-paths:
   - deploy/operator-role-olm.yaml
+  - deploy/operator-role-olm-cluster.yaml
diff --git a/deploy/olm-catalog/csv-config.yaml b/deploy/operator-role-olm-cluster.yaml
similarity index 75%
copy from deploy/olm-catalog/csv-config.yaml
copy to deploy/operator-role-olm-cluster.yaml
index 04a26a6..26a56ec 100644
--- a/deploy/olm-catalog/csv-config.yaml
+++ b/deploy/operator-role-olm-cluster.yaml
@@ -15,12 +15,23 @@
 # limitations under the License.
 # ---------------------------------------------------------------------------
 
-operator-path: deploy/operator-deployment.yaml
-crd-cr-paths:
-  - deploy/crd-build.yaml
-  - deploy/crd-camel-catalog.yaml
-  - deploy/crd-integration.yaml
-  - deploy/crd-integration-kit.yaml
-  - deploy/crd-integration-platform.yaml
-role-paths:
-  - deploy/operator-role-olm.yaml
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1beta1
+metadata:
+  name: camel-k-operator
+  labels:
+    app: "camel-k"
+rules:
+- apiGroups:
+  - console.openshift.io
+  resources:
+  - consoleclidownloads
+  verbs:
+  - create
+  - delete
+  - deletecollection
+  - get
+  - list
+  - patch
+  - update
+  - watch
diff --git a/deploy/resources.go b/deploy/resources.go
index f21b32a..6196a63 100644
--- a/deploy/resources.go
+++ b/deploy/resources.go
@@ -193,12 +193,19 @@ var assets = func() http.FileSystem {
 
 			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x54\xc1\x6e\x1b\x37\x10\xbd\xf3\x2b\x1e\xb4\x97\xa4\xb0\xe4\xa6\xa7\x42\x3d\xa9\x8e\xdd\x0a\x0d\x24\xc0\xab\x34\xc8\x71\x96\x3b\x5a\xb1\xe6\x72\x58\x92\x2b\xd9\xfd\xfa\x82\xd4\x2a\x91\xa3\x04\xe8\x21\xa8\xf7\xa2\x21\x77\xf6\xcd\x9b\xf7\x46\x53\x61\xfa\xfd\x1e\x55\xe1\x9d\xd1\xec\x22\xb7\x48\x82\xb4\x63\x2c\x3c\xe9\x1d\xa3\x96\x6d\x3a\x50\x60\xdc\xc9\xe0\x5a\x4a\x46\x1c\x5e\x2d\xea\xbb\xd7\x18\x5c\xcb\x01\xe2\x18\x [...]
 		},
+		"/operator-role-olm-cluster.yaml": &vfsgen۰CompressedFileInfo{
+			name:             "operator-role-olm-cluster.yaml",
+			modTime:          time.Time{},
+			uncompressedSize: 1249,
+
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x53\xc1\x6e\xdb\x46\x10\xbd\xef\x57\x3c\x88\x97\x04\xb0\xe8\xa6\xa7\x42\x3d\xa9\x8e\xdd\x12\x0d\x24\xc0\x54\x1a\xe4\x38\x22\x47\xe4\xc0\xcb\x1d\x76\x76\x69\xc6\xfd\xfa\x62\x29\xa9\xb1\xd1\x6b\xf6\xc2\xe1\xf2\xf1\xcd\x7b\xfb\x66\x0b\xac\x7f\xdc\x72\x05\x3e\x49\xc3\x21\x72\x8b\xa4\x48\x3d\x63\x3b\x52\xd3\x33\x6a\x3d\xa5\x99\x8c\xf1\xa0\x53\x68\x29\x89\x06\xbc\xdb\xd6\x0f\xef\x31\x85\x96\x0d\x1a\x18\x6a\x18\xd4\xd8\x [...]
+		},
 		"/operator-role-olm.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "operator-role-olm.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 3684,
+			uncompressedSize: 3685,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x56\x41\x8f\xdb\x36\x13\xbd\xeb\x57\x0c\xac\x4b\xf2\x61\x2d\x7f\xe9\xa9\x70\x4f\x6e\xb2\xdb\x1a\x0d\x6c\x60\xed\x34\xc8\x71\x44\x8d\xa5\xa9\x29\x0e\x4b\x52\x76\xdc\x5f\x5f\x88\x92\x77\xe5\xd5\x6e\x37\x05\x02\xb8\xbe\x98\x22\xc7\x6f\xde\xbc\x37\x1a\x33\x85\xe9\xf7\xfb\x24\x29\x7c\x64\x45\xc6\x53\x01\x41\x20\x54\x04\x0b\x8b\xaa\x22\xd8\xc8\x2e\x1c\xd1\x11\xdc\x49\x63\x0a\x0c\x2c\x06\xde\x2c\x36\x77\x6f\xa1\x31\x05\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x56\x41\x8f\xdb\x36\x13\xbd\xeb\x57\x0c\xac\x4b\xf2\x61\x2d\x7f\xe9\xa9\x70\x4f\x6e\xb2\xdb\x1a\x0d\x6c\x60\xed\x34\xc8\x71\x44\x8d\xa5\xa9\x29\x0e\x4b\x52\x76\xdc\x5f\x5f\x88\x92\x77\xe5\xd5\x6e\x37\x05\x02\xb8\xbe\x98\x22\xc7\x6f\xde\xbc\x37\x1a\x33\x85\xe9\xf7\xfb\x24\x29\x7c\x64\x45\xc6\x53\x01\x41\x20\x54\x04\x0b\x8b\xaa\x22\xd8\xc8\x2e\x1c\xd1\x11\xdc\x49\x63\x0a\x0c\x2c\x06\xde\x2c\x36\x77\x6f\xa1\x31\x05\x [...]
 		},
 		"/operator-role-openshift.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "operator-role-openshift.yaml",
@@ -217,9 +224,9 @@ var assets = func() http.FileSystem {
 		"/operator.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "operator.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 2101,
+			uncompressedSize: 2112,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\xc1\x6e\xe3\x36\x10\xbd\xeb\x2b\x1e\xac\xcb\x2e\x10\xdb\x9b\x3d\xaa\x27\xd5\x71\xb0\x42\x53\xd9\xb0\xbc\x0d\xf6\x54\x4c\xa8\x91\x44\x84\x22\x55\x92\x8a\x56\x7f\x5f\x50\xb6\x13\x3b\xbb\x4d\x7b\x08\xca\x93\xa4\x99\x79\xf3\xde\xcc\x13\x63\xcc\xdf\xef\x44\x31\xee\xa4\x60\xed\xb8\x84\x37\xf0\x0d\x23\xed\x48\x34\x8c\xc2\x54\x7e\x20\xcb\xb8\x35\xbd\x2e\xc9\x4b\xa3\xf1\x21\x2d\x6e\x3f\xa2\xd7\x25\x5b\x18\xcd\x30\x16\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\xc1\x6e\xe3\x36\x10\xbd\xeb\x2b\x1e\xac\xcb\x2e\x10\xdb\x49\x76\x4f\xea\x49\x4d\x1c\xac\xd0\x54\x36\x2c\x6f\x83\x3d\x15\x13\x6a\x24\x11\xa1\x48\x95\xa4\xa2\xd5\xdf\x17\x94\xed\xc4\xc9\x6e\xd3\x1e\x82\xf2\x24\x69\x86\x6f\xde\x9b\x79\x9a\x18\xf3\xf7\x3b\x51\x8c\x5b\x29\x58\x3b\x2e\xe1\x0d\x7c\xc3\x48\x3b\x12\x0d\xa3\x30\x95\x1f\xc8\x32\x6e\x4c\xaf\x4b\xf2\xd2\x68\x7c\x48\x8b\x9b\x8f\xe8\x75\xc9\x16\x46\x33\x8c\x [...]
 		},
 		"/platform-cr.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "platform-cr.yaml",
@@ -366,6 +373,7 @@ var assets = func() http.FileSystem {
 		fs["/operator-role-events.yaml"].(os.FileInfo),
 		fs["/operator-role-knative.yaml"].(os.FileInfo),
 		fs["/operator-role-kubernetes.yaml"].(os.FileInfo),
+		fs["/operator-role-olm-cluster.yaml"].(os.FileInfo),
 		fs["/operator-role-olm.yaml"].(os.FileInfo),
 		fs["/operator-role-openshift.yaml"].(os.FileInfo),
 		fs["/operator-service-account.yaml"].(os.FileInfo),
diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go
index 5ad9160..8ed6f7c 100644
--- a/pkg/cmd/operator/operator.go
+++ b/pkg/cmd/operator/operator.go
@@ -27,6 +27,7 @@ import (
 	"time"
 
 	"github.com/apache/camel-k/pkg/client"
+	"github.com/apache/camel-k/pkg/install"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/operator-framework/operator-sdk/pkg/k8sutil"
 	"github.com/operator-framework/operator-sdk/pkg/leader"
@@ -59,6 +60,7 @@ func printVersion() {
 	log.Info(fmt.Sprintf("Buildah Version: %v", defaults.BuildahVersion))
 	log.Info(fmt.Sprintf("Kaniko Version: %v", defaults.KanikoVersion))
 	log.Info(fmt.Sprintf("Camel K Operator Version: %v", defaults.Version))
+	log.Info(fmt.Sprintf("Camel K Default Runtime Version: %v", defaults.DefaultRuntimeVersion))
 	log.Info(fmt.Sprintf("Camel K Git Commit: %v", GitCommit))
 }
 
@@ -136,6 +138,13 @@ func Run() {
 		os.Exit(1)
 	}
 
+	// Try to register the OpenShift CLI Download link if possible
+	installCtx, _ := context.WithTimeout(context.TODO(), 30 * time.Second)
+	if err := install.OpenShiftConsoleDownloadLink(installCtx, c); err != nil {
+		log.Info("Cannot install OpenShift CLI download link: skipping.")
+		log.V(8).Info("Error while installing OpenShift CLI download link", "error", err)
+	}
+
 	log.Info("Registering Components.")
 
 	// Setup Scheme for all resources
diff --git a/pkg/install/cluster.go b/pkg/install/cluster.go
index 7d06d2c..9b67062 100644
--- a/pkg/install/cluster.go
+++ b/pkg/install/cluster.go
@@ -82,7 +82,7 @@ func SetupClusterWideResourcesOrCollect(ctx context.Context, clientProvider clie
 	}
 
 	// Install OpenShift Console download links if possible
-	err = installOpenShiftConsoleDownloadLink(ctx, c)
+	err = OpenShiftConsoleDownloadLink(ctx, c)
 	if err != nil {
 		return err
 	}
diff --git a/pkg/install/openshift.go b/pkg/install/openshift.go
index 66c85fd..82f128e 100644
--- a/pkg/install/openshift.go
+++ b/pkg/install/openshift.go
@@ -36,11 +36,27 @@ import (
 )
 
 const (
-	kamelCliDownloadName   = "kamel-cli"
 	kamelVersionAnnotation = "camel.apache.org/version"
 )
 
-func installOpenShiftConsoleDownloadLink(ctx context.Context, c client.Client) error {
+// The following variables may be overridden at build time
+var (
+	// KamelCLIDownloadName --
+	KamelCLIDownloadName = "kamel-cli"
+	// KamelCLIDownloadDisplayName is the name as seen in the download page
+	KamelCLIDownloadDisplayName = "kamel - Apache Camel K Command Line Interface"
+	// KamelCLIDownloadDescription is the description as seen in the download page
+	KamelCLIDownloadDescription = "Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless superpowers.\n\n" +
+		"The `kamel` binary can be used to both configure the cluster and run integrations. " +
+		"Once you've downloaded the `kamel` binary, log into the cluster using the `oc` client tool and start using the `kamel` CLI.\n\n" +
+		"You can run `kamel help` to list the available commands or go to the [Camel K Website](https://camel.apache.org/projects/camel-k/) for more information."
+
+	// KamelCLIDownloadURLTemplate is the download template with 3 missing parameters (version, version, os)
+	KamelCLIDownloadURLTemplate = "https://github.com/apache/camel-k/releases/download/%s/camel-k-client-%s-%s-64bit.tar.gz"
+)
+
+// OpenShiftConsoleDownloadLink installs the download link for the OpenShift console
+func OpenShiftConsoleDownloadLink(ctx context.Context, c client.Client) error {
 	// Check the ConsoleCLIDownload CRD is present, which should be starting OpenShift version 4.2.
 	// That check is also enough to exclude Kubernetes clusters.
 	ok, err := isAPIResourceInstalled(c, "console.openshift.io/v1", reflect.TypeOf(console.ConsoleCLIDownload{}).Name())
@@ -56,7 +72,7 @@ func installOpenShiftConsoleDownloadLink(ctx context.Context, c client.Client) e
 			ResourceAttributes: &authorization.ResourceAttributes{
 				Group:    "console.openshift.io",
 				Resource: "consoleclidownloads",
-				Name:     kamelCliDownloadName,
+				Name:     KamelCLIDownloadName,
 				Verb:     "create",
 			},
 		},
@@ -75,7 +91,7 @@ func installOpenShiftConsoleDownloadLink(ctx context.Context, c client.Client) e
 
 	// Check for an existing ConsoleCLIDownload resource
 	existing := &console.ConsoleCLIDownload{}
-	err = c.Get(ctx, types.NamespacedName{Name: kamelCliDownloadName}, existing)
+	err = c.Get(ctx, types.NamespacedName{Name: KamelCLIDownloadName}, existing)
 	if err != nil {
 		if errors.IsNotFound(err) {
 			existing = nil
@@ -116,26 +132,23 @@ func installOpenShiftConsoleDownloadLink(ctx context.Context, c client.Client) e
 			Annotations: map[string]string{
 				kamelVersionAnnotation: defaults.Version,
 			},
-			Name: kamelCliDownloadName,
+			Name: KamelCLIDownloadName,
 		},
 		Spec: console.ConsoleCLIDownloadSpec{
-			DisplayName: "kamel - Apache Camel K Command Line Interface",
-			Description: "Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless superpowers.\n\n" +
-				"The `kamel` binary can be used to both configure the cluster and run integrations. " +
-				"Once you've downloaded the `kamel` binary, log into the cluster using the `oc` client tool and start using the `kamel` CLI.\n\n" +
-				"You can run `kamel help` to list the available commands or go to the [Camel K Website](https://camel.apache.org/projects/camel-k/) for more information.",
+			DisplayName: KamelCLIDownloadDisplayName,
+			Description: KamelCLIDownloadDescription,
 			Links: []console.Link{
 				{
 					Text: "Download the kamel binary for Linux",
-					Href: fmt.Sprintf("https://github.com/apache/camel-k/releases/download/%s/camel-k-client-%s-linux-64bit.tar.gz", defaults.Version, defaults.Version),
+					Href: fmt.Sprintf(KamelCLIDownloadURLTemplate, defaults.Version, defaults.Version, "linux"),
 				},
 				{
 					Text: "Download the kamel binary for Mac",
-					Href: fmt.Sprintf("https://github.com/apache/camel-k/releases/download/%s/camel-k-client-%s-mac-64bit.tar.gz", defaults.Version, defaults.Version),
+					Href: fmt.Sprintf(KamelCLIDownloadURLTemplate, defaults.Version, defaults.Version, "mac"),
 				},
 				{
 					Text: "Download the kamel binary for Windows",
-					Href: fmt.Sprintf("https://github.com/apache/camel-k/releases/download/%s/camel-k-client-%s-windows-64bit.tar.gz", defaults.Version, defaults.Version),
+					Href: fmt.Sprintf(KamelCLIDownloadURLTemplate, defaults.Version, defaults.Version, "windows"),
 				},
 			},
 		},