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

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

commit 734dc8354921d145e5eb9a02500e3f2e35b757a6
Author: Christoph Deppisch <cdeppi...@redhat.com>
AuthorDate: Thu Jun 9 08:37:52 2022 +0200

    Fix #2177: Fix golangci-lint errors
---
 pkg/cmd/bind.go                          | 16 ++++++++--------
 pkg/cmd/install.go                       | 14 ++++++++------
 pkg/cmd/operator.go                      | 10 +++++-----
 pkg/cmd/operator/operator.go             |  8 +++++---
 pkg/cmd/run.go                           | 16 ++++++++--------
 pkg/cmd/version.go                       |  6 +++---
 pkg/controller/kameletbinding/monitor.go |  4 ++--
 pkg/platform/platform.go                 |  7 ++++---
 pkg/trait/environment.go                 |  4 ++--
 9 files changed, 45 insertions(+), 40 deletions(-)

diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index b86b08e88..0632c8d87 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -85,7 +85,7 @@ type bindCmdOptions struct {
        SkipChecks   bool     `mapstructure:"skip-checks" yaml:",omitempty"`
        Steps        []string `mapstructure:"steps" yaml:",omitempty"`
        Traits       []string `mapstructure:"traits" yaml:",omitempty"`
-       OperatorId   string   `mapstructure:"operator-id" yaml:",omitempty"`
+       OperatorID   string   `mapstructure:"operator-id" yaml:",omitempty"`
        Annotations  []string `mapstructure:"annotations" yaml:",omitempty"`
        Force        bool     `mapstructure:"force" yaml:",omitempty"`
 }
@@ -116,7 +116,7 @@ func (o *bindCmdOptions) validate(cmd *cobra.Command, args 
[]string) error {
                return errors.New("source or sink arguments are missing")
        }
 
