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 2019/06/21 10:35:01 UTC
[camel-k] branch master updated: chore(lint): fix findings
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
The following commit(s) were added to refs/heads/master by this push:
new 77f06b1 chore(lint): fix findings
77f06b1 is described below
commit 77f06b14fd4844b2c5b7048b15c0fef92d6f807e
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Fri Jun 21 11:10:47 2019 +0200
chore(lint): fix findings
---
pkg/builder/builder_steps_test.go | 4 +++
pkg/builder/kaniko/publisher.go | 1 -
pkg/cmd/install.go | 20 +++++------
pkg/install/builder.go | 1 +
pkg/trait/ingress.go | 10 +++---
pkg/trait/knative_service.go | 14 ++++----
pkg/trait/knative_service_test.go | 11 +++++--
pkg/trait/route.go | 11 ++++---
pkg/trait/route_test.go | 4 +--
pkg/trait/service.go | 2 +-
pkg/trait/service_test.go | 19 +++++++----
pkg/trait/trait.go | 3 --
pkg/trait/trait_test.go | 28 ++++++++--------
pkg/trait/trait_types.go | 6 ++++
pkg/util/maven/maven_settings_test.go | 62 +++++++++++++++++------------------
15 files changed, 104 insertions(+), 92 deletions(-)
diff --git a/pkg/builder/builder_steps_test.go b/pkg/builder/builder_steps_test.go
index 9754f64..d530aed 100644
--- a/pkg/builder/builder_steps_test.go
+++ b/pkg/builder/builder_steps_test.go
@@ -125,6 +125,8 @@ func TestMavenSettingsFromConfigMap(t *testing.T) {
},
)
+ assert.Nil(t, err)
+
ctx := Context{
Catalog: catalog,
Client: c,
@@ -175,6 +177,8 @@ func TestMavenSettingsFromSecret(t *testing.T) {
},
)
+ assert.Nil(t, err)
+
ctx := Context{
Catalog: catalog,
Client: c,
diff --git a/pkg/builder/kaniko/publisher.go b/pkg/builder/kaniko/publisher.go
index 6de226e..4e798ea 100644
--- a/pkg/builder/kaniko/publisher.go
+++ b/pkg/builder/kaniko/publisher.go
@@ -135,7 +135,6 @@ func publisher(ctx *builder.Context) error {
},
}
-
var labelKey string
var labelValue string
if ctx.Namespace == platform.GetOperatorNamespace() {
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 2af4b54..0135156 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -23,21 +23,19 @@ import (
"strings"
"time"
- "github.com/apache/camel-k/pkg/util"
-
- "github.com/apache/camel-k/pkg/util/maven"
-
- "github.com/apache/camel-k/deploy"
- "github.com/apache/camel-k/pkg/apis"
"go.uber.org/multierr"
"k8s.io/apimachinery/pkg/runtime"
+ "github.com/apache/camel-k/deploy"
+ "github.com/apache/camel-k/pkg/apis"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/util/watch"
-
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/install"
+ "github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/kubernetes"
+ "github.com/apache/camel-k/pkg/util/maven"
+ "github.com/apache/camel-k/pkg/util/watch"
+
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -235,7 +233,7 @@ func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error {
Activation: maven.Activation{
ActiveByDefault: true,
},
- Repositories: repositories,
+ Repositories: repositories,
PluginRepositories: repositories,
},
}
@@ -401,9 +399,7 @@ func decodeMavenSettings(mavenSettings string) (v1alpha1.ValueSource, error) {
for _, hit := range hits {
if len(hit) > 1 {
- for _, match := range hit[1:] {
- sub = append(sub, match)
- }
+ sub = append(sub, hit[1:]...)
}
}
diff --git a/pkg/install/builder.go b/pkg/install/builder.go
index 27a1488..cd906c0 100644
--- a/pkg/install/builder.go
+++ b/pkg/install/builder.go
@@ -19,6 +19,7 @@ package install
import (
"context"
+
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/util/openshift"
)
diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go
index 2ef8718..b1184b3 100644
--- a/pkg/trait/ingress.go
+++ b/pkg/trait/ingress.go
@@ -82,11 +82,11 @@ func (t *ingressTrait) Apply(e *Environment) error {
func (t *ingressTrait) getTargetService(e *Environment) (service *corev1.Service) {
e.Resources.VisitService(func(s *corev1.Service) {
if s.ObjectMeta.Labels != nil {
- if intName, ok := s.ObjectMeta.Labels["camel.apache.org/integration"]; ok && intName == e.Integration.Name {
- if s.ObjectMeta.Labels["camel.apache.org/service.type"] == "user" {
- // We should build an ingress only on top of the user service (e.g. not if the service contains only prometheus)
- service = s
- }
+ if s.ObjectMeta.Labels["camel.apache.org/integration"] == e.Integration.Name &&
+ s.ObjectMeta.Labels["camel.apache.org/service.type"] == ServiceTypeUser {
+ // We should build an ingress only on top of the user service (e.g. not if the service contains
+ // only prometheus)
+ service = s
}
}
})
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index 811995a..0835a56 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -222,21 +222,19 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
func (t *knativeServiceTrait) getAllowedEnvVars(e *Environment) []corev1.EnvVar {
res := make([]corev1.EnvVar, 0, len(e.EnvVars))
for _, env := range e.EnvVars {
- if env.ValueFrom == nil {
- // Standard env vars are supported
+ switch {
+ case env.ValueFrom == nil:
res = append(res, env)
- } else if env.ValueFrom.FieldRef != nil && env.ValueFrom.FieldRef.FieldPath == "metadata.namespace" {
- // Namespace is known to the operator
+ case env.ValueFrom.FieldRef != nil && env.ValueFrom.FieldRef.FieldPath == "metadata.namespace":
res = append(res, corev1.EnvVar{
Name: env.Name,
Value: e.Integration.Namespace,
})
- } else if env.ValueFrom.FieldRef != nil {
+ case env.ValueFrom.FieldRef != nil:
t.L.Infof("Environment variable %s uses fieldRef and cannot be set on a Knative service", env.Name)
- } else if env.ValueFrom.ResourceFieldRef != nil {
+ case env.ValueFrom.ResourceFieldRef != nil:
t.L.Infof("Environment variable %s uses resourceFieldRef and cannot be set on a Knative service", env.Name)
- } else {
- // Other downward APIs should be supported
+ default:
res = append(res, env)
}
}
diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go
index 41921ff..30db759 100644
--- a/pkg/trait/knative_service_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -35,6 +35,11 @@ import (
"github.com/stretchr/testify/assert"
)
+const (
+ KnativeServiceTestNamespace = "ns"
+ KnativeServiceTestName = "test"
+)
+
func TestKnativeService(t *testing.T) {
catalog, err := test.DefaultCatalog()
assert.Nil(t, err)
@@ -46,8 +51,8 @@ func TestKnativeService(t *testing.T) {
Catalog: traitCatalog,
Integration: &v1alpha1.Integration{
ObjectMeta: metav1.ObjectMeta{
- Name: "test",
- Namespace: "ns",
+ Name: KnativeServiceTestName,
+ Namespace: KnativeServiceTestNamespace,
},
Status: v1alpha1.IntegrationStatus{
Phase: v1alpha1.IntegrationPhaseDeploying,
@@ -117,7 +122,7 @@ func TestKnativeService(t *testing.T) {
assert.Equal(t, 4, environment.Resources.Size())
s := environment.Resources.GetKnativeService(func(service *serving.Service) bool {
- return service.Name == "test"
+ return service.Name == KnativeServiceTestName
})
assert.NotNil(t, s)
diff --git a/pkg/trait/route.go b/pkg/trait/route.go
index aa1fc0b..ab7c5f4 100644
--- a/pkg/trait/route.go
+++ b/pkg/trait/route.go
@@ -83,11 +83,12 @@ func (t *routeTrait) Apply(e *Environment) error {
func (t *routeTrait) getTargetService(e *Environment) (service *corev1.Service) {
e.Resources.VisitService(func(s *corev1.Service) {
if s.ObjectMeta.Labels != nil {
- if intName, ok := s.ObjectMeta.Labels["camel.apache.org/integration"]; ok && intName == e.Integration.Name {
- if s.ObjectMeta.Labels["camel.apache.org/service.type"] == "user" {
- // We should build a route only on top of the user service (e.g. not if the service contains only prometheus)
- service = s
- }
+ if s.ObjectMeta.Labels["camel.apache.org/integration"] == e.Integration.Name &&
+ s.ObjectMeta.Labels["camel.apache.org/service.type"] == ServiceTypeUser {
+
+ // We should build a route only on top of the user service (e.g. not if the service contains
+ // only prometheus)
+ service = s
}
}
})
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index d484bda..ca45334 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -77,8 +77,8 @@ func createTestRouteEnvironment(t *testing.T) *Environment {
Name: "test-i",
Namespace: "test-ns",
Labels: map[string]string{
- "camel.apache.org/integration": "test-i",
- "camel.apache.org/service.type": "user",
+ "camel.apache.org/integration": "test-i",
+ "camel.apache.org/service.type": ServiceTypeUser,
},
},
Spec: corev1.ServiceSpec{
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index f852c2c..64f410e 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -91,7 +91,7 @@ func (t *serviceTrait) Apply(e *Environment) (err error) {
svc.Spec.Ports = append(svc.Spec.Ports, port)
// Mark the service as a user service
- svc.Labels["camel.apache.org/service.type"] = "user"
+ svc.Labels["camel.apache.org/service.type"] = ServiceTypeUser
// Register a post processor to add a container port to the integration deployment
e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error {
diff --git a/pkg/trait/service_test.go b/pkg/trait/service_test.go
index 7196c77..ba88353 100644
--- a/pkg/trait/service_test.go
+++ b/pkg/trait/service_test.go
@@ -34,6 +34,11 @@ import (
"github.com/stretchr/testify/assert"
)
+const (
+ ServiceTestNamespace = "ns"
+ ServiceTestName = "test"
+)
+
func TestServiceWithDefaults(t *testing.T) {
catalog, err := test.DefaultCatalog()
assert.Nil(t, err)
@@ -45,7 +50,7 @@ func TestServiceWithDefaults(t *testing.T) {
Catalog: traitCatalog,
Integration: &v1alpha1.Integration{
ObjectMeta: metav1.ObjectMeta{
- Name: "test",
+ Name: ServiceTestName,
Namespace: "ns",
},
Status: v1alpha1.IntegrationStatus{
@@ -101,10 +106,10 @@ func TestServiceWithDefaults(t *testing.T) {
assert.NotNil(t, environment.GetTrait(ID("service")))
s := environment.Resources.GetService(func(service *corev1.Service) bool {
- return service.Name == "test"
+ return service.Name == ServiceTestName
})
d := environment.Resources.GetDeployment(func(deployment *appsv1.Deployment) bool {
- return deployment.Name == "test"
+ return deployment.Name == ServiceTestName
})
assert.NotNil(t, d)
@@ -132,8 +137,8 @@ func TestService(t *testing.T) {
Catalog: traitCatalog,
Integration: &v1alpha1.Integration{
ObjectMeta: metav1.ObjectMeta{
- Name: "test",
- Namespace: "ns",
+ Name: ServiceTestName,
+ Namespace: ServiceTestNamespace,
},
Status: v1alpha1.IntegrationStatus{
Phase: v1alpha1.IntegrationPhaseDeploying,
@@ -192,10 +197,10 @@ func TestService(t *testing.T) {
assert.NotNil(t, environment.GetTrait(ID("service")))
s := environment.Resources.GetService(func(service *corev1.Service) bool {
- return service.Name == "test"
+ return service.Name == ServiceTestName
})
d := environment.Resources.GetDeployment(func(deployment *appsv1.Deployment) bool {
- return deployment.Name == "test"
+ return deployment.Name == ServiceTestName
})
assert.NotNil(t, d)
diff --git a/pkg/trait/trait.go b/pkg/trait/trait.go
index aa186a0..2f30c8c 100644
--- a/pkg/trait/trait.go
+++ b/pkg/trait/trait.go
@@ -30,9 +30,6 @@ import (
"github.com/pkg/errors"
)
-// True --
-const True = "true"
-
// Apply --
func Apply(ctx context.Context, c client.Client, integration *v1alpha1.Integration, kit *v1alpha1.IntegrationKit) (*Environment, error) {
environment, err := newEnvironment(ctx, c, integration, kit)
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index f6798ea..797f2ed 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -36,8 +36,8 @@ import (
)
const (
- TestDeployment = "test"
- TestProperties = "test-properties"
+ TestDeploymentName = "test"
+ TestProperties = "test-properties"
)
func TestOpenShiftTraits(t *testing.T) {
@@ -53,7 +53,7 @@ func TestOpenShiftTraits(t *testing.T) {
return cm.Name == TestProperties
}))
assert.NotNil(t, res.GetDeployment(func(deployment *appsv1.Deployment) bool {
- return deployment.Name == TestDeployment
+ return deployment.Name == TestDeploymentName
}))
}
@@ -68,13 +68,13 @@ func TestOpenShiftTraitsWithWeb(t *testing.T) {
return cm.Name == TestProperties
}))
assert.NotNil(t, res.GetDeployment(func(deployment *appsv1.Deployment) bool {
- return deployment.Name == TestDeployment
+ return deployment.Name == TestDeploymentName
}))
assert.NotNil(t, res.GetService(func(svc *corev1.Service) bool {
- return svc.Name == TestDeployment
+ return svc.Name == TestDeploymentName
}))
assert.NotNil(t, res.GetRoute(func(svc *routev1.Route) bool {
- return svc.Name == TestDeployment
+ return svc.Name == TestDeploymentName
}))
}
@@ -90,7 +90,7 @@ func TestOpenShiftTraitsWithWebAndConfig(t *testing.T) {
assert.NotNil(t, env.GetTrait(ID("service")))
assert.NotNil(t, env.GetTrait(ID("route")))
assert.NotNil(t, res.GetService(func(svc *corev1.Service) bool {
- return svc.Name == TestDeployment && svc.Spec.Ports[0].TargetPort.StrVal == "http"
+ return svc.Name == TestDeploymentName && svc.Spec.Ports[0].TargetPort.StrVal == "http"
}))
}
@@ -122,7 +122,7 @@ func TestKubernetesTraits(t *testing.T) {
return cm.Name == TestProperties
}))
assert.NotNil(t, res.GetDeployment(func(deployment *appsv1.Deployment) bool {
- return deployment.Name == TestDeployment
+ return deployment.Name == TestDeploymentName
}))
}
@@ -137,10 +137,10 @@ func TestKubernetesTraitsWithWeb(t *testing.T) {
return cm.Name == TestProperties
}))
assert.NotNil(t, res.GetDeployment(func(deployment *appsv1.Deployment) bool {
- return deployment.Name == TestDeployment
+ return deployment.Name == TestDeploymentName
}))
assert.NotNil(t, res.GetService(func(svc *corev1.Service) bool {
- return svc.Name == TestDeployment
+ return svc.Name == TestDeploymentName
}))
}
@@ -222,7 +222,7 @@ func TestConfigureVolumesAndMounts(t *testing.T) {
env := Environment{
Integration: &v1alpha1.Integration{
ObjectMeta: metav1.ObjectMeta{
- Name: TestDeployment,
+ Name: TestDeploymentName,
Namespace: "ns",
},
Spec: v1alpha1.IntegrationSpec{
@@ -309,7 +309,7 @@ func TestConfigureVolumesAndMounts(t *testing.T) {
assert.NotNil(t, m)
assert.Equal(t, "/etc/camel/resources/i-resource-001", m.MountPath)
- v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeployment+"-resource-002" })
+ v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeploymentName+"-resource-002" })
assert.NotNil(t, v)
assert.NotNil(t, v.VolumeSource.ConfigMap)
assert.Len(t, v.VolumeSource.ConfigMap.Items, 1)
@@ -320,7 +320,7 @@ func TestConfigureVolumesAndMounts(t *testing.T) {
assert.NotNil(t, m)
assert.Equal(t, "/etc/camel/resources/i-resource-002", m.MountPath)
- v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeployment+"-resource-003" })
+ v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == TestDeploymentName+"-resource-003" })
assert.NotNil(t, v)
assert.NotNil(t, v.VolumeSource.ConfigMap)
assert.Len(t, v.VolumeSource.ConfigMap.Items, 1)
@@ -399,7 +399,7 @@ func createTestEnv(t *testing.T, cluster v1alpha1.IntegrationPlatformCluster, sc
Catalog: NewCatalog(context.TODO(), nil),
Integration: &v1alpha1.Integration{
ObjectMeta: metav1.ObjectMeta{
- Name: TestDeployment,
+ Name: TestDeploymentName,
Namespace: "ns",
},
Spec: v1alpha1.IntegrationSpec{
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 92331ba..0f48b5c 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -40,6 +40,12 @@ import (
"github.com/apache/camel-k/pkg/util/log"
)
+// True --
+const True = "true"
+
+// ServiceTypeUser --
+const ServiceTypeUser = "user"
+
// Identifiable represent an identifiable type
type Identifiable interface {
ID() ID
diff --git a/pkg/util/maven/maven_settings_test.go b/pkg/util/maven/maven_settings_test.go
index 8bd25a3..ef1df7f 100644
--- a/pkg/util/maven/maven_settings_test.go
+++ b/pkg/util/maven/maven_settings_test.go
@@ -18,15 +18,15 @@ limitations under the License.
package maven
import (
- "testing"
+ "testing"
- "github.com/apache/camel-k/pkg/util"
- "github.com/stretchr/testify/assert"
+ "github.com/apache/camel-k/pkg/util"
+ "github.com/stretchr/testify/assert"
)
const expectedSettings = `<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ` +
- `xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
+ `xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/tmp/artifacts/m2</localRepository>
<profiles>
<profile>
@@ -53,34 +53,34 @@ const expectedSettings = `<?xml version="1.0" encoding="UTF-8"?>
</settings>`
func TestSettingsGeneration(t *testing.T) {
- settings := NewSettings()
- settings.LocalRepository = "/tmp/artifacts/m2"
- settings.Profiles = []Profile{
- {
- ID: "my-profile",
- Activation: Activation{
- ActiveByDefault: true,
- },
- Repositories: []Repository{
- {
- ID: "central",
- URL: "https://repo.maven.apache.org/maven2",
- Snapshots: RepositoryPolicy{
- Enabled: false,
- },
- Releases: RepositoryPolicy{
- Enabled: true,
- UpdatePolicy: "never",
- },
- },
- },
- },
- }
+ settings := NewSettings()
+ settings.LocalRepository = "/tmp/artifacts/m2"
+ settings.Profiles = []Profile{
+ {
+ ID: "my-profile",
+ Activation: Activation{
+ ActiveByDefault: true,
+ },
+ Repositories: []Repository{
+ {
+ ID: "central",
+ URL: "https://repo.maven.apache.org/maven2",
+ Snapshots: RepositoryPolicy{
+ Enabled: false,
+ },
+ Releases: RepositoryPolicy{
+ Enabled: true,
+ UpdatePolicy: "never",
+ },
+ },
+ },
+ },
+ }
- content, err := util.EncodeXML(settings)
+ content, err := util.EncodeXML(settings)
- assert.Nil(t, err)
- assert.NotNil(t, settings)
+ assert.Nil(t, err)
+ assert.NotNil(t, settings)
- assert.Equal(t, expectedSettings, string(content))
+ assert.Equal(t, expectedSettings, string(content))
}