You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/02/04 13:12:07 UTC

[camel-k] branch master updated: chore(lint): fix lint fidings and standardize traits initialization

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

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


The following commit(s) were added to refs/heads/master by this push:
     new df987e5  chore(lint): fix lint fidings and standardize traits initialization
df987e5 is described below

commit df987e596a35825979b0ddb0d8d57ce8d5a62a96
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Feb 4 12:14:45 2019 +0100

    chore(lint): fix lint fidings and standardize traits initialization
---
 pkg/cmd/run.go                             |  2 +-
 pkg/controller/integration/build_image.go  |  2 +-
 pkg/controller/integrationcontext/build.go |  2 +-
 pkg/trait/builder.go                       |  4 +---
 pkg/trait/classpath.go                     |  4 +---
 pkg/trait/debug.go                         |  4 +---
 pkg/trait/dependencies.go                  |  4 +---
 pkg/trait/deployment.go                    |  4 +---
 pkg/trait/environment.go                   |  4 +---
 pkg/trait/images.go                        |  4 +---
 pkg/trait/ingress.go                       |  6 ++----
 pkg/trait/istio.go                         |  6 ++----
 pkg/trait/jolokia.go                       | 28 +++++++++++++---------------
 pkg/trait/knative.go                       |  4 +---
 pkg/trait/knative_service.go               |  4 +---
 pkg/trait/owner.go                         |  4 +---
 pkg/trait/prometheus.go                    |  6 ++----
 pkg/trait/rest.go                          |  4 +---
 pkg/trait/route.go                         |  4 +---
 pkg/trait/service.go                       |  6 ++----
 pkg/trait/springboot.go                    |  4 +---
 pkg/util/kubernetes/log/util.go            |  3 ++-
 pkg/util/maven/maven.go                    |  3 ++-
 23 files changed, 41 insertions(+), 75 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 3e16958..5c6f547 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -472,7 +472,7 @@ func (*runCmdOptions) configureTrait(integration *v1alpha1.Integration, config s
 	}
 
 	if len(spec.Configuration[prop]) > 0 {
-		// Aggregate multiple occurences of the same option into a comma-separated string,
+		// Aggregate multiple occurrences of the same option into a comma-separated string,
 		// attempting to follow POSIX conventions.
 		// This enables to execute:
 		// $ kamel run -t <trait>.<property>=<value_1> ... -t <trait>.<property>=<value_N>
diff --git a/pkg/controller/integration/build_image.go b/pkg/controller/integration/build_image.go
index 1d4270a..8ae8fa4 100644
--- a/pkg/controller/integration/build_image.go
+++ b/pkg/controller/integration/build_image.go
@@ -71,7 +71,7 @@ func (action *buildImageAction) Handle(ctx context.Context, integration *v1alpha
 	return nil
 }
 
-func (action *buildImageAction) handleBuildImageRunning(ctx context.Context, integration *v1alpha1.Integration) error {
+func (action *buildImageAction) handleBuildImageRunning(_ context.Context, integration *v1alpha1.Integration) error {
 	b, err := platform.GetPlatformBuilder(action.client, integration.Namespace)
 	if err != nil {
 		return err
diff --git a/pkg/controller/integrationcontext/build.go b/pkg/controller/integrationcontext/build.go
index 0ec16b3..91e1762 100644
--- a/pkg/controller/integrationcontext/build.go
+++ b/pkg/controller/integrationcontext/build.go
@@ -68,7 +68,7 @@ func (action *buildAction) Handle(ctx context.Context, ictx *v1alpha1.Integratio
 	return nil
 }
 
-func (action *buildAction) handleBuildRunning(ctx context.Context, ictx *v1alpha1.IntegrationContext) error {
+func (action *buildAction) handleBuildRunning(_ context.Context, ictx *v1alpha1.IntegrationContext) error {
 	b, err := platform.GetPlatformBuilder(action.client, ictx.Namespace)
 	if err != nil {
 		return err
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index e0f7fc0..87f6c37 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -38,9 +38,7 @@ type builderTrait struct {
 
 func newBuilderTrait() *builderTrait {
 	return &builderTrait{
-		BaseTrait: BaseTrait{
-			id: ID("builder"),
-		},
+		BaseTrait: newBaseTrait("builder"),
 	}
 }
 
diff --git a/pkg/trait/classpath.go b/pkg/trait/classpath.go
index ff50440..7e61337 100644
--- a/pkg/trait/classpath.go
+++ b/pkg/trait/classpath.go
@@ -34,9 +34,7 @@ type classpathTrait struct {
 
 func newClasspathTrait() *classpathTrait {
 	return &classpathTrait{
-		BaseTrait: BaseTrait{
-			id: ID("classpath"),
-		},
+		BaseTrait: newBaseTrait("classpath"),
 	}
 }
 
diff --git a/pkg/trait/debug.go b/pkg/trait/debug.go
index 51f5161..2491cbc 100644
--- a/pkg/trait/debug.go
+++ b/pkg/trait/debug.go
@@ -28,9 +28,7 @@ type debugTrait struct {
 
 func newDebugTrait() *debugTrait {
 	return &debugTrait{
-		BaseTrait: BaseTrait{
-			id: ID("debug"),
-		},
+		BaseTrait: newBaseTrait("debug"),
 	}
 }
 
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index 4052e4c..b4e1ef8 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -31,9 +31,7 @@ type dependenciesTrait struct {
 
 func newDependenciesTrait() *dependenciesTrait {
 	return &dependenciesTrait{
-		BaseTrait: BaseTrait{
-			id: ID("dependencies"),
-		},
+		BaseTrait: newBaseTrait("dependencies"),
 	}
 }
 
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index fa72c38..aa78b2b 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -41,9 +41,7 @@ type deploymentTrait struct {
 
 func newDeploymentTrait() *deploymentTrait {
 	return &deploymentTrait{
-		BaseTrait: BaseTrait{
-			id: ID("deployment"),
-		},
+		BaseTrait: newBaseTrait("deployment"),
 	}
 }
 
diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go
index 67fd522..8845f43 100644
--- a/pkg/trait/environment.go
+++ b/pkg/trait/environment.go
@@ -36,9 +36,7 @@ const (
 
 func newEnvironmentTrait() *environmentTrait {
 	return &environmentTrait{
-		BaseTrait: BaseTrait{
-			id: ID("environment"),
-		},
+		BaseTrait:     newBaseTrait("environment"),
 		ContainerMeta: true,
 	}
 }
diff --git a/pkg/trait/images.go b/pkg/trait/images.go
index 3ed4c0b..f5a4c18 100644
--- a/pkg/trait/images.go
+++ b/pkg/trait/images.go
@@ -28,9 +28,7 @@ type imagesTrait struct {
 
 func newImagesTrait() *imagesTrait {
 	return &imagesTrait{
-		BaseTrait: BaseTrait{
-			id: ID("images"),
-		},
+		BaseTrait: newBaseTrait("images"),
 	}
 }
 
diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go
index f8bd7ec..8f0fe56 100644
--- a/pkg/trait/ingress.go
+++ b/pkg/trait/ingress.go
@@ -35,10 +35,8 @@ type ingressTrait struct {
 
 func newIngressTrait() *ingressTrait {
 	return &ingressTrait{
-		BaseTrait: BaseTrait{
-			id: ID("ingress"),
-		},
-		Host: "",
+		BaseTrait: newBaseTrait("ingress"),
+		Host:      "",
 	}
 }
 
diff --git a/pkg/trait/istio.go b/pkg/trait/istio.go
index bd65738..764dbd9 100644
--- a/pkg/trait/istio.go
+++ b/pkg/trait/istio.go
@@ -35,10 +35,8 @@ const (
 
 func newIstioTrait() *istioTrait {
 	return &istioTrait{
-		BaseTrait: BaseTrait{
-			id: ID("istio"),
-		},
-		Allow: "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16",
+		BaseTrait: newBaseTrait("istio"),
+		Allow:     "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16",
 	}
 }
 
diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go
index ba9b8b7..9b288f3 100644
--- a/pkg/trait/jolokia.go
+++ b/pkg/trait/jolokia.go
@@ -52,10 +52,8 @@ type jolokiaTrait struct {
 // as it mutates environment variables
 func newJolokiaTrait() *jolokiaTrait {
 	return &jolokiaTrait{
-		BaseTrait: BaseTrait{
-			id: ID("jolokia"),
-		},
-		Port: 8778,
+		BaseTrait: newBaseTrait("jolokia"),
+		Port:      8778,
 	}
 }
 
@@ -88,7 +86,7 @@ func (t *jolokiaTrait) Apply(e *Environment) (err error) {
 		return nil
 	}
 
-	// Need to set it explicitely as it default to true
+	// Need to set it explicitly as it default to true
 	envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_AUTH_OPENSHIFT", "false")
 
 	// Configure the Jolokia Java agent
@@ -98,7 +96,7 @@ func (t *jolokiaTrait) Apply(e *Environment) (err error) {
 		return err
 	}
 
-	// Then add explicitely set trait configuration properties
+	// Then add explicitly set trait configuration properties
 	addToJolokiaOptions(options, "caCert", t.CaCert)
 	addToJolokiaOptions(options, "clientPrincipal", t.ClientPrincipal)
 	addToJolokiaOptions(options, "discoveryEnabled", t.DiscoveryEnabled)
@@ -145,19 +143,19 @@ func setDefaultJolokiaOption(options map[string]string, option interface{}, key
 	if _, ok := options[key]; ok {
 		return
 	}
-	switch option.(type) {
+	switch o := option.(type) {
 	case **bool:
-		if o := option.(**bool); *o == nil {
+		if *o == nil {
 			v := value.(bool)
 			*o = &v
 		}
 	case **int:
-		if o := option.(**int); *o == nil {
+		if *o == nil {
 			v := value.(int)
 			*o = &v
 		}
 	case **string:
-		if o := option.(**string); *o == nil {
+		if *o == nil {
 			v := value.(string)
 			*o = &v
 		}
@@ -165,19 +163,19 @@ func setDefaultJolokiaOption(options map[string]string, option interface{}, key
 }
 
 func addToJolokiaOptions(options map[string]string, key string, value interface{}) {
-	switch value.(type) {
+	switch v := value.(type) {
 	case *bool:
-		if v := value.(*bool); v != nil {
+		if v != nil {
 			options[key] = strconv.FormatBool(*v)
 		}
 	case *int:
-		if v := value.(*int); v != nil {
+		if v != nil {
 			options[key] = strconv.Itoa(*v)
 		}
 	case int:
-		options[key] = strconv.Itoa(value.(int))
+		options[key] = strconv.Itoa(v)
 	case *string:
-		if v := value.(*string); v != nil {
+		if v != nil {
 			options[key] = *v
 		}
 	}
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index a7bc622..9f00d3b 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -43,9 +43,7 @@ type knativeTrait struct {
 
 func newKnativeTrait() *knativeTrait {
 	return &knativeTrait{
-		BaseTrait: BaseTrait{
-			id: ID("knative"),
-		},
+		BaseTrait: newBaseTrait("knative"),
 	}
 }
 
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index cb4a603..2c48953 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -45,9 +45,7 @@ type knativeServiceTrait struct {
 
 func newKnativeServiceTrait() *knativeServiceTrait {
 	return &knativeServiceTrait{
-		BaseTrait: BaseTrait{
-			id: ID("knative-service"),
-		},
+		BaseTrait: newBaseTrait("knative-service"),
 	}
 }
 
diff --git a/pkg/trait/owner.go b/pkg/trait/owner.go
index 26a7906..770c00d 100644
--- a/pkg/trait/owner.go
+++ b/pkg/trait/owner.go
@@ -29,9 +29,7 @@ type ownerTrait struct {
 
 func newOwnerTrait() *ownerTrait {
 	return &ownerTrait{
-		BaseTrait: BaseTrait{
-			id: ID("owner"),
-		},
+		BaseTrait: newBaseTrait("owner"),
 	}
 }
 
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index d05cb7f..5229d7b 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -45,9 +45,7 @@ const prometheusPortName = "prometheus"
 // as it mutates environment variables
 func newPrometheusTrait() *prometheusTrait {
 	return &prometheusTrait{
-		BaseTrait: BaseTrait{
-			id: ID("prometheus"),
-		},
+		BaseTrait:      newBaseTrait("prometheus"),
 		Port:           9779,
 		ServiceMonitor: true,
 	}
@@ -142,7 +140,7 @@ func (t *prometheusTrait) getServiceMonitorFor(e *Environment) (*monitoringv1.Se
 				},
 			},
 			Endpoints: []monitoringv1.Endpoint{
-				monitoringv1.Endpoint{
+				{
 					Port: "prometheus",
 				},
 			},
diff --git a/pkg/trait/rest.go b/pkg/trait/rest.go
index a8596f7..7f7a6e6 100644
--- a/pkg/trait/rest.go
+++ b/pkg/trait/rest.go
@@ -42,9 +42,7 @@ type restTrait struct {
 
 func newRestTrait() *restTrait {
 	return &restTrait{
-		BaseTrait: BaseTrait{
-			id: ID("rest"),
-		},
+		BaseTrait: newBaseTrait("rest"),
 	}
 }
 
diff --git a/pkg/trait/route.go b/pkg/trait/route.go
index 1e6746c..e77d021 100644
--- a/pkg/trait/route.go
+++ b/pkg/trait/route.go
@@ -37,9 +37,7 @@ type routeTrait struct {
 
 func newRouteTrait() *routeTrait {
 	return &routeTrait{
-		BaseTrait: BaseTrait{
-			id: ID("route"),
-		},
+		BaseTrait: newBaseTrait("route"),
 	}
 }
 
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 4e4dda0..74590ff 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -37,10 +37,8 @@ const httpPortName = "http"
 
 func newServiceTrait() *serviceTrait {
 	return &serviceTrait{
-		BaseTrait: BaseTrait{
-			id: ID("service"),
-		},
-		Port: 8080,
+		BaseTrait: newBaseTrait("service"),
+		Port:      8080,
 	}
 }
 
diff --git a/pkg/trait/springboot.go b/pkg/trait/springboot.go
index 92befb3..60ce22d 100644
--- a/pkg/trait/springboot.go
+++ b/pkg/trait/springboot.go
@@ -35,9 +35,7 @@ type springBootTrait struct {
 
 func newSpringBootTrait() *springBootTrait {
 	return &springBootTrait{
-		BaseTrait: BaseTrait{
-			id: ID("springboot"),
-		},
+		BaseTrait: newBaseTrait("springboot"),
 	}
 }
 
diff --git a/pkg/util/kubernetes/log/util.go b/pkg/util/kubernetes/log/util.go
index 2dc91fc..56f8cc1 100644
--- a/pkg/util/kubernetes/log/util.go
+++ b/pkg/util/kubernetes/log/util.go
@@ -25,12 +25,13 @@ import (
 	"os"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+
 	"k8s.io/client-go/kubernetes"
 )
 
 // Print prints integrations logs to the stdout
 func Print(ctx context.Context, client kubernetes.Interface, integration *v1alpha1.Integration) error {
-	scraper := NewSelectorScraper(client, integration.Namespace, integration.Name,"camel.apache.org/integration="+integration.Name)
+	scraper := NewSelectorScraper(client, integration.Namespace, integration.Name, "camel.apache.org/integration="+integration.Name)
 	reader := scraper.Start(ctx)
 
 	if _, err := io.Copy(os.Stdout, ioutil.NopCloser(reader)); err != nil {
diff --git a/pkg/util/maven/maven.go b/pkg/util/maven/maven.go
index 4e753cc..8af78cd 100644
--- a/pkg/util/maven/maven.go
+++ b/pkg/util/maven/maven.go
@@ -21,12 +21,13 @@ import (
 	"bytes"
 	"encoding/xml"
 	"fmt"
-	"github.com/pkg/errors"
 	"os"
 	"os/exec"
 	"regexp"
 	"strings"
 
+	"github.com/pkg/errors"
+
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/util"
 	"github.com/apache/camel-k/pkg/util/log"