Skip to content

Util dir refactor #649

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

Merged
merged 8 commits into from
Oct 25, 2018
10 changes: 5 additions & 5 deletions commands/operator-sdk/cmd/add/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package add
import (
"log"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"

Expand Down Expand Up @@ -64,16 +64,16 @@ Example:

func apiRun(cmd *cobra.Command, args []string) {
// Create and validate new resource
cmdutil.MustInProjectRoot()
projutil.MustInProjectRoot()
r, err := scaffold.NewResource(apiVersion, kind)
if err != nil {
log.Fatal(err)
}

absProjectPath := cmdutil.MustGetwd()
absProjectPath := projutil.MustGetwd()

cfg := &input.Config{
Repo: cmdutil.CheckAndGetCurrPkg(),
Repo: projutil.CheckAndGetCurrPkg(),
AbsProjectPath: absProjectPath,
}

Expand All @@ -91,7 +91,7 @@ func apiRun(cmd *cobra.Command, args []string) {
}

// update deploy/role.yaml for the given resource r.
if err := cmdutil.UpdateRoleForResource(r, absProjectPath); err != nil {
if err := scaffold.UpdateRoleForResource(r, absProjectPath); err != nil {
log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): %v", r.APIVersion, r.Kind, err)
}

Expand Down
8 changes: 4 additions & 4 deletions commands/operator-sdk/cmd/add/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package add
import (
"log"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"

Expand Down Expand Up @@ -57,16 +57,16 @@ Example:
}

func controllerRun(cmd *cobra.Command, args []string) {
cmdutil.MustInProjectRoot()
projutil.MustInProjectRoot()
// Create and validate new resource
r, err := scaffold.NewResource(apiVersion, kind)
if err != nil {
log.Fatal(err)
}

cfg := &input.Config{
Repo: cmdutil.CheckAndGetCurrPkg(),
AbsProjectPath: cmdutil.MustGetwd(),
Repo: projutil.CheckAndGetCurrPkg(),
AbsProjectPath: projutil.MustGetwd(),
}

s := &scaffold.Scaffold{}
Expand Down
15 changes: 5 additions & 10 deletions commands/operator-sdk/cmd/add/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@ import (
"path/filepath"
"strings"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"

"github.com/spf13/cobra"
)

const (
goDir = "GOPATH"
deployCrdDir = "deploy"
)

// NewAddCrdCmd - add crd command
func NewAddCrdCmd() *cobra.Command {
crdCmd := &cobra.Command{
Expand All @@ -57,7 +52,7 @@ Generated CR filename: <project-name>/deploy/crds/<group>_<version>_<kind>_cr.y

func crdFunc(cmd *cobra.Command, args []string) {
cfg := &input.Config{
AbsProjectPath: cmdutil.MustGetwd(),
AbsProjectPath: projutil.MustGetwd(),
}
if len(args) != 0 {
log.Fatal("crd command doesn't accept any arguments")
Expand All @@ -83,7 +78,7 @@ func crdFunc(cmd *cobra.Command, args []string) {
}

// update deploy/role.yaml for the given resource r.
if err := cmdutil.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil {
if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil {
log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): %v", resource.APIVersion, resource.Kind, err)
}
}
Expand Down Expand Up @@ -111,8 +106,8 @@ func verifyCrdDeployPath() {
log.Fatalf("failed to determine the full path of the current directory: %v", err)
}
// check if the deploy sub-directory exist
_, err = os.Stat(filepath.Join(wd, deployCrdDir))
_, err = os.Stat(filepath.Join(wd, scaffold.DeployDir))
if err != nil {
log.Fatalf("the path (./%v) does not exist. run this command in your project directory", deployCrdDir)
log.Fatalf("the path (./%v) does not exist. run this command in your project directory", scaffold.DeployDir)
}
}
30 changes: 13 additions & 17 deletions commands/operator-sdk/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"os/exec"
"path/filepath"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
"github.com/operator-framework/operator-sdk/pkg/test"
Expand Down Expand Up @@ -132,16 +132,12 @@ func verifyTestManifest(image string) {
}
}

const (
mainGo = "./cmd/manager/main.go"
)

func buildFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalf("build command needs exactly 1 argument")
}

cmdutil.MustInProjectRoot()
projutil.MustInProjectRoot()
goBuildEnv := append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0")
wd, err := os.Getwd()
if err != nil {
Expand All @@ -150,8 +146,8 @@ func buildFunc(cmd *cobra.Command, args []string) {

// Don't need to buld go code if Ansible Operator
if mainExists() {
managerDir := filepath.Join(cmdutil.CheckAndGetCurrPkg(), "cmd/manager")
outputBinName := filepath.Join(wd, "build/_output/bin", filepath.Base(wd))
managerDir := filepath.Join(projutil.CheckAndGetCurrPkg(), scaffold.ManagerDir)
outputBinName := filepath.Join(wd, scaffold.BuildBinDir, filepath.Base(wd))
buildCmd := exec.Command("go", "build", "-o", outputBinName, managerDir)
buildCmd.Env = goBuildEnv
o, err := buildCmd.CombinedOutput()
Expand All @@ -178,20 +174,22 @@ func buildFunc(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stdout, string(o))

if enableTests {
buildTestCmd := exec.Command("go", "test", "-c", "-o", filepath.Join(wd, "build/_output/bin", filepath.Base(wd)+"-test"), testLocationBuild+"/...")
testBinary := filepath.Join(wd, scaffold.BuildBinDir, filepath.Base(wd)+"-test")
buildTestCmd := exec.Command("go", "test", "-c", "-o", testBinary, testLocationBuild+"/...")
buildTestCmd.Env = goBuildEnv
o, err := buildTestCmd.CombinedOutput()
if err != nil {
log.Fatalf("failed to build test binary: %v (%v)", err, string(o))
}
fmt.Fprintln(os.Stdout, string(o))
// if a user is using an older sdk repo as their library, make sure they have required build files
_, err = os.Stat("build/test-framework/Dockerfile")
testDockerfile := filepath.Join(scaffold.BuildTestDir, scaffold.DockerfileFile)
_, err = os.Stat(testDockerfile)
if err != nil && os.IsNotExist(err) {

absProjectPath := cmdutil.MustGetwd()
absProjectPath := projutil.MustGetwd()
cfg := &input.Config{
Repo: cmdutil.CheckAndGetCurrPkg(),
Repo: projutil.CheckAndGetCurrPkg(),
AbsProjectPath: absProjectPath,
ProjectName: filepath.Base(wd),
}
Expand All @@ -207,7 +205,7 @@ func buildFunc(cmd *cobra.Command, args []string) {
}
}

testDbcmd := exec.Command("docker", "build", ".", "-f", "build/test-framework/Dockerfile", "-t", image, "--build-arg", "NAMESPACEDMAN="+namespacedManBuild, "--build-arg", "BASEIMAGE="+baseImageName)
testDbcmd := exec.Command("docker", "build", ".", "-f", testDockerfile, "-t", image, "--build-arg", "NAMESPACEDMAN="+namespacedManBuild, "--build-arg", "BASEIMAGE="+baseImageName)
o, err = testDbcmd.CombinedOutput()
if err != nil {
log.Fatalf("failed to output build image %s: %v (%s)", image, err, string(o))
Expand All @@ -219,8 +217,6 @@ func buildFunc(cmd *cobra.Command, args []string) {
}

func mainExists() bool {
if _, err := os.Stat(mainGo); err == nil {
return true
}
return false
_, err := os.Stat(filepath.Join(scaffold.ManagerDir, scaffold.CmdFile))
return err == nil
}
Loading