-       if o.OperatorId == "" {
+       if o.OperatorID == "" {
                return fmt.Errorf("cannot use empty operator id")
        }
 
@@ -237,24 +237,24 @@ func (o *bindCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
                binding.Annotations = make(map[string]string)
        }
 
-       if o.OperatorId != "" {
-               if pl, err := platformutil.LookupForPlatformName(o.Context, 
client, o.OperatorId); err != nil {
+       if o.OperatorID != "" {
+               if pl, err := platformutil.LookupForPlatformName(o.Context, 
client, o.OperatorID); err != nil {
                        if k8serrors.IsForbidden(err) {
-                               o.PrintfVerboseOutf(cmd, "Unable to verify 
existence of operator id [%s] due to lack of user privileges\n", o.OperatorId)
+                               o.PrintfVerboseOutf(cmd, "Unable to verify 
existence of operator id [%s] due to lack of user privileges\n", o.OperatorID)
                        } else {
                                return err
                        }
                } else if pl == nil {
                        if o.Force {
-                               o.PrintfVerboseOutf(cmd, "Unable to find 
operator with given id [%s] - Kamelet binding may not be reconciled and get 
stuck in waiting state\n", o.OperatorId)
+                               o.PrintfVerboseOutf(cmd, "Unable to find 
operator with given id [%s] - Kamelet binding may not be reconciled and get 
stuck in waiting state\n", o.OperatorID)
                        } else {
-                               return errors.New(fmt.Sprintf("unable to find 
integration platform for given operator id '%s', use --force option or make 
sure to use a proper operator id", o.OperatorId))
+                               return fmt.Errorf("unable to find integration 
platform for given operator id '%s', use --force option or make sure to use a 
proper operator id", o.OperatorID)
                        }
                }
        }
 
        // --operator-id={id} is a syntax sugar for '--annotation 
camel.apache.org/operator.id={id}'
-       binding.SetOperatorID(strings.TrimSpace(o.OperatorId))
+       binding.SetOperatorID(strings.TrimSpace(o.OperatorID))
 
        for _, annotation := range o.Annotations {
                parts := strings.SplitN(annotation, "=", 2)
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 1efba233e..2176f22db 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -180,7 +180,7 @@ type installCmdOptions struct {
        OutputFormat             string   `mapstructure:"output"`
        RuntimeVersion           string   `mapstructure:"runtime-version"`
        BaseImage                string   `mapstructure:"base-image"`
-       OperatorId               string   `mapstructure:"operator-id"`
+       OperatorID               string   `mapstructure:"operator-id"`
        OperatorImage            string   `mapstructure:"operator-image"`
        OperatorImagePullPolicy  string   
`mapstructure:"operator-image-pull-policy"`
        BuildStrategy            string   `mapstructure:"build-strategy"`
@@ -221,7 +221,7 @@ func (o *installCmdOptions) install(cobraCmd 
*cobra.Command, _ []string) error {
        clientProvider := client.Provider{Get: o.NewCmdClient}
 
        // --operator-id={id} is a syntax sugar for '--operator-env-vars 
KAMEL_OPERATOR_ID={id}'
-       o.EnvVars = append(o.EnvVars, fmt.Sprintf("KAMEL_OPERATOR_ID=%s", 
strings.TrimSpace(o.OperatorId)))
+       o.EnvVars = append(o.EnvVars, fmt.Sprintf("KAMEL_OPERATOR_ID=%s", 
strings.TrimSpace(o.OperatorID)))
 
        // --skip-default-kamelets-setup is a syntax sugar for 
'--operator-env-vars KAMEL_INSTALL_DEFAULT_KAMELETS=false'
        if o.SkipDefaultKameletsSetup {
@@ -303,16 +303,18 @@ func (o *installCmdOptions) install(cobraCmd 
*cobra.Command, _ []string) error {
 
                namespace := o.Namespace
 
-               platformName := platformutil.DefaultPlatformName
+               var platformName string
                if operatorID != "" {
                        platformName = operatorID
+               } else {
+                       platformName = platformutil.DefaultPlatformName
                }
 
                if !o.SkipOperatorSetup && !installViaOLM {
                        if ok, err := isInstallAllowed(o.Context, c, 
platformName, o.Force, cobraCmd.OutOrStdout()); err != nil {
                                return err
                        } else if !ok {
-                               return errors.New(fmt.Sprintf("installation not 
allowed because operator with id '%s' already exists, use the --force option to 
skip this check", platformName))
+                               return fmt.Errorf("installation not allowed 
because operator with id '%s' already exists, use the --force option to skip 
this check", platformName)
                        }
 
                        cfg := install.OperatorConfiguration{
@@ -528,7 +530,7 @@ func isInstallAllowed(ctx context.Context, c client.Client, 
operatorID string, f
        pl, err := platformutil.LookupForPlatformName(ctx, c, operatorID)
 
        if pl != nil && force {
-               fmt.Fprintln(out, fmt.Sprintf("Overwriting existing operator 
with id '%s'", operatorID))
+               fmt.Fprintf(out, "Overwriting existing operator with id 
'%s'\n", operatorID)
                return true, nil
        }
 
@@ -636,7 +638,7 @@ func (o *installCmdOptions) decode(cmd *cobra.Command, _ 
[]string) error {
 func (o *installCmdOptions) validate(_ *cobra.Command, _ []string) error {
        var result error
 
-       if o.OperatorId == "" {
+       if o.OperatorID == "" {
                result = multierr.Append(result, fmt.Errorf("cannot use empty 
operator id"))
        }
 
diff --git a/pkg/cmd/operator.go b/pkg/cmd/operator.go
index b2570a356..9bb66a51f 100644
--- a/pkg/cmd/operator.go
+++ b/pkg/cmd/operator.go
@@ -57,14 +57,14 @@ type operatorCmdOptions struct {
 
 func (o *operatorCmdOptions) run(_ *cobra.Command, _ []string) {
 
-       leaderElectionId := o.LeaderElectionID
-       if leaderElectionId == "" {
+       leaderElectionID := o.LeaderElectionID
+       if leaderElectionID == "" {
                if defaults.OperatorID() != "" {
-                       leaderElectionId = fmt.Sprintf("%s-lock", 
defaults.OperatorID())
+                       leaderElectionID = fmt.Sprintf("%s-lock", 
defaults.OperatorID())
                } else {
-                       leaderElectionId = platform.OperatorLockName
+                       leaderElectionID = platform.OperatorLockName
                }
        }
 
-       operator.Run(o.HealthPort, o.MonitoringPort, o.LeaderElection, 
leaderElectionId)
+       operator.Run(o.HealthPort, o.MonitoringPort, o.LeaderElection, 
leaderElectionID)
 }
diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go
index 2ae7436e2..4d108d6a3 100644
--- a/pkg/cmd/operator/operator.go
+++ b/pkg/cmd/operator/operator.go
@@ -245,10 +245,12 @@ func Run(healthPort, monitoringPort int32, leaderElection 
bool, leaderElectionID
        exitOnError(mgr.Start(signals.SetupSignalHandler()), "manager exited 
non-zero")
 }
 
-// findOrCreateIntegrationPlatform create default integration platform in 
operator namespace if not already exists
+// findOrCreateIntegrationPlatform create default integration platform in 
operator namespace if not already exists.
 func findOrCreateIntegrationPlatform(ctx context.Context, c client.Client, 
operatorNamespace string) error {
-       platformName := defaults.OperatorID()
-       if platformName == "" {
+       var platformName string
+       if defaults.OperatorID() != "" {
+               platformName = defaults.OperatorID()
+       } else {
                platformName = platform.DefaultPlatformName
        }
 
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index a3ad6b6e1..5d46a9fb0 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -140,7 +140,7 @@ type runCmdOptions struct {
        IntegrationKit  string   `mapstructure:"kit" yaml:",omitempty"`
        IntegrationName string   `mapstructure:"name" yaml:",omitempty"`
        Profile         string   `mapstructure:"profile" yaml:",omitempty"`
-       OperatorId      string   `mapstructure:"operator-id" yaml:",omitempty"`
+       OperatorID      string   `mapstructure:"operator-id" yaml:",omitempty"`
        OutputFormat    string   `mapstructure:"output" yaml:",omitempty"`
        PodTemplate     string   `mapstructure:"pod-template" yaml:",omitempty"`
        Connects        []string `mapstructure:"connects" yaml:",omitempty"`
@@ -244,7 +244,7 @@ func (o *runCmdOptions) validateArgs(cmd *cobra.Command, 
args []string) error {
 }
 
 func (o *runCmdOptions) validate() error {
-       if o.OperatorId == "" {
+       if o.OperatorID == "" {
                return fmt.Errorf("cannot use empty operator id")
        }
 
@@ -552,24 +552,24 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd 
*cobra.Command, c client.C
                integration.Annotations = make(map[string]string)
        }
 
-       if o.OperatorId != "" {
-               if pl, err := platformutil.LookupForPlatformName(o.Context, c, 
o.OperatorId); err != nil {
+       if o.OperatorID != "" {
+               if pl, err := platformutil.LookupForPlatformName(o.Context, c, 
o.OperatorID); err != nil {
                        if k8serrors.IsForbidden(err) {
-                               o.PrintfVerboseOutf(cmd, "Unable to verify 
existence of operator id [%s] due to lack of user privileges\n", o.OperatorId)
+                               o.PrintfVerboseOutf(cmd, "Unable to verify 
existence of operator id [%s] due to lack of user privileges\n", o.OperatorID)
                        } else {
                                return nil, err
                        }
                } else if pl == nil {
                        if o.Force {
-                               o.PrintfVerboseOutf(cmd, "Unable to find 
operator with given id [%s] - integration may not be reconciled and get stuck 
in waiting state\n", o.OperatorId)
+                               o.PrintfVerboseOutf(cmd, "Unable to find 
operator with given id [%s] - integration may not be reconciled and get stuck 
in waiting state\n", o.OperatorID)
                        } else {
-                               return nil, errors.New(fmt.Sprintf("unable to 
find integration platform for given operator id '%s', use --force option or 
make sure to use a proper operator id", o.OperatorId))
+                               return nil, fmt.Errorf("unable to find 
integration platform for given operator id '%s', use --force option or make 
sure to use a proper operator id", o.OperatorID)
                        }
                }
        }
 
        // --operator-id={id} is a syntax sugar for '--annotation 
camel.apache.org/operator.id={id}'
-       integration.SetOperatorID(strings.TrimSpace(o.OperatorId))
+       integration.SetOperatorID(strings.TrimSpace(o.OperatorID))
 
        for _, annotation := range o.Annotations {
                parts := strings.SplitN(annotation, "=", 2)
diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go
index 1a6055ffe..6cec424d6 100644
--- a/pkg/cmd/version.go
+++ b/pkg/cmd/version.go
@@ -133,10 +133,10 @@ func operatorInfo(ctx context.Context, c client.Client, 
namespace string) (map[s
        platform, err := platformutil.GetOrFindLocal(ctx, c, namespace)
        if err != nil && k8serrors.IsNotFound(err) {
                // find default operator platform in any namespace
-               if defaultPlatform, _ := 
platformutil.LookupForPlatformName(ctx, c, platformutil.DefaultPlatformName); 
defaultPlatform == nil {
-                       return nil, err
-               } else {
+               if defaultPlatform, _ := 
platformutil.LookupForPlatformName(ctx, c, platformutil.DefaultPlatformName); 
defaultPlatform != nil {
                        platform = defaultPlatform
+               } else {
+                       return nil, err
                }
        } else if err != nil {
                return nil, err
diff --git a/pkg/controller/kameletbinding/monitor.go 
b/pkg/controller/kameletbinding/monitor.go
index d6465573c..841a313fc 100644
--- a/pkg/controller/kameletbinding/monitor.go
+++ b/pkg/controller/kameletbinding/monitor.go
@@ -73,7 +73,7 @@ func (action *monitorAction) Handle(ctx context.Context, 
kameletbinding *v1alpha
                return nil, errors.Wrapf(err, "could not load integration for 
KameletBinding %q", kameletbinding.Name)
        }
 
-       operatorIdChanged := v1.GetOperatorIDAnnotation(kameletbinding) != "" &&
+       operatorIDChanged := v1.GetOperatorIDAnnotation(kameletbinding) != "" &&
                (v1.GetOperatorIDAnnotation(kameletbinding) != 
v1.GetOperatorIDAnnotation(&it))
 
        // Check if the integration needs to be changed
@@ -82,7 +82,7 @@ func (action *monitorAction) Handle(ctx context.Context, 
kameletbinding *v1alpha
                return nil, err
        }
 
-       if !equality.Semantic.DeepDerivative(expected.Spec, it.Spec) || 
operatorIdChanged {
+       if !equality.Semantic.DeepDerivative(expected.Spec, it.Spec) || 
operatorIDChanged {
                action.L.Info("Monitor: KameletBinding needs a rebuild")
 
                // KameletBinding has changed and needs rebuild
diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go
index 42c88cd82..84119b696 100644
--- a/pkg/platform/platform.go
+++ b/pkg/platform/platform.go
@@ -32,7 +32,7 @@ const (
        DefaultPlatformName = "camel-k"
 )
 
-// LookupForPlatformName finds integration platform with given operator id as 
name in any namespace
+// LookupForPlatformName finds integration platform with given operator id as 
name in any namespace.
 func LookupForPlatformName(ctx context.Context, c k8sclient.Reader, name 
string) (*v1.IntegrationPlatform, error) {
        platformList := v1.NewIntegrationPlatformList()
 
@@ -86,7 +86,7 @@ func getOrFindForResource(ctx context.Context, c 
k8sclient.Reader, o k8sclient.O
                        platformName = ik.Status.Platform
                }
 
-               return getOrFind(ctx, c, ik.Namespace, ik.Status.Platform, 
active, local)
+               return getOrFind(ctx, c, ik.Namespace, platformName, active, 
local)
        }
        return find(ctx, c, o.GetNamespace(), active, local)
 }
@@ -178,7 +178,8 @@ func ListPrimaryPlatforms(ctx context.Context, c 
k8sclient.Reader, namespace str
        }
 
        filtered := v1.NewIntegrationPlatformList()
-       for _, pl := range lst.Items {
+       for i := range lst.Items {
+               pl := lst.Items[i]
                if !IsSecondary(&pl) {
                        filtered.Items = append(filtered.Items, pl)
                }
diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go
index 7155a7552..b9c1ac315 100644
--- a/pkg/trait/environment.go
+++ b/pkg/trait/environment.go
@@ -37,7 +37,7 @@ type environmentTrait struct {
 const (
        envVarNamespace            = "NAMESPACE"
        envVarPodName              = "POD_NAME"
-       envVarOperatorId           = "CAMEL_K_OPERATOR_ID"
+       envVarOperatorID           = "CAMEL_K_OPERATOR_ID"
        envVarCamelKVersion        = "CAMEL_K_VERSION"
        envVarCamelKIntegration    = "CAMEL_K_INTEGRATION"
        envVarCamelKRuntimeVersion = "CAMEL_K_RUNTIME_VERSION"
@@ -71,7 +71,7 @@ func (t *environmentTrait) Configure(e *Environment) (bool, 
error) {
 
 func (t *environmentTrait) Apply(e *Environment) error {
        envvar.SetVal(&e.EnvVars, envVarCamelKVersion, defaults.Version)
-       envvar.SetVal(&e.EnvVars, envVarOperatorId, defaults.OperatorID())
+       envvar.SetVal(&e.EnvVars, envVarOperatorID, defaults.OperatorID())
        if e.Integration != nil {
                envvar.SetVal(&e.EnvVars, envVarCamelKIntegration, 
e.Integration.Name)
        }

Reply via email to