From fa2649b38e6523bdb5e1b436a13f46637e0454a2 Mon Sep 17 00:00:00 2001 From: Daniil Fedotov Date: Wed, 23 Oct 2024 14:03:34 -0400 Subject: [PATCH] build: bump golangci-lint version in build image (#3195) --- .golangci.yml | 3 +++ docker/build/Dockerfile | 2 +- pkg/function/create_volume_snapshot.go | 2 +- pkg/function/delete_rds_snapshot.go | 22 +++++++++++----------- pkg/handler/handler.go | 2 +- pkg/kube/pod.go | 2 +- pkg/kube/pod_test.go | 2 +- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6f11113279..e2bdf6fa8c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -77,6 +77,9 @@ linters-settings: skip-generated: true stylecheck: checks: [ "all", "-ST1001", "-ST1005", "-ST1016", "-ST1023", "-ST1000"] + errcheck: + exclude-functions: + - fmt.Fprintln exclude-dirs: - pkg/client/applyconfiguration/cr/v1alpha1 # generated from code-gen diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile index c011f04863..0f664952f9 100644 --- a/docker/build/Dockerfile +++ b/docker/build/Dockerfile @@ -19,7 +19,7 @@ COPY --from=goreleaser/goreleaser:v1.26.2 /usr/bin/goreleaser /usr/local/bin/ COPY --from=alpine/helm:3.12.2 /usr/bin/helm /usr/local/bin/ -COPY --from=golangci/golangci-lint:v1.57.2 /usr/bin/golangci-lint /usr/local/bin/ +COPY --from=golangci/golangci-lint:v1.60.1 /usr/bin/golangci-lint /usr/local/bin/ RUN wget -O /usr/local/bin/kind \ https://github.com/kubernetes-sigs/kind/releases/download/v0.18.0/kind-$(echo $TARGETPLATFORM | tr / -) \ diff --git a/pkg/function/create_volume_snapshot.go b/pkg/function/create_volume_snapshot.go index 4a27e160f3..e45b1c161d 100644 --- a/pkg/function/create_volume_snapshot.go +++ b/pkg/function/create_volume_snapshot.go @@ -134,7 +134,7 @@ func createVolumeSnapshot(ctx context.Context, tp param.TemplateParams, cli kube } wg.Wait() - err := fmt.Errorf(strings.Join(errstrings, "\n")) + err := errkit.New(strings.Join(errstrings, "\n")) if len(err.Error()) > 0 { return nil, errkit.Wrap(err, "Failed to snapshot one of the volumes") } diff --git a/pkg/function/delete_rds_snapshot.go b/pkg/function/delete_rds_snapshot.go index f213a4e4bb..68d3dd3361 100644 --- a/pkg/function/delete_rds_snapshot.go +++ b/pkg/function/delete_rds_snapshot.go @@ -55,22 +55,22 @@ func (*deleteRDSSnapshotFunc) Name() string { return DeleteRDSSnapshotFuncName } -func deleteRDSSnapshot(ctx context.Context, snapshotID string, profile *param.Profile, dbEngine RDSDBEngine) (map[string]interface{}, error) { +func deleteRDSSnapshot(ctx context.Context, snapshotID string, profile *param.Profile, dbEngine RDSDBEngine) error { // Validate profile if err := ValidateProfile(profile); err != nil { - return nil, errkit.Wrap(err, "Profile Validation failed") + return errkit.Wrap(err, "Profile Validation failed") } // Get aws config from profile awsConfig, region, err := getAWSConfigFromProfile(ctx, profile) if err != nil { - return nil, errkit.Wrap(err, "Failed to get AWS creds from profile") + return errkit.Wrap(err, "Failed to get AWS creds from profile") } // Create rds client rdsCli, err := rds.NewClient(ctx, awsConfig, region) if err != nil { - return nil, errkit.Wrap(err, "Failed to create RDS client") + return errkit.Wrap(err, "Failed to create RDS client") } if !isAuroraCluster(string(dbEngine)) { @@ -82,16 +82,16 @@ func deleteRDSSnapshot(ctx context.Context, snapshotID string, profile *param.Pr switch err.Code() { case awsrds.ErrCodeDBSnapshotNotFoundFault: log.WithContext(ctx).Print("Could not find matching RDS snapshot; might have been deleted previously", field.M{"SnapshotId": snapshotID}) - return nil, nil + return nil default: - return nil, errkit.Wrap(err, "Failed to delete snapshot") + return errkit.Wrap(err, "Failed to delete snapshot") } } } // Wait until snapshot is deleted log.WithContext(ctx).Print("Waiting for RDS snapshot to be deleted", field.M{"SnapshotID": snapshotID}) err = rdsCli.WaitUntilDBSnapshotDeleted(ctx, snapshotID) - return nil, errkit.Wrap(err, "Error while waiting for snapshot to be deleted") + return errkit.Wrap(err, "Error while waiting for snapshot to be deleted") } // delete Aurora DB cluster snapshot @@ -102,9 +102,9 @@ func deleteRDSSnapshot(ctx context.Context, snapshotID string, profile *param.Pr switch err.Code() { case awsrds.ErrCodeDBClusterSnapshotNotFoundFault: log.WithContext(ctx).Print("Could not find matching Aurora DB cluster snapshot; might have been deleted previously", field.M{"SnapshotId": snapshotID}) - return nil, nil + return nil default: - return nil, errkit.Wrap(err, "Error deleting Aurora DB cluster snapshot") + return errkit.Wrap(err, "Error deleting Aurora DB cluster snapshot") } } } @@ -112,7 +112,7 @@ func deleteRDSSnapshot(ctx context.Context, snapshotID string, profile *param.Pr log.WithContext(ctx).Print("Waiting for Aurora DB cluster snapshot to be deleted") err = rdsCli.WaitUntilDBClusterDeleted(ctx, snapshotID) - return nil, errkit.Wrap(err, "Error waiting for Aurora DB cluster snapshot to be deleted") + return errkit.Wrap(err, "Error waiting for Aurora DB cluster snapshot to be deleted") } func (d *deleteRDSSnapshotFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) { @@ -130,7 +130,7 @@ func (d *deleteRDSSnapshotFunc) Exec(ctx context.Context, tp param.TemplateParam return nil, err } - return deleteRDSSnapshot(ctx, snapshotID, tp.Profile, dbEngine) + return nil, deleteRDSSnapshot(ctx, snapshotID, tp.Profile, dbEngine) } func (*deleteRDSSnapshotFunc) RequiredArgs() []string { diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 53ab0c9dc6..887c6cb666 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -60,7 +60,7 @@ func (*healthCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") - _, _ = io.WriteString(w, string(js)) + _, _ = io.Writer.Write(w, js) } // RunWebhookServer starts the validating webhook resources for blueprint kanister resources diff --git a/pkg/kube/pod.go b/pkg/kube/pod.go index 5819d02a00..8baf644565 100644 --- a/pkg/kube/pod.go +++ b/pkg/kube/pod.go @@ -167,7 +167,7 @@ func GetPodObjectFromPodOptions(ctx context.Context, cli kubernetes.Interface, o ServiceAccountName: sa, } - if opts.EnvironmentVariables != nil && len(opts.EnvironmentVariables) > 0 { + if len(opts.EnvironmentVariables) > 0 { defaultSpecs.Containers[0].Env = opts.EnvironmentVariables } diff --git a/pkg/kube/pod_test.go b/pkg/kube/pod_test.go index a2b93593bf..852dd29f10 100644 --- a/pkg/kube/pod_test.go +++ b/pkg/kube/pod_test.go @@ -252,7 +252,7 @@ func (s *PodSuite) TestPod(c *check.C) { c.Assert(pod.Spec.RestartPolicy, check.Equals, po.RestartPolicy) } - if po.EnvironmentVariables != nil && len(po.EnvironmentVariables) > 0 { + if len(po.EnvironmentVariables) > 0 { c.Assert(pod.Spec.Containers[0].Env, check.DeepEquals, po.EnvironmentVariables) }