This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 0ca19e54e767493e233ac318c77d42ca13f3025e Author: Gaelle Fournier <gaelle.fournier.w...@gmail.com> AuthorDate: Thu Jul 27 18:12:48 2023 +0200 chore(ci): Fix golang-ci lint errors --- .golangci.yml | 4 ++++ addons/tracing/tracing.go | 1 - addons/vault/aws/aws_secrets_manager.go | 1 - cmd/kamel/main.go | 4 ---- cmd/util/vfs-gen/main.go | 2 -- e2e/common/traits/pod_test.go | 4 ++-- e2e/common/traits/route_test.go | 4 ++-- e2e/commonwithcustominstall/maven_http_proxy_test.go | 4 ++-- e2e/install/cli/maven_ca_secret_test.go | 4 ++-- pkg/base/root.go | 2 +- pkg/cmd/builder/builder.go | 3 --- pkg/cmd/completion_bash.go | 1 + pkg/cmd/describe_integration.go | 1 + pkg/cmd/describe_kamelet.go | 1 + pkg/cmd/operator/operator.go | 2 -- pkg/cmd/source/content.go | 2 +- pkg/cmd/uninstall.go | 2 +- pkg/controller/build/build_controller.go | 8 ++++---- pkg/controller/catalog/initialize.go | 4 ++-- pkg/controller/integration/build_kit.go | 4 ++-- pkg/metadata/metadata_dependencies_test.go | 1 + pkg/resources/resources_support.go | 1 - pkg/trait/jvm.go | 2 +- pkg/util/maven/maven_command.go | 3 +-- pkg/util/maven/maven_types.go | 2 +- pkg/util/s2i/build.go | 4 ++-- pkg/util/util.go | 5 +++++ 27 files changed, 37 insertions(+), 39 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 768b46cc5..999185e67 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,6 +24,7 @@ linters: enable-all: true disable: - cyclop + - depguard - dupl - exhaustive - exhaustivestruct @@ -50,12 +51,15 @@ linters: - nestif - nilnil - nlreturn + - nolintlint - nosnakecase - paralleltest + - revive - rowserrcheck - scopelint - structcheck - sqlclosecheck + - tagalign - tagliatelle - tenv - testpackage diff --git a/addons/tracing/tracing.go b/addons/tracing/tracing.go index 85278a96d..caca01841 100644 --- a/addons/tracing/tracing.go +++ b/addons/tracing/tracing.go @@ -27,7 +27,6 @@ import ( "github.com/apache/camel-k/v2/pkg/util" ) -// // WARNING: The Tracing trait has been **deprecated** in favor of the xref:traits:telemetry.adoc[Telemetry] trait. // // The Tracing trait can be used to automatically publish tracing information to an OpenTracing compatible collector. diff --git a/addons/vault/aws/aws_secrets_manager.go b/addons/vault/aws/aws_secrets_manager.go index 2b5dbcec3..e2bad5965 100644 --- a/addons/vault/aws/aws_secrets_manager.go +++ b/addons/vault/aws/aws_secrets_manager.go @@ -41,7 +41,6 @@ import ( // the following trait options: // -t aws-secrets-manager.enabled=true -t aws-secrets-manager.access-key="aws-access-key" -t aws-secrets-manager.secret-key="aws-secret-key" -t aws-secrets-manager.region="aws-region" -t aws-secrets-manager.context-reload-enabled="true" -t aws-secrets-manager.refresh-enabled="true" -t aws-secrets-manager.refresh-period="30000" -t aws-secrets-manager.secrets="test*" // -// // +camel-k:trait=aws-secrets-manager. type Trait struct { traitv1.Trait `property:",squash"` diff --git a/cmd/kamel/main.go b/cmd/kamel/main.go index b86a96cf6..c52207683 100644 --- a/cmd/kamel/main.go +++ b/cmd/kamel/main.go @@ -19,9 +19,7 @@ package main import ( "context" - "math/rand" "os" - "time" _ "github.com/apache/camel-k/v2/addons" _ "github.com/apache/camel-k/v2/pkg/builder" @@ -33,8 +31,6 @@ import ( ) func main() { - rand.Seed(time.Now().UTC().UnixNano()) - ctx, cancel := context.WithCancel(context.Background()) // Cancel ctx as soon as main returns diff --git a/cmd/util/vfs-gen/main.go b/cmd/util/vfs-gen/main.go index 79d6f8593..32b511b18 100644 --- a/cmd/util/vfs-gen/main.go +++ b/cmd/util/vfs-gen/main.go @@ -164,9 +164,7 @@ func NamedFilesFilter(names ...string) func(path string, fi os.FileInfo) bool { } } -// // If file is bigger than maximum size (in bytes) then exclude. -// func BigFilesFilter(size int) func(path string, fi os.FileInfo) bool { return func(path string, fi os.FileInfo) bool { if fi.IsDir() { diff --git a/e2e/common/traits/pod_test.go b/e2e/common/traits/pod_test.go index 46a2c67bf..81d2e1596 100644 --- a/e2e/common/traits/pod_test.go +++ b/e2e/common/traits/pod_test.go @@ -44,7 +44,7 @@ func TestPodTrait(t *testing.T) { { name: "pod trait with env vars and volume mounts", templateName: "files/template.yaml", - // nolint: thelper + //nolint: thelper assertions: func(t *testing.T, ns string, name string) { // check that integrations is working and reading data created by sidecar container Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Content from the sidecar container")) @@ -60,7 +60,7 @@ func TestPodTrait(t *testing.T) { { name: "pod trait with supplemental groups", templateName: "files/template-with-supplemental-groups.yaml", - // nolint: thelper + //nolint: thelper assertions: func(t *testing.T, ns string, name string) { Eventually(IntegrationPodHas(ns, name, func(pod *corev1.Pod) bool { if pod.Spec.SecurityContext == nil { diff --git a/e2e/common/traits/route_test.go b/e2e/common/traits/route_test.go index 291f56fdc..22e6d82f8 100644 --- a/e2e/common/traits/route_test.go +++ b/e2e/common/traits/route_test.go @@ -32,7 +32,6 @@ import ( "encoding/pem" "fmt" "math/big" - rand2 "math/rand" "net/http" "testing" "time" @@ -44,6 +43,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" . "github.com/apache/camel-k/v2/e2e/support" + "github.com/apache/camel-k/v2/pkg/util" "github.com/apache/camel-k/v2/pkg/util/openshift" ) @@ -271,7 +271,7 @@ func createSecret(ns string) (corev1.Secret, error) { } func generateSampleKeyAndCertificate(ns string) keyCertificatePair { - serialNumber := big.NewInt(rand2.Int63()) + serialNumber := big.NewInt(util.RandomInt63()) domainName, err := ClusterDomainName() if err != nil { fmt.Printf("Error retrieving cluster domain object, then the http client request will skip TLS validation: %s\n", err) diff --git a/e2e/commonwithcustominstall/maven_http_proxy_test.go b/e2e/commonwithcustominstall/maven_http_proxy_test.go index 5dd74f2b6..dbd25e0db 100644 --- a/e2e/commonwithcustominstall/maven_http_proxy_test.go +++ b/e2e/commonwithcustominstall/maven_http_proxy_test.go @@ -30,12 +30,12 @@ import ( "encoding/pem" "fmt" "math/big" - rand2 "math/rand" "reflect" "strings" "testing" "time" + "github.com/apache/camel-k/v2/pkg/util" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/olm" @@ -62,7 +62,7 @@ func TestMavenProxy(t *testing.T) { hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns) // Generate the TLS certificate - serialNumber := big.NewInt(rand2.Int63()) + serialNumber := big.NewInt(util.RandomInt63()) cert := &x509.Certificate{ SerialNumber: serialNumber, Subject: pkix.Name{ diff --git a/e2e/install/cli/maven_ca_secret_test.go b/e2e/install/cli/maven_ca_secret_test.go index bb37dfaaf..74849920c 100644 --- a/e2e/install/cli/maven_ca_secret_test.go +++ b/e2e/install/cli/maven_ca_secret_test.go @@ -32,7 +32,6 @@ import ( "encoding/pem" "fmt" "math/big" - rand2 "math/rand" "os" "strings" "testing" @@ -52,6 +51,7 @@ import ( . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + "github.com/apache/camel-k/v2/pkg/util" "github.com/apache/camel-k/v2/pkg/util/maven" ) @@ -61,7 +61,7 @@ func TestMavenCASecret(t *testing.T) { tlsMountPath := "/etc/tls/private" // Generate the TLS certificate - serialNumber := big.NewInt(rand2.Int63()) + serialNumber := big.NewInt(util.RandomInt63()) cert := &x509.Certificate{ SerialNumber: serialNumber, Subject: pkix.Name{ diff --git a/pkg/base/root.go b/pkg/base/root.go index dba5248a1..0e2f774ba 100644 --- a/pkg/base/root.go +++ b/pkg/base/root.go @@ -6,7 +6,7 @@ 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 + 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, diff --git a/pkg/cmd/builder/builder.go b/pkg/cmd/builder/builder.go index f0b169376..7252fd89d 100644 --- a/pkg/cmd/builder/builder.go +++ b/pkg/cmd/builder/builder.go @@ -20,12 +20,10 @@ package builder import ( "context" "fmt" - "math/rand" "os" "os/signal" "runtime" "syscall" - "time" "k8s.io/apimachinery/pkg/types" @@ -57,7 +55,6 @@ func Run(namespace string, buildName string, taskName string) { o.Development = false })) - rand.Seed(time.Now().UTC().UnixNano()) printVersion() c, err := client.NewClient(false) diff --git a/pkg/cmd/completion_bash.go b/pkg/cmd/completion_bash.go index 5f6ab1051..b070503f8 100644 --- a/pkg/cmd/completion_bash.go +++ b/pkg/cmd/completion_bash.go @@ -45,6 +45,7 @@ To configure your bash shell to load completions for each session add to your ba . <(kamel completion bash) ` +//nolint:dupword var bashCompletionFunction = ` __kamel_dependency_type() { case ${cur} in diff --git a/pkg/cmd/describe_integration.go b/pkg/cmd/describe_integration.go index a97d2d513..848d40518 100644 --- a/pkg/cmd/describe_integration.go +++ b/pkg/cmd/describe_integration.go @@ -152,6 +152,7 @@ func (command *describeIntegrationCommandOptions) describeIntegration(cmd *cobra } } } else { + //nolint:dupword w.Writef(1, "Name\tLanguage\tCompression\tRef\tRef Key\n") for _, s := range i.Sources() { w.Writef(1, "%s\t%s\t%t\t%s\t%s\n", diff --git a/pkg/cmd/describe_kamelet.go b/pkg/cmd/describe_kamelet.go index c49d9dc20..c7267fd84 100644 --- a/pkg/cmd/describe_kamelet.go +++ b/pkg/cmd/describe_kamelet.go @@ -166,6 +166,7 @@ func (command *describeKameletCommandOptions) describeKamelet(cmd *cobra.Command // Sources if len(kamelet.Spec.Sources) > 0 { w.Writef(0, "Sources:\t\n") + //nolint:dupword w.Writef(1, "Name\tLanguage\tCompression\tRef\tRef Key\n") for _, s := range kamelet.Spec.Sources { w.Writef(1, "%s\t%s\t%t\t%s\t%s\n", diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go index fff5a04aa..a08eae495 100644 --- a/pkg/cmd/operator/operator.go +++ b/pkg/cmd/operator/operator.go @@ -21,7 +21,6 @@ import ( "context" "flag" "fmt" - "math/rand" "os" "reflect" "runtime" @@ -85,7 +84,6 @@ func printVersion() { // Run starts the Camel K operator. func Run(healthPort, monitoringPort int32, leaderElection bool, leaderElectionID string) { - rand.Seed(time.Now().UTC().UnixNano()) flag.Parse() diff --git a/pkg/cmd/source/content.go b/pkg/cmd/source/content.go index a58b612e9..57f3fc877 100644 --- a/pkg/cmd/source/content.go +++ b/pkg/cmd/source/content.go @@ -120,7 +120,7 @@ func loadContentHTTP(ctx context.Context, u fmt.Stringer) ([]byte, error) { _ = resp.Body.Close() }() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return []byte{}, fmt.Errorf("the provided URL %s is not reachable, error code is %d", u.String(), resp.StatusCode) } diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go index 12fcfba7b..399361009 100644 --- a/pkg/cmd/uninstall.go +++ b/pkg/cmd/uninstall.go @@ -132,7 +132,7 @@ func (o *uninstallCmdOptions) uninstall(cmd *cobra.Command, _ []string) error { return err } - // nolint: ifshort + //nolint: ifshort uninstallViaOLM := false if o.OlmEnabled { var err error diff --git a/pkg/controller/build/build_controller.go b/pkg/controller/build/build_controller.go index fdd8d4d2e..20bb554bc 100644 --- a/pkg/controller/build/build_controller.go +++ b/pkg/controller/build/build_controller.go @@ -185,9 +185,9 @@ func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques } if newTarget != nil { - if res, err := r.update(ctx, &instance, newTarget); err != nil { + if err := r.update(ctx, &instance, newTarget); err != nil { camelevent.NotifyBuildError(ctx, r.client, r.recorder, &instance, newTarget, err) - return res, err + return reconcile.Result{}, err } if newTarget.Status.Phase != instance.Status.Phase { @@ -236,9 +236,9 @@ func (r *reconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques return reconcile.Result{}, nil } -func (r *reconcileBuild) update(ctx context.Context, base *v1.Build, target *v1.Build) (reconcile.Result, error) { +func (r *reconcileBuild) update(ctx context.Context, base *v1.Build, target *v1.Build) error { target.Status.ObservedGeneration = base.Generation err := r.client.Status().Patch(ctx, target, ctrl.MergeFrom(base)) - return reconcile.Result{}, err + return err } diff --git a/pkg/controller/catalog/initialize.go b/pkg/controller/catalog/initialize.go index 38bc35e96..299b36530 100644 --- a/pkg/controller/catalog/initialize.go +++ b/pkg/controller/catalog/initialize.go @@ -352,7 +352,7 @@ func initializeS2i(ctx context.Context, c client.Client, ip *v1.IntegrationPlatf err = s2i.WaitForS2iBuildCompletion(ctx, c, &s2iBuild) if err != nil { if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - // nolint: contextcheck + //nolint: contextcheck if err := s2i.CancelBuild(context.Background(), c, &s2iBuild); err != nil { return fmt.Errorf("cannot cancel s2i Build: %s/%s", s2iBuild.Namespace, s2iBuild.Name) } @@ -522,7 +522,7 @@ func tarEntries(writer io.Writer, files ...string) error { tw := tar.NewWriter(gzw) defer util.CloseQuietly(tw) - // Iterate over files and and add them to the tar archive + // Iterate over files and add them to the tar archive for _, fileDetail := range files { fileSource := strings.Split(fileDetail, ":")[0] fileTarget := strings.Split(fileDetail, ":")[1] diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go index ee84fb36c..a110218d9 100644 --- a/pkg/controller/integration/build_kit.go +++ b/pkg/controller/integration/build_kit.go @@ -68,8 +68,8 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr kit, err := kubernetes.GetIntegrationKit(ctx, action.client, integration.Status.IntegrationKit.Name, integration.Status.IntegrationKit.Namespace) if err != nil { - return nil, fmt.Errorf("unable to find integration kit %s/%s, %s: %w", - integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err, err) + return nil, fmt.Errorf("unable to find integration kit %s/%s: %w", + integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err) } diff --git a/pkg/metadata/metadata_dependencies_test.go b/pkg/metadata/metadata_dependencies_test.go index d252a8453..45d3bb1aa 100644 --- a/pkg/metadata/metadata_dependencies_test.go +++ b/pkg/metadata/metadata_dependencies_test.go @@ -686,6 +686,7 @@ const yamlWithCircuitBreaker = ` todo: "not implemented" ` +//nolint:dupword const yamlWithLanguages = ` - from: uri: "direct:start" diff --git a/pkg/resources/resources_support.go b/pkg/resources/resources_support.go index 2dc27637b..94d739517 100644 --- a/pkg/resources/resources_support.go +++ b/pkg/resources/resources_support.go @@ -31,7 +31,6 @@ import ( "github.com/apache/camel-k/v2/pkg/util" ) -// // ResourceAsString returns the named resource content as string. // Warning : do not remove the go:generate line as it is used to update the resources file in case of CRD changes. // diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go index 7dd081f19..a80a6bf02 100644 --- a/pkg/trait/jvm.go +++ b/pkg/trait/jvm.go @@ -83,7 +83,7 @@ func (t *jvmTrait) Apply(e *Environment) error { ns := e.Integration.GetIntegrationKitNamespace(e.Platform) k := v1.NewIntegrationKit(ns, name) if err := t.Client.Get(e.Ctx, ctrl.ObjectKeyFromObject(k), k); err != nil { - return fmt.Errorf("unable to find integration kit %s/%s, %s: %w", ns, name, err, err) + return fmt.Errorf("unable to find integration kit %s/%s: %w", ns, name, err) } kit = k } diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go index 49b49d6db..9ba23b1b7 100644 --- a/pkg/util/maven/maven_command.go +++ b/pkg/util/maven/maven_command.go @@ -250,8 +250,7 @@ func (c *Command) prepareMavenWrapper(ctx context.Context) error { // // The artifact id is in the form of: // -// <groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?') -// +// <groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?') func ParseGAV(gav string) (Dependency, error) { // <groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?') dep := Dependency{} diff --git a/pkg/util/maven/maven_types.go b/pkg/util/maven/maven_types.go index 98494c54b..4a655a3ec 100644 --- a/pkg/util/maven/maven_types.go +++ b/pkg/util/maven/maven_types.go @@ -66,7 +66,7 @@ type Settings struct { // Project models a Maven project. type Project struct { - XMLName xml.Name + XMLName xml.Name `xml:"project"` XMLNs string `xml:"xmlns,attr"` XMLNsXsi string `xml:"xmlns:xsi,attr"` XsiSchemaLocation string `xml:"xsi:schemaLocation,attr"` diff --git a/pkg/util/s2i/build.go b/pkg/util/s2i/build.go index 82e68d40e..a2a393493 100644 --- a/pkg/util/s2i/build.go +++ b/pkg/util/s2i/build.go @@ -75,7 +75,7 @@ func WaitForS2iBuildCompletion(ctx context.Context, c client.Client, build *buil } } -// Create the BuildConfig of the build with the right owner after having deleted it it already existed. +// Create the BuildConfig of the build with the right owner after having deleted it already existed. func BuildConfig(ctx context.Context, c client.Client, bc *buildv1.BuildConfig, owner metav1.Object) error { if err := c.Delete(ctx, bc); err != nil && !apierrors.IsNotFound(err) { return fmt.Errorf("cannot delete build config: %w", err) @@ -91,7 +91,7 @@ func BuildConfig(ctx context.Context, c client.Client, bc *buildv1.BuildConfig, return nil } -// Create the ImageStream for the builded image with the right owner after having deleted it it already existed. +// Create the ImageStream for the builded image with the right owner after having deleted it already existed. func ImageStream(ctx context.Context, c client.Client, is *imagev1.ImageStream, owner metav1.Object) error { if err := c.Delete(ctx, is); err != nil && !apierrors.IsNotFound(err) { return fmt.Errorf("cannot delete image stream: %w", err) diff --git a/pkg/util/util.go b/pkg/util/util.go index 2d91ee22d..5d122dee1 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -212,6 +212,7 @@ const ( ) var randomSource = rand.NewSource(time.Now().UnixNano()) +var randomSourceUTC = rand.NewSource(time.Now().UTC().UnixNano()) func RandomString(n int) string { sb := strings.Builder{} @@ -231,6 +232,10 @@ func RandomString(n int) string { return sb.String() } +func RandomInt63() int64 { + return randomSourceUTC.Int63() +} + func EncodeXML(content interface{}) ([]byte, error) { w := &bytes.Buffer{} w.WriteString(xml.Header)