Skip to content
Closed
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
9 changes: 2 additions & 7 deletions commands/operator-sdk/cmd/add/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ import (
"github.com/spf13/cobra"
)

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

// NewAddCrdCmd - add crd command
func NewAddCrdCmd() *cobra.Command {
crdCmd := &cobra.Command{
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)
}
}
22 changes: 9 additions & 13 deletions commands/operator-sdk/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ 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")
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(cmdutil.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,15 +174,17 @@ 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()
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
}
9 changes: 4 additions & 5 deletions commands/operator-sdk/cmd/generate/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func K8sCodegen() {
cmdutil.MustInProjectRoot()
repoPkg := cmdutil.CheckAndGetCurrPkg()
outputPkg := filepath.Join(repoPkg, "pkg/generated")
apisPkg := filepath.Join(repoPkg, "pkg/apis")
apisPkg := filepath.Join(repoPkg, scaffold.ApisDir)
groupVersions, err := parseGroupVersions()
if err != nil {
log.Fatalf("failed to parse group versions: (%v)", err)
Expand Down Expand Up @@ -79,16 +79,15 @@ func K8sCodegen() {
// in the format "groupA:v1,v2 groupB:v1 groupC:v2",
// as required by the generate-groups.sh script
func parseGroupVersions() (string, error) {
groupVersions := ""
apisDir := filepath.Join("pkg", "apis")
groups, err := ioutil.ReadDir(apisDir)
var groupVersions string
groups, err := ioutil.ReadDir(scaffold.ApisDir)
if err != nil {
return "", fmt.Errorf("could not read pkg/apis directory to find api Versions: %v", err)
}

for _, g := range groups {
if g.IsDir() {
groupDir := filepath.Join(apisDir, g.Name())
groupDir := filepath.Join(scaffold.ApisDir, g.Name())
versions, err := ioutil.ReadDir(groupDir)
if err != nil {
return "", fmt.Errorf("could not read %s directory to find api Versions: %v", groupDir, err)
Expand Down
3 changes: 2 additions & 1 deletion commands/operator-sdk/cmd/test/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"time"

"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/test"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -89,7 +90,7 @@ func testClusterFunc(cmd *cobra.Command, args []string) error {
Name: "operator-test",
Image: args[0],
ImagePullPolicy: pullPolicy,
Command: []string{"/go-test.sh"},
Command: []string{"/" + scaffold.GoTestScriptFile},
Env: []v1.EnvVar{{
Name: test.TestNamespaceEnv,
ValueFrom: &v1.EnvVarSource{FieldRef: &v1.ObjectFieldSelector{FieldPath: "metadata.namespace"}},
Expand Down
32 changes: 18 additions & 14 deletions commands/operator-sdk/cmd/test/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import (
"strings"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/test"

"github.com/spf13/cobra"
)

var deployTestDir = filepath.Join(scaffold.DeployDir, "test")

type testLocalConfig struct {
kubeconfig string
globalManPath string
Expand Down Expand Up @@ -65,25 +68,26 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
}
// if no namespaced manifest path is given, combine deploy/service_account.yaml, deploy/role.yaml, deploy/role_binding.yaml and deploy/operator.yaml
if tlConfig.namespacedManPath == "" {
err := os.MkdirAll("deploy/test", os.FileMode(cmdutil.DefaultDirFileMode))
err := os.MkdirAll(deployTestDir, os.FileMode(cmdutil.DefaultDirFileMode))
if err != nil {
log.Fatalf("could not create deploy/test: %v", err)
log.Fatalf("could not create %s: %v", deployTestDir, err)
}
tlConfig.namespacedManPath = "deploy/test/namespace-manifests.yaml"
tlConfig.namespacedManPath = filepath.Join(deployTestDir, "namespace-manifests.yaml")

sa, err := ioutil.ReadFile("deploy/service_account.yaml")
saFile := filepath.Join(scaffold.DeployDir, scaffold.ServiceAccountYamlFile)
sa, err := ioutil.ReadFile(saFile)
if err != nil {
log.Fatalf("could not find the manifest deploy/service_account.yaml: %v", err)
log.Fatalf("could not find the manifest %s: %v", saFile, err)
}
role, err := ioutil.ReadFile("deploy/role.yaml")
role, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.RoleYamlFile))
if err != nil {
log.Fatalf("could not find role manifest: %v", err)
}
roleBinding, err := ioutil.ReadFile("deploy/role_binding.yaml")
roleBinding, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.RoleBindingYamlFile))
if err != nil {
log.Fatalf("could not find role_binding manifest: %v", err)
}
operator, err := ioutil.ReadFile("deploy/operator.yaml")
operator, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.OperatorYamlFile))
if err != nil {
log.Fatalf("could not find operator manifest: %v", err)
}
Expand All @@ -105,21 +109,21 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
}()
}
if tlConfig.globalManPath == "" {
err := os.MkdirAll("deploy/test", os.FileMode(cmdutil.DefaultDirFileMode))
err := os.MkdirAll(deployTestDir, os.FileMode(cmdutil.DefaultDirFileMode))
if err != nil {
log.Fatalf("could not create deploy/test: %v", err)
log.Fatalf("could not create %s: %v", deployTestDir, err)
}
tlConfig.globalManPath = "deploy/test/global-manifests.yaml"
files, err := ioutil.ReadDir("deploy/crds")
tlConfig.globalManPath = filepath.Join(deployTestDir, "global-manifests.yaml")
files, err := ioutil.ReadDir(scaffold.CrdsDir)
if err != nil {
log.Fatalf("could not read deploy directory: %v", err)
}
var combined []byte
for _, file := range files {
if strings.HasSuffix(file.Name(), "crd.yaml") {
fileBytes, err := ioutil.ReadFile(filepath.Join("deploy/crds", file.Name()))
fileBytes, err := ioutil.ReadFile(filepath.Join(scaffold.CrdsDir, file.Name()))
if err != nil {
log.Fatalf("could not read file deploy/crds/%s: %v", file.Name(), err)
log.Fatalf("could not read file %s: %v", filepath.Join(scaffold.CrdsDir, file.Name()), err)
}
if combined == nil {
combined = []byte{}
Expand Down
7 changes: 5 additions & 2 deletions commands/operator-sdk/cmd/up/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import (
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
ansibleOperator "github.com/operator-framework/operator-sdk/pkg/ansible/operator"
proxy "github.com/operator-framework/operator-sdk/pkg/ansible/proxy"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
ansibleScaffold "github.com/operator-framework/operator-sdk/pkg/scaffold/ansible"
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
sdkVersion "github.com/operator-framework/operator-sdk/version"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand Down Expand Up @@ -96,7 +99,7 @@ func mustKubeConfig() {
}

func upLocal() {
args := []string{"run", filepath.Join("cmd", "manager", "main.go")}
args := []string{"run", filepath.Join(scaffold.ManagerDir, scaffold.CmdFile)}
if operatorFlags != "" {
extraArgs := strings.Split(operatorFlags, " ")
args = append(args, extraArgs...)
Expand Down Expand Up @@ -142,7 +145,7 @@ func upLocalAnsible() {
}

// start the operator
go ansibleOperator.Run(done, mgr, "./watches.yaml")
go ansibleOperator.Run(done, mgr, "./"+ansibleScaffold.WatchesYamlFile)

// wait for either to finish
err = <-done
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/add_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type AddController struct {
func (s *AddController) GetInput() (input.Input, error) {
if s.Path == "" {
fileName := "add_" + s.Resource.LowerKind + ".go"
s.Path = filepath.Join(controllerDir, fileName)
s.Path = filepath.Join(ControllerDir, fileName)
}
s.TemplateBody = addControllerTemplate
return s.Input, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/addtoscheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *AddToScheme) GetInput() (input.Input, error) {
fileName := fmt.Sprintf("addtoscheme_%s_%s.go",
strings.ToLower(s.Resource.Group),
strings.ToLower(s.Resource.Version))
s.Path = filepath.Join(apisDir, fileName)
s.Path = filepath.Join(ApisDir, fileName)
}
s.TemplateBody = addToSchemeTemplate
return s.Input, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/scaffold/ansible/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ansible
import (
"path/filepath"

"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

Expand All @@ -30,7 +31,7 @@ type Dockerfile struct {
// GetInput - gets the input
func (d *Dockerfile) GetInput() (input.Input, error) {
if d.Path == "" {
d.Path = filepath.Join("build", "Dockerfile")
d.Path = filepath.Join(scaffold.BuildDir, scaffold.DockerfileFile)
}
d.TemplateBody = dockerFileAnsibleTmpl
return d.Input, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/scaffold/ansible/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ansible
import (
"path/filepath"

"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

Expand All @@ -26,7 +27,7 @@ type Operator struct {

func (s *Operator) GetInput() (input.Input, error) {
if s.Path == "" {
s.Path = filepath.Join("deploy", "operator.yaml")
s.Path = filepath.Join(scaffold.DeployDir, scaffold.OperatorYamlFile)
}
s.TemplateBody = operatorTemplate
return s.Input, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/scaffold/ansible/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

const PlaybookYamlFile = "playbook.yaml"

// Playbook - the playbook tmpl wrapper
type Playbook struct {
input.Input
Expand All @@ -28,7 +30,7 @@ type Playbook struct {
// GetInput - gets the input
func (p *Playbook) GetInput() (input.Input, error) {
if p.Path == "" {
p.Path = "playbook.yaml"
p.Path = PlaybookYamlFile
}
p.TemplateBody = playbookTmpl
return p.Input, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import (
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

const (
watchesFile = "watches.yaml"
)
const WatchesYamlFile = "watches.yaml"

// WatchesYAML - watches yaml input wrapper
type WatchesYAML struct {
Expand All @@ -34,7 +32,7 @@ type WatchesYAML struct {
// GetInput - gets the input
func (s *WatchesYAML) GetInput() (input.Input, error) {
if s.Path == "" {
s.Path = watchesFile
s.Path = WatchesYamlFile
}
s.TemplateBody = watchesYAMLTmpl
return s.Input, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/scaffold/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

const ApisFile = "apis.go"

type Apis struct {
input.Input
}

func (s *Apis) GetInput() (input.Input, error) {
if s.Path == "" {
s.Path = filepath.Join(apisDir, apisFile)
s.Path = filepath.Join(ApisDir, ApisFile)
}
s.TemplateBody = apisTmpl
return s.Input, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/scaffold/build_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

const DockerfileFile = "Dockerfile"

type Dockerfile struct {
input.Input
}

func (s *Dockerfile) GetInput() (input.Input, error) {
if s.Path == "" {
s.Path = filepath.Join(buildDir, dockerfileFile)
s.Path = filepath.Join(BuildDir, DockerfileFile)
}
s.TemplateBody = dockerfileTmpl
return s.Input, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/scaffold/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
)

const CmdFile = "main.go"

type Cmd struct {
input.Input
}

func (s *Cmd) GetInput() (input.Input, error) {
if s.Path == "" {
s.Path = filepath.Join(managerDir, cmdFile)
s.Path = filepath.Join(ManagerDir, CmdFile)
}
s.TemplateBody = cmdTmpl
return s.Input, nil
Expand Down
Loading