Skip to content

Commit

Permalink
ci: add gosec in golangci lint check
Browse files Browse the repository at this point in the history
adding gosec in golangci lint check, also skip gosec G204 as we don't
want to run gosec on exec method.

Signed-off-by: subhamkrai <[email protected]>
  • Loading branch information
subhamkrai committed Jul 8, 2024
1 parent 2bf6beb commit 86999a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linters:
- goimports
- gosimple
- govet
- gosec
- ineffassign
- lll
- misspell
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = Describe("controller", Ordered, func() {
Expect(utils.InstallCertManager()).To(Succeed())

By("creating manager namespace")
cmd := exec.Command("kubectl", "create", "ns", namespace)
cmd := exec.Command("kubectl", "create", "ns", namespace) //nolint:gosec
_, _ = utils.Run(cmd)
})

Expand All @@ -50,7 +50,7 @@ var _ = Describe("controller", Ordered, func() {
utils.UninstallCertManager()

By("removing manager namespace")
cmd := exec.Command("kubectl", "delete", "ns", namespace)
cmd := exec.Command("kubectl", "delete", "ns", namespace) //nolint:gosec
_, _ = utils.Run(cmd)
})

Expand All @@ -63,7 +63,7 @@ var _ = Describe("controller", Ordered, func() {
var projectimage = "example.com/ceph-csi-operator:v0.0.1"

By("building the manager(Operator) image")
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage))
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage)) //nolint:gosec
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

Expand All @@ -72,12 +72,12 @@ var _ = Describe("controller", Ordered, func() {
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("installing CRDs")
cmd = exec.Command("make", "install")
cmd = exec.Command("make", "install") //nolint:gosec
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("deploying the controller-manager")
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage))
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage)) //nolint:gosec
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

Expand All @@ -92,7 +92,7 @@ var _ = Describe("controller", Ordered, func() {
"{{ .metadata.name }}"+
"{{ \"\\n\" }}{{ end }}{{ end }}",
"-n", namespace,
)
) //nolint:gosec

podOutput, err := utils.Run(cmd)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
Expand All @@ -107,7 +107,7 @@ var _ = Describe("controller", Ordered, func() {
cmd = exec.Command("kubectl", "get",

Check failure on line 107 in test/e2e/e2e_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

G204: Subprocess launched with variable (gosec)
"pods", controllerPodName, "-o", "jsonpath={.status.phase}",
"-n", namespace,
)
) //nolint:gosec
status, err := utils.Run(cmd)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
if string(status) != "Running" {
Expand Down
12 changes: 6 additions & 6 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func warnError(err error) {
// InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics.
func InstallPrometheusOperator() error {
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
cmd := exec.Command("kubectl", "create", "-f", url)
cmd := exec.Command("kubectl", "create", "-f", url) //nolint:gosec
_, err := Run(cmd)
return err
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func Run(cmd *exec.Cmd) ([]byte, error) {
// UninstallPrometheusOperator uninstalls the prometheus
func UninstallPrometheusOperator() {
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
cmd := exec.Command("kubectl", "delete", "-f", url)
cmd := exec.Command("kubectl", "delete", "-f", url) //nolint:gosec
if _, err := Run(cmd); err != nil {
warnError(err)
}
Expand All @@ -78,7 +78,7 @@ func UninstallPrometheusOperator() {
// UninstallCertManager uninstalls the cert manager
func UninstallCertManager() {
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
cmd := exec.Command("kubectl", "delete", "-f", url)
cmd := exec.Command("kubectl", "delete", "-f", url) //nolint:gosec
if _, err := Run(cmd); err != nil {
warnError(err)
}
Expand All @@ -87,7 +87,7 @@ func UninstallCertManager() {
// InstallCertManager installs the cert manager bundle.
func InstallCertManager() error {
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
cmd := exec.Command("kubectl", "apply", "-f", url)
cmd := exec.Command("kubectl", "apply", "-f", url) //nolint:gosec
if _, err := Run(cmd); err != nil {
return err
}
Expand All @@ -97,7 +97,7 @@ func InstallCertManager() error {
"--for", "condition=Available",
"--namespace", "cert-manager",
"--timeout", "5m",
)
) //nolint:gosec

_, err := Run(cmd)
return err
Expand All @@ -110,7 +110,7 @@ func LoadImageToKindClusterWithName(name string) error {
cluster = v
}
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
cmd := exec.Command("kind", kindOptions...)
cmd := exec.Command("kind", kindOptions...) //nolint:gosec
_, err := Run(cmd)
return err
}
Expand Down

0 comments on commit 86999a0

Please sign in to comment.