From 31459c3f523d6c9343e81cb2c1f66d8a79c2594f Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 18 Oct 2018 17:14:05 -0700 Subject: [PATCH 1/4] pkg/scaffold/*: moved filename constants to respective scaffold files and exported them --- pkg/scaffold/apis.go | 4 +++- pkg/scaffold/build_dockerfile.go | 4 +++- pkg/scaffold/cmd.go | 4 +++- pkg/scaffold/constants.go | 24 ----------------------- pkg/scaffold/controller.go | 4 +++- pkg/scaffold/doc.go | 4 +++- pkg/scaffold/gitignore.go | 4 +++- pkg/scaffold/go_test_script.go | 6 ++++-- pkg/scaffold/gopkgtoml.go | 4 +++- pkg/scaffold/operator.go | 4 +++- pkg/scaffold/register.go | 4 +++- pkg/scaffold/role.go | 4 +++- pkg/scaffold/rolebinding.go | 4 +++- pkg/scaffold/service_account.go | 4 +++- pkg/scaffold/test_framework_dockerfile.go | 2 +- pkg/scaffold/test_pod.go | 4 +++- pkg/scaffold/version.go | 4 +++- 17 files changed, 47 insertions(+), 41 deletions(-) diff --git a/pkg/scaffold/apis.go b/pkg/scaffold/apis.go index 181d20e9fc5..f4810e3a90d 100644 --- a/pkg/scaffold/apis.go +++ b/pkg/scaffold/apis.go @@ -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 diff --git a/pkg/scaffold/build_dockerfile.go b/pkg/scaffold/build_dockerfile.go index f14f51e37c4..69c2778ede5 100644 --- a/pkg/scaffold/build_dockerfile.go +++ b/pkg/scaffold/build_dockerfile.go @@ -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 diff --git a/pkg/scaffold/cmd.go b/pkg/scaffold/cmd.go index acc33911793..b813955a7e8 100644 --- a/pkg/scaffold/cmd.go +++ b/pkg/scaffold/cmd.go @@ -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 diff --git a/pkg/scaffold/constants.go b/pkg/scaffold/constants.go index 1608ae36d6b..57fa71ca69b 100644 --- a/pkg/scaffold/constants.go +++ b/pkg/scaffold/constants.go @@ -19,10 +19,6 @@ import ( ) const ( - // Boolean values for Input.IsExec - isExecTrue = true - isExecFalse = false - // Separator to statically create directories. filePathSep = string(filepath.Separator) @@ -38,24 +34,4 @@ const ( olmCatalogDir = deployDir + filePathSep + "olm-catalog" crdsDir = deployDir + filePathSep + "crds" versionDir = "version" - - // files - cmdFile = "main.go" - apisFile = "apis.go" - controllerFile = "controller.go" - dockerfileFile = "Dockerfile" - goTestScriptFile = "go-test.sh" - versionFile = "version.go" - docFile = "doc.go" - registerFile = "register.go" - serviceAccountYamlFile = "service_account.yaml" - roleYamlFile = "role.yaml" - roleBindingYamlFile = "role_binding.yaml" - operatorYamlFile = "operator.yaml" - catalogPackageYamlFile = "package.yaml" - catalogCSVYamlFile = "csv.yaml" - testPodYamlFile = "test-pod.yaml" - gitignoreFile = ".gitignore" - gopkgtomlFile = "Gopkg.toml" - gopkglockFile = "Gopkg.lock" ) diff --git a/pkg/scaffold/controller.go b/pkg/scaffold/controller.go index 790a4c0f673..1f7d9f47afc 100644 --- a/pkg/scaffold/controller.go +++ b/pkg/scaffold/controller.go @@ -20,13 +20,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const ControllerFile = "controller.go" + type Controller struct { input.Input } func (s *Controller) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(controllerDir, controllerFile) + s.Path = filepath.Join(controllerDir, ControllerFile) } s.TemplateBody = controllerTmpl return s.Input, nil diff --git a/pkg/scaffold/doc.go b/pkg/scaffold/doc.go index ca58c491291..2a758bac4fa 100644 --- a/pkg/scaffold/doc.go +++ b/pkg/scaffold/doc.go @@ -21,6 +21,8 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const DocFile = "doc.go" + // Doc is the input needed to generate a pkg/apis///doc.go file type Doc struct { input.Input @@ -34,7 +36,7 @@ func (s *Doc) GetInput() (input.Input, error) { s.Path = filepath.Join(apisDir, strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), - docFile) + DocFile) } s.IfExistsAction = input.Skip s.TemplateBody = docTemplate diff --git a/pkg/scaffold/gitignore.go b/pkg/scaffold/gitignore.go index 3976d5890f3..b33b5f50697 100644 --- a/pkg/scaffold/gitignore.go +++ b/pkg/scaffold/gitignore.go @@ -18,13 +18,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const GitignoreFile = ".gitignore" + type Gitignore struct { input.Input } func (s *Gitignore) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = gitignoreFile + s.Path = GitignoreFile } s.TemplateBody = gitignoreTmpl return s.Input, nil diff --git a/pkg/scaffold/go_test_script.go b/pkg/scaffold/go_test_script.go index 0a832ac17e6..122834d5431 100644 --- a/pkg/scaffold/go_test_script.go +++ b/pkg/scaffold/go_test_script.go @@ -20,15 +20,17 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const GoTestScriptFile = "go-test.sh" + type GoTestScript struct { input.Input } func (s *GoTestScript) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(buildTestDir, goTestScriptFile) + s.Path = filepath.Join(buildTestDir, GoTestScriptFile) } - s.IsExec = isExecTrue + s.IsExec = true s.TemplateBody = goTestScriptTmpl return s.Input, nil } diff --git a/pkg/scaffold/gopkgtoml.go b/pkg/scaffold/gopkgtoml.go index 1552f7c3045..afd15bb8e0c 100644 --- a/pkg/scaffold/gopkgtoml.go +++ b/pkg/scaffold/gopkgtoml.go @@ -18,13 +18,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const GopkgTomlFile = "Gopkg.toml" + type GopkgToml struct { input.Input } func (s *GopkgToml) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = gopkgtomlFile + s.Path = GopkgTomlFile } s.TemplateBody = gopkgTomlTmpl return s.Input, nil diff --git a/pkg/scaffold/operator.go b/pkg/scaffold/operator.go index 96f8734d2f2..d86b1a59788 100644 --- a/pkg/scaffold/operator.go +++ b/pkg/scaffold/operator.go @@ -20,13 +20,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const OperatorYamlFile = "operator.yaml" + type Operator struct { input.Input } func (s *Operator) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, operatorYamlFile) + s.Path = filepath.Join(deployDir, OperatorYamlFile) } s.TemplateBody = operatorTemplate return s.Input, nil diff --git a/pkg/scaffold/register.go b/pkg/scaffold/register.go index 70c41b32291..b3dabc7c5ac 100644 --- a/pkg/scaffold/register.go +++ b/pkg/scaffold/register.go @@ -21,6 +21,8 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const RegisterFile = "register.go" + // Register is the input needed to generate a pkg/apis///register.go file type Register struct { input.Input @@ -34,7 +36,7 @@ func (s *Register) GetInput() (input.Input, error) { s.Path = filepath.Join(apisDir, strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), - registerFile) + RegisterFile) } // Do not overwrite this file if it exists. s.IfExistsAction = input.Skip diff --git a/pkg/scaffold/role.go b/pkg/scaffold/role.go index 6916ec18d96..58b941972d2 100644 --- a/pkg/scaffold/role.go +++ b/pkg/scaffold/role.go @@ -20,13 +20,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const RoleYamlFile = "role.yaml" + type Role struct { input.Input } func (s *Role) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, roleYamlFile) + s.Path = filepath.Join(deployDir, RoleYamlFile) } s.TemplateBody = roleTemplate return s.Input, nil diff --git a/pkg/scaffold/rolebinding.go b/pkg/scaffold/rolebinding.go index 88907b04918..dee9a0cb18d 100644 --- a/pkg/scaffold/rolebinding.go +++ b/pkg/scaffold/rolebinding.go @@ -20,13 +20,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const RoleBindingYamlFile = "role_binding.yaml" + type RoleBinding struct { input.Input } func (s *RoleBinding) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, roleBindingYamlFile) + s.Path = filepath.Join(deployDir, RoleBindingYamlFile) } s.TemplateBody = roleBindingTemplate return s.Input, nil diff --git a/pkg/scaffold/service_account.go b/pkg/scaffold/service_account.go index 361fce28df4..9f471f04ad1 100644 --- a/pkg/scaffold/service_account.go +++ b/pkg/scaffold/service_account.go @@ -20,13 +20,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const ServiceAccountYamlFile = "service_account.yaml" + type ServiceAccount struct { input.Input } func (s *ServiceAccount) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, serviceAccountYamlFile) + s.Path = filepath.Join(deployDir, ServiceAccountYamlFile) } s.TemplateBody = serviceAccountTemplate return s.Input, nil diff --git a/pkg/scaffold/test_framework_dockerfile.go b/pkg/scaffold/test_framework_dockerfile.go index 6fdf8d03616..8ac63b0cf4b 100644 --- a/pkg/scaffold/test_framework_dockerfile.go +++ b/pkg/scaffold/test_framework_dockerfile.go @@ -26,7 +26,7 @@ type TestFrameworkDockerfile struct { func (s *TestFrameworkDockerfile) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(buildTestDir, dockerfileFile) + s.Path = filepath.Join(buildTestDir, DockerfileFile) } s.TemplateBody = testFrameworkDockerfileTmpl return s.Input, nil diff --git a/pkg/scaffold/test_pod.go b/pkg/scaffold/test_pod.go index 9ae77fd56d6..d780efbb702 100644 --- a/pkg/scaffold/test_pod.go +++ b/pkg/scaffold/test_pod.go @@ -20,6 +20,8 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const TestPodYamlFile = "test-pod.yaml" + type TestPod struct { input.Input @@ -32,7 +34,7 @@ type TestPod struct { func (s *TestPod) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, testPodYamlFile) + s.Path = filepath.Join(deployDir, TestPodYamlFile) } s.TemplateBody = testPodTmpl return s.Input, nil diff --git a/pkg/scaffold/version.go b/pkg/scaffold/version.go index 60e8b78629d..87fab76387e 100644 --- a/pkg/scaffold/version.go +++ b/pkg/scaffold/version.go @@ -20,13 +20,15 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/input" ) +const VersionFile = "version.go" + type Version struct { input.Input } func (s *Version) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(versionDir, versionFile) + s.Path = filepath.Join(versionDir, VersionFile) } s.TemplateBody = versionTemplate return s.Input, nil From e7c4b302e62b51801e7c18e04c5f81386f947c38 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 18 Oct 2018 17:18:05 -0700 Subject: [PATCH 2/4] pkg/scaffold/*: exported directory names --- pkg/scaffold/add_controller.go | 2 +- pkg/scaffold/addtoscheme.go | 2 +- pkg/scaffold/apis.go | 2 +- pkg/scaffold/build_dockerfile.go | 2 +- pkg/scaffold/cmd.go | 2 +- pkg/scaffold/constants.go | 22 +++++++++++----------- pkg/scaffold/controller.go | 2 +- pkg/scaffold/controller_kind.go | 2 +- pkg/scaffold/cr.go | 2 +- pkg/scaffold/crd.go | 2 +- pkg/scaffold/doc.go | 2 +- pkg/scaffold/go_test_script.go | 2 +- pkg/scaffold/operator.go | 2 +- pkg/scaffold/register.go | 2 +- pkg/scaffold/role.go | 2 +- pkg/scaffold/rolebinding.go | 2 +- pkg/scaffold/service_account.go | 2 +- pkg/scaffold/test_framework_dockerfile.go | 2 +- pkg/scaffold/test_pod.go | 2 +- pkg/scaffold/types.go | 2 +- pkg/scaffold/version.go | 2 +- 21 files changed, 31 insertions(+), 31 deletions(-) diff --git a/pkg/scaffold/add_controller.go b/pkg/scaffold/add_controller.go index e77cc54c52c..a7f9310c71d 100644 --- a/pkg/scaffold/add_controller.go +++ b/pkg/scaffold/add_controller.go @@ -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 diff --git a/pkg/scaffold/addtoscheme.go b/pkg/scaffold/addtoscheme.go index b3e96e4f66a..343f8b263e2 100644 --- a/pkg/scaffold/addtoscheme.go +++ b/pkg/scaffold/addtoscheme.go @@ -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 diff --git a/pkg/scaffold/apis.go b/pkg/scaffold/apis.go index f4810e3a90d..5f32d7ce5b5 100644 --- a/pkg/scaffold/apis.go +++ b/pkg/scaffold/apis.go @@ -28,7 +28,7 @@ type Apis struct { 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 diff --git a/pkg/scaffold/build_dockerfile.go b/pkg/scaffold/build_dockerfile.go index 69c2778ede5..e62572a28e2 100644 --- a/pkg/scaffold/build_dockerfile.go +++ b/pkg/scaffold/build_dockerfile.go @@ -28,7 +28,7 @@ type Dockerfile struct { 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 diff --git a/pkg/scaffold/cmd.go b/pkg/scaffold/cmd.go index b813955a7e8..38f51f9357c 100644 --- a/pkg/scaffold/cmd.go +++ b/pkg/scaffold/cmd.go @@ -28,7 +28,7 @@ type Cmd struct { 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 diff --git a/pkg/scaffold/constants.go b/pkg/scaffold/constants.go index 57fa71ca69b..c71b6132366 100644 --- a/pkg/scaffold/constants.go +++ b/pkg/scaffold/constants.go @@ -23,15 +23,15 @@ const ( filePathSep = string(filepath.Separator) // dirs - cmdDir = "cmd" - managerDir = cmdDir + filePathSep + "manager" - pkgDir = "pkg" - apisDir = pkgDir + filePathSep + "apis" - controllerDir = pkgDir + filePathSep + "controller" - buildDir = "build" - buildTestDir = buildDir + filePathSep + "test-framework" - deployDir = "deploy" - olmCatalogDir = deployDir + filePathSep + "olm-catalog" - crdsDir = deployDir + filePathSep + "crds" - versionDir = "version" + CmdDir = "cmd" + ManagerDir = CmdDir + filePathSep + "manager" + PkgDir = "pkg" + ApisDir = PkgDir + filePathSep + "apis" + ControllerDir = PkgDir + filePathSep + "controller" + BuildDir = "build" + BuildTestDir = BuildDir + filePathSep + "test-framework" + DeployDir = "deploy" + OlmCatalogDir = DeployDir + filePathSep + "olm-catalog" + CrdsDir = DeployDir + filePathSep + "crds" + VersionDir = "version" ) diff --git a/pkg/scaffold/controller.go b/pkg/scaffold/controller.go index 1f7d9f47afc..d47fa919276 100644 --- a/pkg/scaffold/controller.go +++ b/pkg/scaffold/controller.go @@ -28,7 +28,7 @@ type Controller struct { func (s *Controller) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(controllerDir, ControllerFile) + s.Path = filepath.Join(ControllerDir, ControllerFile) } s.TemplateBody = controllerTmpl return s.Input, nil diff --git a/pkg/scaffold/controller_kind.go b/pkg/scaffold/controller_kind.go index 8a5bba1b3a2..d831066b0d9 100644 --- a/pkg/scaffold/controller_kind.go +++ b/pkg/scaffold/controller_kind.go @@ -31,7 +31,7 @@ type ControllerKind struct { func (s *ControllerKind) GetInput() (input.Input, error) { if s.Path == "" { fileName := s.Resource.LowerKind + "_controller.go" - s.Path = filepath.Join(controllerDir, s.Resource.LowerKind, fileName) + s.Path = filepath.Join(ControllerDir, s.Resource.LowerKind, fileName) } // Error if this file exists. s.IfExistsAction = input.Error diff --git a/pkg/scaffold/cr.go b/pkg/scaffold/cr.go index 609d24878ff..18d58cc03e2 100644 --- a/pkg/scaffold/cr.go +++ b/pkg/scaffold/cr.go @@ -36,7 +36,7 @@ func (s *Cr) GetInput() (input.Input, error) { strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), s.Resource.LowerKind) - s.Path = filepath.Join(crdsDir, fileName) + s.Path = filepath.Join(CrdsDir, fileName) } s.TemplateBody = crTemplate return s.Input, nil diff --git a/pkg/scaffold/crd.go b/pkg/scaffold/crd.go index cf9c9700cff..91ba943b612 100644 --- a/pkg/scaffold/crd.go +++ b/pkg/scaffold/crd.go @@ -36,7 +36,7 @@ func (s *Crd) GetInput() (input.Input, error) { strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), s.Resource.LowerKind) - s.Path = filepath.Join(crdsDir, fileName) + s.Path = filepath.Join(CrdsDir, fileName) } s.TemplateBody = crdTemplate return s.Input, nil diff --git a/pkg/scaffold/doc.go b/pkg/scaffold/doc.go index 2a758bac4fa..86bd812d7db 100644 --- a/pkg/scaffold/doc.go +++ b/pkg/scaffold/doc.go @@ -33,7 +33,7 @@ type Doc struct { func (s *Doc) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(apisDir, + s.Path = filepath.Join(ApisDir, strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), DocFile) diff --git a/pkg/scaffold/go_test_script.go b/pkg/scaffold/go_test_script.go index 122834d5431..2a4427887b9 100644 --- a/pkg/scaffold/go_test_script.go +++ b/pkg/scaffold/go_test_script.go @@ -28,7 +28,7 @@ type GoTestScript struct { func (s *GoTestScript) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(buildTestDir, GoTestScriptFile) + s.Path = filepath.Join(BuildTestDir, GoTestScriptFile) } s.IsExec = true s.TemplateBody = goTestScriptTmpl diff --git a/pkg/scaffold/operator.go b/pkg/scaffold/operator.go index d86b1a59788..3f63bdc114f 100644 --- a/pkg/scaffold/operator.go +++ b/pkg/scaffold/operator.go @@ -28,7 +28,7 @@ type Operator struct { func (s *Operator) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, OperatorYamlFile) + s.Path = filepath.Join(DeployDir, OperatorYamlFile) } s.TemplateBody = operatorTemplate return s.Input, nil diff --git a/pkg/scaffold/register.go b/pkg/scaffold/register.go index b3dabc7c5ac..7c8a0329a98 100644 --- a/pkg/scaffold/register.go +++ b/pkg/scaffold/register.go @@ -33,7 +33,7 @@ type Register struct { func (s *Register) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(apisDir, + s.Path = filepath.Join(ApisDir, strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), RegisterFile) diff --git a/pkg/scaffold/role.go b/pkg/scaffold/role.go index 58b941972d2..cf4d7eaf532 100644 --- a/pkg/scaffold/role.go +++ b/pkg/scaffold/role.go @@ -28,7 +28,7 @@ type Role struct { func (s *Role) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, RoleYamlFile) + s.Path = filepath.Join(DeployDir, RoleYamlFile) } s.TemplateBody = roleTemplate return s.Input, nil diff --git a/pkg/scaffold/rolebinding.go b/pkg/scaffold/rolebinding.go index dee9a0cb18d..a9718354f37 100644 --- a/pkg/scaffold/rolebinding.go +++ b/pkg/scaffold/rolebinding.go @@ -28,7 +28,7 @@ type RoleBinding struct { func (s *RoleBinding) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, RoleBindingYamlFile) + s.Path = filepath.Join(DeployDir, RoleBindingYamlFile) } s.TemplateBody = roleBindingTemplate return s.Input, nil diff --git a/pkg/scaffold/service_account.go b/pkg/scaffold/service_account.go index 9f471f04ad1..456f89a4921 100644 --- a/pkg/scaffold/service_account.go +++ b/pkg/scaffold/service_account.go @@ -28,7 +28,7 @@ type ServiceAccount struct { func (s *ServiceAccount) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, ServiceAccountYamlFile) + s.Path = filepath.Join(DeployDir, ServiceAccountYamlFile) } s.TemplateBody = serviceAccountTemplate return s.Input, nil diff --git a/pkg/scaffold/test_framework_dockerfile.go b/pkg/scaffold/test_framework_dockerfile.go index 8ac63b0cf4b..618c6bd912b 100644 --- a/pkg/scaffold/test_framework_dockerfile.go +++ b/pkg/scaffold/test_framework_dockerfile.go @@ -26,7 +26,7 @@ type TestFrameworkDockerfile struct { func (s *TestFrameworkDockerfile) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(buildTestDir, DockerfileFile) + s.Path = filepath.Join(BuildTestDir, DockerfileFile) } s.TemplateBody = testFrameworkDockerfileTmpl return s.Input, nil diff --git a/pkg/scaffold/test_pod.go b/pkg/scaffold/test_pod.go index d780efbb702..0bb423530b7 100644 --- a/pkg/scaffold/test_pod.go +++ b/pkg/scaffold/test_pod.go @@ -34,7 +34,7 @@ type TestPod struct { func (s *TestPod) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(deployDir, TestPodYamlFile) + s.Path = filepath.Join(DeployDir, TestPodYamlFile) } s.TemplateBody = testPodTmpl return s.Input, nil diff --git a/pkg/scaffold/types.go b/pkg/scaffold/types.go index 5c90f0224cb..ccf5d7d4364 100644 --- a/pkg/scaffold/types.go +++ b/pkg/scaffold/types.go @@ -31,7 +31,7 @@ type Types struct { func (s *Types) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(apisDir, + s.Path = filepath.Join(ApisDir, strings.ToLower(s.Resource.Group), strings.ToLower(s.Resource.Version), s.Resource.LowerKind+"_types.go") diff --git a/pkg/scaffold/version.go b/pkg/scaffold/version.go index 87fab76387e..f844062a6ca 100644 --- a/pkg/scaffold/version.go +++ b/pkg/scaffold/version.go @@ -28,7 +28,7 @@ type Version struct { func (s *Version) GetInput() (input.Input, error) { if s.Path == "" { - s.Path = filepath.Join(versionDir, VersionFile) + s.Path = filepath.Join(VersionDir, VersionFile) } s.TemplateBody = versionTemplate return s.Input, nil From 2e5c981524e952450ebe68e781badba5a9653ede Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 18 Oct 2018 17:26:05 -0700 Subject: [PATCH 3/4] pkg/scaffold/ansible/*: update Ansible scaffolds with scaffold constants --- pkg/scaffold/ansible/dockerfile.go | 3 ++- pkg/scaffold/ansible/operator.go | 3 ++- pkg/scaffold/ansible/playbook.go | 4 +++- pkg/scaffold/ansible/{watches_yaml.go => watches.go} | 6 ++---- 4 files changed, 9 insertions(+), 7 deletions(-) rename pkg/scaffold/ansible/{watches_yaml.go => watches.go} (95%) diff --git a/pkg/scaffold/ansible/dockerfile.go b/pkg/scaffold/ansible/dockerfile.go index 9d5c8af6a9d..dc49c141dff 100644 --- a/pkg/scaffold/ansible/dockerfile.go +++ b/pkg/scaffold/ansible/dockerfile.go @@ -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" ) @@ -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 diff --git a/pkg/scaffold/ansible/operator.go b/pkg/scaffold/ansible/operator.go index 7e2ade5a22c..c4031e7eb0d 100644 --- a/pkg/scaffold/ansible/operator.go +++ b/pkg/scaffold/ansible/operator.go @@ -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" ) @@ -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 diff --git a/pkg/scaffold/ansible/playbook.go b/pkg/scaffold/ansible/playbook.go index d1609cbdfe7..b0c4f634c7e 100644 --- a/pkg/scaffold/ansible/playbook.go +++ b/pkg/scaffold/ansible/playbook.go @@ -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 @@ -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 diff --git a/pkg/scaffold/ansible/watches_yaml.go b/pkg/scaffold/ansible/watches.go similarity index 95% rename from pkg/scaffold/ansible/watches_yaml.go rename to pkg/scaffold/ansible/watches.go index 0f5c7c45d5d..749bda165eb 100644 --- a/pkg/scaffold/ansible/watches_yaml.go +++ b/pkg/scaffold/ansible/watches.go @@ -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 { @@ -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 From 09d91f82834469854fb32522eb58ef99493988d7 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 18 Oct 2018 17:59:55 -0700 Subject: [PATCH 4/4] commands/operator-sdk/cmd/*,pkg/scaffold/constants.go: use scaffold constants instead of hard-coded strings for dirs and filenames --- commands/operator-sdk/cmd/add/crd.go | 9 ++----- commands/operator-sdk/cmd/build.go | 22 +++++++--------- commands/operator-sdk/cmd/generate/k8s.go | 9 +++---- commands/operator-sdk/cmd/test/cluster.go | 3 ++- commands/operator-sdk/cmd/test/local.go | 32 +++++++++++++---------- commands/operator-sdk/cmd/up/local.go | 7 +++-- pkg/scaffold/constants.go | 1 + 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/commands/operator-sdk/cmd/add/crd.go b/commands/operator-sdk/cmd/add/crd.go index 185242a3a2d..f63f04cc704 100644 --- a/commands/operator-sdk/cmd/add/crd.go +++ b/commands/operator-sdk/cmd/add/crd.go @@ -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{ @@ -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) } } diff --git a/commands/operator-sdk/cmd/build.go b/commands/operator-sdk/cmd/build.go index 247e26bc384..f3b694780bc 100644 --- a/commands/operator-sdk/cmd/build.go +++ b/commands/operator-sdk/cmd/build.go @@ -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") @@ -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() @@ -178,7 +174,8 @@ 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 { @@ -186,7 +183,8 @@ func buildFunc(cmd *cobra.Command, args []string) { } 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() @@ -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)) @@ -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 } diff --git a/commands/operator-sdk/cmd/generate/k8s.go b/commands/operator-sdk/cmd/generate/k8s.go index beaa45c774e..d7fac1f85c5 100644 --- a/commands/operator-sdk/cmd/generate/k8s.go +++ b/commands/operator-sdk/cmd/generate/k8s.go @@ -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) @@ -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) diff --git a/commands/operator-sdk/cmd/test/cluster.go b/commands/operator-sdk/cmd/test/cluster.go index 678dfb8538f..cb02ab939e4 100644 --- a/commands/operator-sdk/cmd/test/cluster.go +++ b/commands/operator-sdk/cmd/test/cluster.go @@ -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" @@ -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"}}, diff --git a/commands/operator-sdk/cmd/test/local.go b/commands/operator-sdk/cmd/test/local.go index 074ac0bd8d1..f075eb76186 100644 --- a/commands/operator-sdk/cmd/test/local.go +++ b/commands/operator-sdk/cmd/test/local.go @@ -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 @@ -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) } @@ -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{} diff --git a/commands/operator-sdk/cmd/up/local.go b/commands/operator-sdk/cmd/up/local.go index 650edb481be..5b5328d7bcc 100644 --- a/commands/operator-sdk/cmd/up/local.go +++ b/commands/operator-sdk/cmd/up/local.go @@ -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" @@ -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...) @@ -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 diff --git a/pkg/scaffold/constants.go b/pkg/scaffold/constants.go index c71b6132366..fdcbbccb067 100644 --- a/pkg/scaffold/constants.go +++ b/pkg/scaffold/constants.go @@ -30,6 +30,7 @@ const ( ControllerDir = PkgDir + filePathSep + "controller" BuildDir = "build" BuildTestDir = BuildDir + filePathSep + "test-framework" + BuildBinDir = BuildDir + filePathSep + "_output" + filePathSep + "bin" DeployDir = "deploy" OlmCatalogDir = DeployDir + filePathSep + "olm-catalog" CrdsDir = DeployDir + filePathSep + "crds"