You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2020/02/12 09:48:59 UTC

[camel-k] 04/06: Fix #1223: fix lint

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 65a9e7cd39a3455ed254383106010879af98b3e9
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Mon Feb 10 18:02:46 2020 +0100

    Fix #1223: fix lint
---
 pkg/cmd/install.go        | 10 ++++++----
 pkg/cmd/uninstall.go      |  5 +++--
 pkg/util/olm/available.go |  5 ++---
 pkg/util/olm/operator.go  | 17 ++++++++---------
 4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index eee8a8f..42c5128 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -102,8 +102,10 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *installCmdO
 	cmd.Flags().String("olm-channel", olm.DefaultChannel, "Name of the Camel K channel in the OLM source or marketplace")
 	cmd.Flags().String("olm-source", olm.DefaultSource, "Name of the OLM source providing the Camel K package (defaults to the standard Operator Hub source)")
 	cmd.Flags().String("olm-source-namespace", olm.DefaultSourceNamespace, "Namespace where the OLM source is available")
-	cmd.Flags().String("olm-starting-csv", olm.DefaultStartingCSV, "Allow to install a specific version from the operator source instead of latest available from the channel")
-	cmd.Flags().String("olm-global-namespace", olm.DefaultGlobalNamespace, "A namespace containing an OperatorGroup that defines global scope for the operator (used in combination with the --global flag)")
+	cmd.Flags().String("olm-starting-csv", olm.DefaultStartingCSV, "Allow to install a specific version from the operator source instead of latest available "+
+		"from the channel")
+	cmd.Flags().String("olm-global-namespace", olm.DefaultGlobalNamespace, "A namespace containing an OperatorGroup that defines global scope for the "+
+		"operator (used in combination with the --global flag)")
 
 	// maven settings
 	cmd.Flags().String("local-repository", "", "Location of the local maven repository")
@@ -174,7 +176,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 			return err
 		}
 		var olmAvailable bool
