Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exec.LookPath to check operator-sdk is in $PATH #1209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/operatorsdk/operatorsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ type execContext = func(name string, arg ...string) *exec.Cmd
func (o operatorSdk) Scorecard(ctx context.Context, image string, opts OperatorSdkScorecardOptions) (*OperatorSdkScorecardReport, error) {
logger := logr.FromContextOrDiscard(ctx)

// checking to make sure operator-sdk is in the $PATH
_, err := exec.LookPath("operator-sdk")
if err != nil {
return nil, fmt.Errorf("%v", err)
}

cmdArgs := []string{"scorecard"}
if opts.OutputFormat == "" {
opts.OutputFormat = "json"
Expand Down
8 changes: 8 additions & 0 deletions internal/operatorsdk/operatorsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/redhat-openshift-ecosystem/openshift-preflight/artifacts"
Expand All @@ -29,6 +30,13 @@ var _ = Describe("OperatorSdk", func() {
aw, err := artifacts.NewFilesystemWriter(artifacts.WithDirectory(tmpdir))
Expect(err).ToNot(HaveOccurred())

err = os.WriteFile(filepath.Join(tmpdir, "operator-sdk"), []byte("testcontents"), 0o755)
Expect(err).ToNot(HaveOccurred())

// updating PATH env to include the directory created in the test
err = os.Setenv("PATH", os.Getenv("PATH")+":"+tmpdir)
Expect(err).ToNot(HaveOccurred())

testcontext = artifacts.ContextWithWriter(context.Background(), aw)
})
When("The Scorecard result is good", func() {
Expand Down
Loading