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 9, 2024
1 parent 2bf6beb commit 3beca80
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 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
13 changes: 8 additions & 5 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var _ = Describe("controller", Ordered, func() {
Expect(utils.InstallCertManager()).To(Succeed())

By("creating manager namespace")
//nolint:gosec
cmd := exec.Command("kubectl", "create", "ns", namespace)
_, _ = utils.Run(cmd)
})
Expand All @@ -50,6 +51,7 @@ var _ = Describe("controller", Ordered, func() {
utils.UninstallCertManager()

By("removing manager namespace")
//nolint:gosec
cmd := exec.Command("kubectl", "delete", "ns", namespace)
_, _ = utils.Run(cmd)
})
Expand All @@ -63,6 +65,7 @@ var _ = Describe("controller", Ordered, func() {
var projectimage = "example.com/ceph-csi-operator:v0.0.1"

By("building the manager(Operator) image")
//nolint:gosec
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage))
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expand All @@ -72,19 +75,21 @@ var _ = Describe("controller", Ordered, func() {
ExpectWithOffset(1, err).NotTo(HaveOccurred())

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

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

By("validating that the controller-manager pod is running as expected")
verifyControllerUp := func() error {
// Get pod name

//nolint:gosec
cmd = exec.Command("kubectl", "get",
"pods", "-l", "control-plane=controller-manager",
"-o", "go-template={{ range .items }}"+
Expand All @@ -104,10 +109,8 @@ var _ = Describe("controller", Ordered, func() {
ExpectWithOffset(2, controllerPodName).Should(ContainSubstring("controller-manager"))

// Validate pod status
cmd = exec.Command("kubectl", "get",
"pods", controllerPodName, "-o", "jsonpath={.status.phase}",
"-n", namespace,
)
//nolint:gosec
cmd = exec.Command("kubectl", "get", "pods", controllerPodName, "-o", "jsonpath={.status.phase}", "-n", namespace)
status, err := utils.Run(cmd)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
if string(status) != "Running" {
Expand Down
8 changes: 7 additions & 1 deletion test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +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)
//nolint:gosec
cmd := exec.Command("kubectl", "create", "-f", url)
_, err := Run(cmd)
return err
Expand Down Expand Up @@ -69,6 +70,7 @@ func Run(cmd *exec.Cmd) ([]byte, error) {
// UninstallPrometheusOperator uninstalls the prometheus
func UninstallPrometheusOperator() {
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
//nolint:gosec
cmd := exec.Command("kubectl", "delete", "-f", url)
if _, err := Run(cmd); err != nil {
warnError(err)
Expand All @@ -78,6 +80,7 @@ func UninstallPrometheusOperator() {
// UninstallCertManager uninstalls the cert manager
func UninstallCertManager() {
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
//nolint:gosec
cmd := exec.Command("kubectl", "delete", "-f", url)
if _, err := Run(cmd); err != nil {
warnError(err)
Expand All @@ -87,12 +90,14 @@ func UninstallCertManager() {
// InstallCertManager installs the cert manager bundle.
func InstallCertManager() error {
url := fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
//nolint:gosec
cmd := exec.Command("kubectl", "apply", "-f", url)
if _, err := Run(cmd); err != nil {
return err
}
// Wait for cert-manager-webhook to be ready, which can take time if cert-manager
// was re-installed after uninstalling on a cluster.
// was re-installed after uninstalling on a cluster.\
//nolint:gosec
cmd = exec.Command("kubectl", "wait", "deployment.apps/cert-manager-webhook",
"--for", "condition=Available",
"--namespace", "cert-manager",
Expand All @@ -110,6 +115,7 @@ func LoadImageToKindClusterWithName(name string) error {
cluster = v
}
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
//nolint:gosec
cmd := exec.Command("kind", kindOptions...)
_, err := Run(cmd)
return err
Expand Down

0 comments on commit 3beca80

Please sign in to comment.