Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1379: make download link available also when installing from operator hub #1380

Merged
merged 2 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -385,6 +401,14 @@ spec:
- patch
- update
- watch
- apiGroups:
- rbac.authorization.k8s.io
resourceNames:
- system:image-builder
resources:
- clusterroles
verbs:
- bind
Comment on lines +404 to +411
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astefanutti this is auto-generated from the OLM role file. Does this need to be a role or a clusterrole? I'm not sure, since you deal with a cluster resource but you want to bind it locally...

I've left it as you did

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, I think a role is enough as it is granted for the operator SA in its namespace.

serviceAccountName: camel-k-operator
strategy: deployment
installModes:
Expand Down
1 change: 1 addition & 0 deletions deploy/olm-catalog/csv-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 37 additions & 0 deletions deploy/operator-role-olm-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ---------------------------------------------------------------------------
# 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: 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
16 changes: 12 additions & 4 deletions deploy/resources.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions pkg/cmd/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -144,6 +146,14 @@ func Run() {
os.Exit(1)
}

// Try to register the OpenShift CLI Download link if possible
installCtx, installCancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer installCancel()
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)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "")
Expand Down
2 changes: 1 addition & 1 deletion pkg/install/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
39 changes: 26 additions & 13 deletions pkg/install/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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",
},
},
Expand All @@ -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
Expand Down Expand Up @@ -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"),
},
},
},
Expand Down