-		if olmAvailable, err = olm.IsAvailable(o.Context, olmClient, o.Namespace); err != nil {
+		if olmAvailable, err = olm.IsAPIAvailable(o.Context, olmClient, o.Namespace); err != nil {
 			return errors.Wrap(err, "error while checking OLM availability. Run with '--olm=false' to skip this check")
 		}
 
@@ -183,7 +185,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 				return errors.Wrap(err, "error while checking permissions to install operator via OLM. Run with '--olm=false' to skip this check")
 			}
 			if !installViaOLM {
-				fmt.Fprintln(cobraCmd.OutOrStdout(), "OLM is available but current user has not enough permissions to create the operator. " +
+				fmt.Fprintln(cobraCmd.OutOrStdout(), "OLM is available but current user has not enough permissions to create the operator. "+
 					"You can either ask your administrator to provide permissions (preferred) or run the install command with the `--olm=false` flag.")
 				os.Exit(1)
 			}
diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go
index 11462f8..ab264b4 100644
--- a/pkg/cmd/uninstall.go
+++ b/pkg/cmd/uninstall.go
@@ -55,7 +55,8 @@ func newCmdUninstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *uninstall
 	cmd.Flags().BoolVar(&options.olmEnabled, "olm", true, "Try to uninstall via OLM (Operator Lifecycle Manager) if available")
 	cmd.Flags().StringVar(&options.olmOptions.OperatorName, "olm-operator-name", olm.DefaultOperatorName, "Name of the Camel K operator in the OLM source or marketplace")
 	cmd.Flags().StringVar(&options.olmOptions.Package, "olm-package", olm.DefaultPackage, "Name of the Camel K package in the OLM source or marketplace")
-	cmd.Flags().StringVar(&options.olmOptions.GlobalNamespace, "olm-global-namespace", olm.DefaultGlobalNamespace, "A namespace containing an OperatorGroup that defines global scope for the operator (used in combination with the --global flag)")
+	cmd.Flags().StringVar(&options.olmOptions.GlobalNamespace, "olm-global-namespace", olm.DefaultGlobalNamespace, "A namespace containing an OperatorGroup that defines "+
+		"global scope for the operator (used in combination with the --global flag)")
 
 	// completion support
 	configureBashAnnotationForFlag(
@@ -99,7 +100,7 @@ func (o *uninstallCmdOptions) uninstall(cmd *cobra.Command, _ []string) error {
 	uninstallViaOLM := false
 	if o.olmEnabled {
 		var err error
-		if uninstallViaOLM, err = olm.IsAvailable(o.Context, c, o.Namespace); err != nil {
+		if uninstallViaOLM, err = olm.IsAPIAvailable(o.Context, c, o.Namespace); err != nil {
 			return errors.Wrap(err, "error while checking OLM availability. Run with '--olm=false' to skip this check")
 		}
 
diff --git a/pkg/util/olm/available.go b/pkg/util/olm/available.go
index 3c1d627..eb4b7da 100644
--- a/pkg/util/olm/available.go
+++ b/pkg/util/olm/available.go
@@ -20,7 +20,6 @@ package olm
 import (
 	"context"
 
-	"github.com/apache/camel-k/pkg/client"
 	kubernetesutils "github.com/apache/camel-k/pkg/util/kubernetes"
 	olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
 	olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
@@ -29,10 +28,10 @@ import (
 	"k8s.io/client-go/kubernetes"
 )
 
-// IsAvailable returns true if we are connected to a cluster with OLM installed
+// IsAPIAvailable returns true if we are connected to a cluster with OLM installed
 //
 // This method should not be called from the operator, as it might require permissions that are not available.
-func IsAvailable(ctx context.Context, c client.Client, namespace string) (bool, error) {
+func IsAPIAvailable(ctx context.Context, c kubernetes.Interface, namespace string) (bool, error) {
 	// check some Knative APIs
 	for _, api := range getOLMGroupVersions() {
 		if installed, err := isAvailable(c, api); err != nil {
diff --git a/pkg/util/olm/operator.go b/pkg/util/olm/operator.go
index 73a84e4..a85c414 100644
--- a/pkg/util/olm/operator.go
+++ b/pkg/util/olm/operator.go
@@ -135,6 +135,7 @@ func HasPermissionToInstall(ctx context.Context, client client.Client, namespace
 	return true, nil
 }
 
+// nolint:unparam
 func checkPermission(client client.Client, group, resource, namespace, name, verb string) (bool, error) {
 	sarReview := &authorizationv1.SelfSubjectAccessReview{
 		Spec: authorizationv1.SelfSubjectAccessReviewSpec{
@@ -191,10 +192,8 @@ func Install(ctx context.Context, client client.Client, namespace string, global
 	}
 	if collection != nil {
 		collection.Add(&sub)
-	} else {
-		if err := client.Create(ctx, &sub); err != nil {
-			return false, err
-		}
+	} else if err := client.Create(ctx, &sub); err != nil {
+		return false, err
 	}
 
 	if !global {
@@ -214,11 +213,10 @@ func Install(ctx context.Context, client client.Client, namespace string, global
 			}
 			if collection != nil {
 				collection.Add(group)
-			} else {
-				if err := client.Create(ctx, group); err != nil {
-					return false, errors.Wrap(err, fmt.Sprintf("namespace %s has no operator group defined and current user is not able to create it. "+
-						"Make sure you have the right roles to install operators from OLM", namespace))
-				}
+			} else if err := client.Create(ctx, group); err != nil {
+				return false, errors.Wrap(err, fmt.Sprintf("namespace %s has no operator group defined and "+
+					"current user is not able to create it. "+
+					"Make sure you have the right roles to install operators from OLM", namespace))
 			}
 		}
 	}
@@ -282,6 +280,7 @@ func findCSV(ctx context.Context, client client.Client, namespace string, option
 	return nil, nil
 }
 
+// nolint:unparam
 func findOperatorGroup(ctx context.Context, client client.Client, namespace string, options Options) (*olmv1.OperatorGroup, error) {
 	opGroupList := olmv1.OperatorGroupList{}
 	if err := client.List(ctx, &opGroupList, runtime.InNamespace(namespace)); err != nil {