From 45bb42205296c1e5271f3c4f6df029920a96c774 Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Tue, 7 Mar 2023 21:40:35 +1000 Subject: [PATCH] Upating linting --- .circleci/config.yml | 27 ------------------- .github/workflows/lint.yml | 2 +- Makefile | 8 ++---- .../apps/v1/deployment/image/read.go | 11 +++++--- internal/interfaceutils/interfaceutils.go | 2 +- .../core/v1/pod/container/args/expand.go | 2 +- .../core/v1/pod/container/command/expand.go | 2 +- .../rbac/v1/role/rule/apigroups/expand.go | 2 +- .../rbac/v1/role/rule/resourcenames/expand.go | 2 +- .../rbac/v1/role/rule/resources/expand.go | 2 +- .../rbac/v1/role/rule/verbs/expand.go | 2 +- internal/terraform/config/config.go | 3 +-- 12 files changed, 19 insertions(+), 46 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 4b702afb..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,27 +0,0 @@ -version: 2 - -workflows: - version: 2 - test: - jobs: - - lint - - unit - -jobs: - lint: - docker: - - image: golang:1.20 - working_directory: /go/src/github.com/previousnext/terraform-provider-k8s - steps: - - checkout - - run: | - go get golang.org/x/lint/golint - make lint - - unit: - docker: - - image: golang:1.20 - working_directory: /go/src/github.com/previousnext/terraform-provider-k8s - steps: - - checkout - - run: make test diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7ccafe4f..09b8919e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,4 +13,4 @@ jobs: go-version: '1.20' - uses: golangci/golangci-lint-action@v3 with: - args: --timeout=5m + args: --disable=errcheck --timeout=5m diff --git a/Makefile b/Makefile index 38cf3376..afa7623b 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,6 @@ build: # Run all lint checking with exit codes for CI lint: - golint -set_exit_status `go list ./... | grep -v /vendor/` + golangci-lint run --disable=errcheck --timeout=5m -# Run tests with coverage reporting -test: - # @todo, Unit tests for marshalling. - -.PHONY: build lint test +.PHONY: build lint diff --git a/internal/datasources/apps/v1/deployment/image/read.go b/internal/datasources/apps/v1/deployment/image/read.go index ca516819..0c6b913b 100644 --- a/internal/datasources/apps/v1/deployment/image/read.go +++ b/internal/datasources/apps/v1/deployment/image/read.go @@ -33,8 +33,11 @@ func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn deployment, err := conn.Kubernetes().AppsV1().Deployments(namespace).Get(ctx, name, metav1.GetOptions{}) if kerrors.IsNotFound(err) { - d.Set(FieldResult, fallback) - return nil + if err := d.Set(FieldResult, fallback); err != nil { + return diag.FromErr(err) + } + + return diags } else if err != nil { return diag.FromErr(err) } @@ -51,7 +54,9 @@ func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn result := getImage(deployment.Spec.Template.Spec.Containers, container, fallback) - d.Set(FieldResult, result) + if err := d.Set(FieldResult, result); err != nil { + return diag.FromErr(err) + } return diags } diff --git a/internal/interfaceutils/interfaceutils.go b/internal/interfaceutils/interfaceutils.go index af8b9f5b..b43e9907 100644 --- a/internal/interfaceutils/interfaceutils.go +++ b/internal/interfaceutils/interfaceutils.go @@ -2,7 +2,7 @@ package interfaceutils // ExpandSlice converts an interface slice to a string slice. func ExpandSlice(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { result[k] = v.(string) diff --git a/internal/resources/core/v1/pod/container/args/expand.go b/internal/resources/core/v1/pod/container/args/expand.go index 8b359f41..9a6bce23 100644 --- a/internal/resources/core/v1/pod/container/args/expand.go +++ b/internal/resources/core/v1/pod/container/args/expand.go @@ -2,7 +2,7 @@ package args // Expand will return a structured object. func Expand(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { result[k] = v.(string) diff --git a/internal/resources/core/v1/pod/container/command/expand.go b/internal/resources/core/v1/pod/container/command/expand.go index 8cebdb6d..272f6db3 100644 --- a/internal/resources/core/v1/pod/container/command/expand.go +++ b/internal/resources/core/v1/pod/container/command/expand.go @@ -2,7 +2,7 @@ package command // Expand will return a structured object. func Expand(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { result[k] = v.(string) diff --git a/internal/resources/rbac/v1/role/rule/apigroups/expand.go b/internal/resources/rbac/v1/role/rule/apigroups/expand.go index 6d3b76d5..0f3d80a4 100644 --- a/internal/resources/rbac/v1/role/rule/apigroups/expand.go +++ b/internal/resources/rbac/v1/role/rule/apigroups/expand.go @@ -2,7 +2,7 @@ package apigroups // Expand will return a structured object. func Expand(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { if v == nil { diff --git a/internal/resources/rbac/v1/role/rule/resourcenames/expand.go b/internal/resources/rbac/v1/role/rule/resourcenames/expand.go index e3909060..5c7843c9 100644 --- a/internal/resources/rbac/v1/role/rule/resourcenames/expand.go +++ b/internal/resources/rbac/v1/role/rule/resourcenames/expand.go @@ -2,7 +2,7 @@ package resourcenames // Expand will return a structured object. func Expand(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { result[k] = v.(string) diff --git a/internal/resources/rbac/v1/role/rule/resources/expand.go b/internal/resources/rbac/v1/role/rule/resources/expand.go index 41bbe140..ed0c7ec8 100644 --- a/internal/resources/rbac/v1/role/rule/resources/expand.go +++ b/internal/resources/rbac/v1/role/rule/resources/expand.go @@ -2,7 +2,7 @@ package resources // Expand will return a structured object. func Expand(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { result[k] = v.(string) diff --git a/internal/resources/rbac/v1/role/rule/verbs/expand.go b/internal/resources/rbac/v1/role/rule/verbs/expand.go index d9f47081..1e2f4068 100644 --- a/internal/resources/rbac/v1/role/rule/verbs/expand.go +++ b/internal/resources/rbac/v1/role/rule/verbs/expand.go @@ -2,7 +2,7 @@ package verbs // Expand will return a structured object. func Expand(s []interface{}) []string { - result := make([]string, len(s), len(s)) + result := make([]string, len(s)) for k, v := range s { result[k] = v.(string) diff --git a/internal/terraform/config/config.go b/internal/terraform/config/config.go index 7760eba7..d0a44acf 100644 --- a/internal/terraform/config/config.go +++ b/internal/terraform/config/config.go @@ -8,7 +8,6 @@ import ( awsconfig "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/sts" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform/terraform" "github.com/pkg/errors" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -31,7 +30,7 @@ func Func(d *schema.ResourceData) (interface{}, error) { cfg := &rest.Config{} // Overriding with static configuration - cfg.UserAgent = fmt.Sprintf("HashiCorp/1.0 Terraform/%s", terraform.VersionString()) + cfg.UserAgent = "HashiCorp/1.0 Terraform" if v, ok := d.GetOk(FieldHost); ok { cfg.Host = v.(string)