From b659cde810b36618cb624057ce0f0218d1d276c4 Mon Sep 17 00:00:00 2001 From: Ashley-Joy Date: Fri, 8 Nov 2024 10:35:54 +0000 Subject: [PATCH 1/4] modify-actions --- .github/workflows/actions.yml | 83 ------------------------- .github/workflows/common-workflows.yaml | 18 ++++++ .github/workflows/go-version.yaml | 2 +- 3 files changed, 19 insertions(+), 84 deletions(-) delete mode 100644 .github/workflows/actions.yml create mode 100644 .github/workflows/common-workflows.yaml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml deleted file mode 100644 index 0b73752..0000000 --- a/.github/workflows/actions.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Workflow -on: - push: - branches: [main] - pull_request: - branches: [main] -jobs: - code-check: - name: Check Go formatting, linting, vetting - runs-on: ubuntu-latest - steps: - - name: Checkout the code - uses: actions/checkout@v4 - - name: Run the formatter, linter, and vetter - uses: dell/common-github-actions/go-code-formatter-linter-vetter@main - with: - directories: ./... - sanitize: - name: Check for forbidden words - runs-on: ubuntu-latest - steps: - - name: Checkout the code - uses: actions/checkout@v4 - - name: Run the forbidden words scan - uses: dell/common-github-actions/code-sanitizer@main - with: - args: /github/workspace - test: - name: Run Go unit tests and check package coverage - runs-on: ubuntu-latest - steps: - - name: Checkout the code - uses: actions/checkout@v4 - - name: Run unit tests and check package coverage - uses: dell/common-github-actions/go-code-tester@main - with: - threshold: 90 - go_security_scan: - name: Go security - runs-on: ubuntu-latest - steps: - - name: Checkout the code - uses: actions/checkout@v4 - - name: Run Go Security - uses: securego/gosec@master - malware_security_scan: - name: Malware Scanner - runs-on: ubuntu-latest - steps: - - name: Checkout the code - uses: actions/checkout@v4 - - name: Run malware scan - uses: dell/common-github-actions/malware-scanner@main - with: - directories: . - options: -ri - image_security_scan: - name: Image Scanner - runs-on: ubuntu-latest - steps: - - name: Set up Go latest - uses: actions/setup-go@v5 - with: - go-version: "1.23" - cache: false - id: go - - name: Checkout the code - uses: actions/checkout@v4 - - name: Install Mockgen - run: go install github.com/golang/mock/mockgen@v1.6.0 - - name: Get dependencies - run: go mod download - - name: Build csm-metrics-powerflex Docker Image - run: | - chmod +x ./scripts/build_ubi_micro.sh - make build-base-image - podman build -t docker.io/csm-metrics-powerflex -f ./Dockerfile --build-arg GOIMAGE=golang:latest --build-arg BASEIMAGE="localhost/mpfx-ubimicro" - podman save docker.io/library/csm-metrics-powerflex -o /tmp/csm-metrics-powerflex.tar - docker load -i /tmp/csm-metrics-powerflex.tar - - name: Run Trivy action - uses: aquasecurity/trivy-action@master - with: - image-ref: csm-metrics-powerflex diff --git a/.github/workflows/common-workflows.yaml b/.github/workflows/common-workflows.yaml new file mode 100644 index 0000000..9c9ba9d --- /dev/null +++ b/.github/workflows/common-workflows.yaml @@ -0,0 +1,18 @@ +name: Common Workflows +on: # yamllint disable-line rule:truthy + push: + branches: [main] + pull_request: + branches: ["**"] + +jobs: + + # golang static analysis checks + go-static-analysis: + uses: dell/common-github-actions/.github/workflows/go-static-analysis.yaml@main + name: Golang Validation + + # checks unit tests, package coverage, and gosec + common: + name: Run gosec, unit tests, and check package coverage + uses: dell/common-github-actions/.github/workflows/go-common.yml@main diff --git a/.github/workflows/go-version.yaml b/.github/workflows/go-version.yaml index 1ba387e..20a4366 100644 --- a/.github/workflows/go-version.yaml +++ b/.github/workflows/go-version.yaml @@ -9,7 +9,7 @@ # Reusable workflow to perform go version update on Golang based projects name: Go Version Update -on: +on: # yamllint disable-line rule:truthy workflow_dispatch: repository_dispatch: types: [go-update-workflow] From 64caa6fe0d8e3de97d32b8a99d9814c0fb5b94b8 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 12 Nov 2024 19:01:44 +0000 Subject: [PATCH 2/4] consoliate actions --- .github/workflows/actions.yml | 45 +++++++++++++++++++++++++ .github/workflows/common-workflows.yaml | 3 +- .github/workflows/linters.yaml | 30 ----------------- .golangci.yaml | 30 ----------------- 4 files changed, 46 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/actions.yml delete mode 100644 .github/workflows/linters.yaml delete mode 100644 .golangci.yaml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..ab77805 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,45 @@ +name: Workflow +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + sanitize: + name: Check for forbidden words + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + - name: Run the forbidden words scan + uses: dell/common-github-actions/code-sanitizer@main + with: + args: /github/workspace + + image_security_scan: + name: Image Scanner + runs-on: ubuntu-latest + steps: + - name: Set up Go latest + uses: actions/setup-go@v5 + with: + go-version: "1.23" + cache: false + id: go + - name: Checkout the code + uses: actions/checkout@v4 + - name: Install Mockgen + run: go install github.com/golang/mock/mockgen@v1.6.0 + - name: Get dependencies + run: go mod download + - name: Build csm-metrics-powerflex Docker Image + run: | + chmod +x ./scripts/build_ubi_micro.sh + make build-base-image + podman build -t docker.io/csm-metrics-powerflex -f ./Dockerfile --build-arg GOIMAGE=golang:latest --build-arg BASEIMAGE="localhost/mpfx-ubimicro" + podman save docker.io/library/csm-metrics-powerflex -o /tmp/csm-metrics-powerflex.tar + docker load -i /tmp/csm-metrics-powerflex.tar + - name: Run Trivy action + uses: aquasecurity/trivy-action@master + with: + image-ref: csm-metrics-powerflex diff --git a/.github/workflows/common-workflows.yaml b/.github/workflows/common-workflows.yaml index 9c9ba9d..05e4e07 100644 --- a/.github/workflows/common-workflows.yaml +++ b/.github/workflows/common-workflows.yaml @@ -12,7 +12,6 @@ jobs: uses: dell/common-github-actions/.github/workflows/go-static-analysis.yaml@main name: Golang Validation - # checks unit tests, package coverage, and gosec common: - name: Run gosec, unit tests, and check package coverage + name: Quality Checks uses: dell/common-github-actions/.github/workflows/go-common.yml@main diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml deleted file mode 100644 index 16b9903..0000000 --- a/.github/workflows/linters.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: linters - -on: - push: - branches: [main] - pull_request: - branches: ["**"] - -permissions: - contents: read - -jobs: - golangci-lint: - name: golangci-lint - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - cache: false - - name: Checkout the code - uses: actions/checkout@v4 - - name: Vendor packages - run: | - go mod vendor - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: latest - skip-cache: true diff --git a/.golangci.yaml b/.golangci.yaml deleted file mode 100644 index d20d7e0..0000000 --- a/.golangci.yaml +++ /dev/null @@ -1,30 +0,0 @@ -run: - timeout: 20m - issues-exit-code: 0 # we will change this later - tests: true - skip-dirs-use-default: true - modules-download-mode: readonly - -issues: - max-issues-per-linter: 0 - max-same-issues: 0 - new: false - -output: - print-linter-name: true - sort-results: true - uniq-by-line: false - print-issued-lines: true - -linters: - disable-all: true - fast: false - enable: - # A stricter replacement for gofmt. - - gofumpt - # Inspects source code for security problems. - - gosec - # Check for correctness of programs. - - govet - # Drop-in replacement of golint. - - revive From fa5bcf282f3cf2820f333bfeed8637e6d2c256bf Mon Sep 17 00:00:00 2001 From: root Date: Tue, 12 Nov 2024 20:47:20 +0000 Subject: [PATCH 3/4] fix linting --- internal/k8s/k8sapi_test.go | 2 +- internal/service/configuration_reader.go | 16 ++++++++-------- internal/service/service.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/k8s/k8sapi_test.go b/internal/k8s/k8sapi_test.go index 19ac9a8..b36e6d4 100644 --- a/internal/k8s/k8sapi_test.go +++ b/internal/k8s/k8sapi_test.go @@ -373,7 +373,7 @@ func Test_NewForConfigError(t *testing.T) { defer func() { k8s.NewConfigFn = oldNewConfigFn }() expected := "could not create Clientset from KubeConfig" k8s.NewConfigFn = func(_ *rest.Config) (*kubernetes.Clientset, error) { - return nil, fmt.Errorf(expected) + return nil, fmt.Errorf("%s", expected) } _, err := k8sapi.GetStorageClasses() diff --git a/internal/service/configuration_reader.go b/internal/service/configuration_reader.go index c7d48f4..4371d25 100644 --- a/internal/service/configuration_reader.go +++ b/internal/service/configuration_reader.go @@ -42,12 +42,12 @@ type ConfigurationReader struct{} // If no default system is supplied, the first system in the list is returned func (c *ConfigurationReader) GetStorageSystemConfiguration(file string) ([]ArrayConnectionData, error) { if _, err := os.Stat(file); os.IsNotExist(err) { - return nil, fmt.Errorf(fmt.Sprintf("File %s does not exist", file)) + return nil, fmt.Errorf("%s", fmt.Sprintf("File %s does not exist", file)) } config, err := os.ReadFile(filepath.Clean(file)) if err != nil { - return nil, fmt.Errorf(fmt.Sprintf("File %s errors: %v", file, err)) + return nil, fmt.Errorf("%s", fmt.Sprintf("File %s errors: %v", file, err)) } if string(config) == "" { @@ -58,12 +58,12 @@ func (c *ConfigurationReader) GetStorageSystemConfiguration(file string) ([]Arra // support backward compatibility config, err = yaml.JSONToYAML(config) if err != nil { - return nil, fmt.Errorf(fmt.Sprintf("converting json to yaml: %v", err)) + return nil, fmt.Errorf("%s", fmt.Sprintf("converting json to yaml: %v", err)) } err = yaml.Unmarshal(config, &connectionData) if err != nil { - return nil, fmt.Errorf(fmt.Sprintf("Unable to parse the credentials: %v", err)) + return nil, fmt.Errorf("%s", fmt.Sprintf("Unable to parse the credentials: %v", err)) } if len(connectionData) == 0 { @@ -82,16 +82,16 @@ func (c *ConfigurationReader) GetStorageSystemConfiguration(file string) ([]Arra func validateStorageSystem(system ArrayConnectionData, i int) error { if system.SystemID == "" { - return fmt.Errorf(fmt.Sprintf("invalid value for system name at index %d", i)) + return fmt.Errorf("%s", fmt.Sprintf("invalid value for system name at index %d", i)) } if system.Username == "" { - return fmt.Errorf(fmt.Sprintf("invalid value for Username at index %d", i)) + return fmt.Errorf("%s", fmt.Sprintf("invalid value for Username at index %d", i)) } if system.Password == "" { - return fmt.Errorf(fmt.Sprintf("invalid value for Password at index %d", i)) + return fmt.Errorf("%s", fmt.Sprintf("invalid value for Password at index %d", i)) } if system.Endpoint == "" { - return fmt.Errorf(fmt.Sprintf("invalid value for Endpoint at index %d", i)) + return fmt.Errorf("%s", fmt.Sprintf("invalid value for Endpoint at index %d", i)) } return nil } diff --git a/internal/service/service.go b/internal/service/service.go index 00a2198..2ab05d8 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -330,7 +330,7 @@ func (s *PowerFlexService) pushSDCMetrics(ctx context.Context, sdcMetrics <-chan if err != nil { s.Logger.WithError(err).WithField("sdc", mr.sdcMeta.ID).Error("recording statistics for sdc") } else { - ch <- fmt.Sprintf(mr.sdcMeta.ID) + ch <- fmt.Sprintf("%s", mr.sdcMeta.ID) } }(record) } @@ -525,7 +525,7 @@ func (s *PowerFlexService) pushVolumeMetrics(ctx context.Context, volumeMetrics if err != nil { s.Logger.WithError(err).WithField("volume_id", metrics.volumeMeta.ID).Error("recording statistics for volume") } else { - ch <- fmt.Sprintf(metrics.volumeMeta.ID) + ch <- fmt.Sprintf("%s", metrics.volumeMeta.ID) } }(metrics) } From 3189d02c29cb3195bbf9d44a054e2ce75380a797 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 12 Nov 2024 20:51:28 +0000 Subject: [PATCH 4/4] yaml lint --- .github/workflows/actions.yml | 2 +- .github/workflows/go-version.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index ab77805..23b16bf 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -1,5 +1,5 @@ name: Workflow -on: +on: # yamllint disable-line rule:truthy push: branches: [main] pull_request: diff --git a/.github/workflows/go-version.yaml b/.github/workflows/go-version.yaml index 20a4366..51df53b 100644 --- a/.github/workflows/go-version.yaml +++ b/.github/workflows/go-version.yaml @@ -9,7 +9,7 @@ # Reusable workflow to perform go version update on Golang based projects name: Go Version Update -on: # yamllint disable-line rule:truthy +on: # yamllint disable-line rule:truthy workflow_dispatch: repository_dispatch: types: [go-update-workflow]