From f8f203c526e3759f5ad63c1dba0d6f1065205989 Mon Sep 17 00:00:00 2001 From: varshaprasad96 Date: Fri, 24 Jul 2020 10:58:20 -0700 Subject: [PATCH] Remove operator-sdk new|add api commands and ansible scaffolding. This commit does the following: 1. Remove operator-sdk new and operator-sdk add api in favour of ansible plugins. 2. Remove ansible scaffolding (ie) internal/scaffold/ansible. 3. Remove internal/flags/apiflags/flags.go and relevant tests which were used in the commands. 4. Update IsOperatorAnsible() to check only for new layouts. 5. Remove hack/tests/e2e-ansible-molecule.sh and rewrite hack/tests/e2e-ansible.sh (which will get updated after ansible plugins). --- .../fragments/rm-cmd-legacy-ansible.yaml | 33 +++ cmd/operator-sdk/add/api.go | 162 ----------- cmd/operator-sdk/add/cmd.go | 1 - cmd/operator-sdk/cli/cli.go | 4 - cmd/operator-sdk/cli/legacy.go | 5 - cmd/operator-sdk/main.go | 1 - cmd/operator-sdk/new/cmd.go | 262 ------------------ internal/flags/apiflags/flags.go | 67 ----- internal/flags/apiflags/flags_test.go | 158 ----------- internal/scaffold/ansible/OWNERS | 6 - internal/scaffold/ansible/build_dockerfile.go | 59 ---- internal/scaffold/ansible/constants.go | 33 --- internal/scaffold/ansible/deploy_operator.go | 90 ------ internal/scaffold/ansible/input.go | 32 --- .../ansible/molecule_cluster_converge.go | 63 ----- .../ansible/molecule_cluster_create.go | 45 --- .../ansible/molecule_cluster_destroy.go | 76 ----- .../ansible/molecule_cluster_molecule.go | 77 ----- .../ansible/molecule_cluster_prepare.go | 73 ----- .../ansible/molecule_cluster_verify.go | 77 ----- .../ansible/molecule_default_converge.go | 54 ---- .../ansible/molecule_default_molecule.go | 84 ------ .../ansible/molecule_default_prepare.go | 66 ----- .../ansible/molecule_default_verify.go | 57 ---- .../ansible/molecule_templates_operator.go | 87 ------ .../ansible/molecule_test_local_converge.go | 84 ------ .../ansible/molecule_test_local_molecule.go | 86 ------ .../ansible/molecule_test_local_prepare.go | 42 --- .../ansible/molecule_test_local_verify.go | 41 --- internal/scaffold/ansible/playbook.go | 50 ---- internal/scaffold/ansible/requirements.go | 40 --- .../scaffold/ansible/roles_defaults_main.go | 44 --- internal/scaffold/ansible/roles_files.go | 40 --- .../scaffold/ansible/roles_handlers_main.go | 44 --- internal/scaffold/ansible/roles_meta_main.go | 105 ------- internal/scaffold/ansible/roles_readme.go | 84 ------ internal/scaffold/ansible/roles_tasks_main.go | 44 --- internal/scaffold/ansible/roles_templates.go | 40 --- internal/scaffold/ansible/roles_vars_main.go | 44 --- .../invalid/emptywatchfile/watches.yaml | 0 .../invalid/invalid_watch/watches.yaml | 4 - .../ansible/testdata/valid1/validWatches.yaml | 10 - .../ansible/testdata/valid2/validWatches.yaml | 10 - internal/scaffold/ansible/travis.go | 42 --- internal/scaffold/ansible/watches.go | 129 --------- internal/scaffold/ansible/watches_test.go | 164 ----------- internal/util/projutil/project_util.go | 28 +- website/content/en/docs/cli/operator-sdk.md | 1 - .../content/en/docs/cli/operator-sdk_new.md | 54 ---- 49 files changed, 40 insertions(+), 2862 deletions(-) create mode 100644 changelog/fragments/rm-cmd-legacy-ansible.yaml delete mode 100644 cmd/operator-sdk/add/api.go delete mode 100644 cmd/operator-sdk/new/cmd.go delete mode 100644 internal/flags/apiflags/flags.go delete mode 100644 internal/flags/apiflags/flags_test.go delete mode 100644 internal/scaffold/ansible/OWNERS delete mode 100644 internal/scaffold/ansible/build_dockerfile.go delete mode 100644 internal/scaffold/ansible/constants.go delete mode 100644 internal/scaffold/ansible/deploy_operator.go delete mode 100644 internal/scaffold/ansible/input.go delete mode 100644 internal/scaffold/ansible/molecule_cluster_converge.go delete mode 100644 internal/scaffold/ansible/molecule_cluster_create.go delete mode 100644 internal/scaffold/ansible/molecule_cluster_destroy.go delete mode 100644 internal/scaffold/ansible/molecule_cluster_molecule.go delete mode 100644 internal/scaffold/ansible/molecule_cluster_prepare.go delete mode 100644 internal/scaffold/ansible/molecule_cluster_verify.go delete mode 100644 internal/scaffold/ansible/molecule_default_converge.go delete mode 100644 internal/scaffold/ansible/molecule_default_molecule.go delete mode 100644 internal/scaffold/ansible/molecule_default_prepare.go delete mode 100644 internal/scaffold/ansible/molecule_default_verify.go delete mode 100644 internal/scaffold/ansible/molecule_templates_operator.go delete mode 100644 internal/scaffold/ansible/molecule_test_local_converge.go delete mode 100644 internal/scaffold/ansible/molecule_test_local_molecule.go delete mode 100644 internal/scaffold/ansible/molecule_test_local_prepare.go delete mode 100644 internal/scaffold/ansible/molecule_test_local_verify.go delete mode 100644 internal/scaffold/ansible/playbook.go delete mode 100644 internal/scaffold/ansible/requirements.go delete mode 100644 internal/scaffold/ansible/roles_defaults_main.go delete mode 100644 internal/scaffold/ansible/roles_files.go delete mode 100644 internal/scaffold/ansible/roles_handlers_main.go delete mode 100644 internal/scaffold/ansible/roles_meta_main.go delete mode 100644 internal/scaffold/ansible/roles_readme.go delete mode 100644 internal/scaffold/ansible/roles_tasks_main.go delete mode 100644 internal/scaffold/ansible/roles_templates.go delete mode 100644 internal/scaffold/ansible/roles_vars_main.go delete mode 100644 internal/scaffold/ansible/testdata/invalid/emptywatchfile/watches.yaml delete mode 100644 internal/scaffold/ansible/testdata/invalid/invalid_watch/watches.yaml delete mode 100644 internal/scaffold/ansible/testdata/valid1/validWatches.yaml delete mode 100644 internal/scaffold/ansible/testdata/valid2/validWatches.yaml delete mode 100644 internal/scaffold/ansible/travis.go delete mode 100644 internal/scaffold/ansible/watches.go delete mode 100644 internal/scaffold/ansible/watches_test.go delete mode 100644 website/content/en/docs/cli/operator-sdk_new.md diff --git a/changelog/fragments/rm-cmd-legacy-ansible.yaml b/changelog/fragments/rm-cmd-legacy-ansible.yaml new file mode 100644 index 0000000000..727f5ce28e --- /dev/null +++ b/changelog/fragments/rm-cmd-legacy-ansible.yaml @@ -0,0 +1,33 @@ +# entries is a list of entries to include in +# release notes and/or the migration guide +entries: + - description: > + The commands `operator-sdk new --type=ansible` and `operator-sdk add api` are no longer supported for Ansible-based Operators. + + # kind is one of: + # - addition + # - change + # - deprecation + # - removal + # - bugfix + kind: "removal" + + # Is this a breaking change? + breaking: true + + # NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS + # FILE FOR A PREVIOUSLY MERGED PULL_REQUEST! + # + # The generator auto-detects the PR number from the commit + # message in which this file was originally added. + # + # What is the pull request number (without the "#")? + # pull_request_override: 0 + + + # Migration can be defined to automatically add a section to + # the migration guide. This is required for breaking changes. + migration: + header: New and api subcommands are no longer supported for Ansible-based Operators. + body: > + TBD diff --git a/cmd/operator-sdk/add/api.go b/cmd/operator-sdk/add/api.go deleted file mode 100644 index 68ee4d48fd..0000000000 --- a/cmd/operator-sdk/add/api.go +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package add - -import ( - "fmt" - "os" - "path/filepath" - - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - - "github.com/operator-framework/operator-sdk/internal/flags/apiflags" - "github.com/operator-framework/operator-sdk/internal/genutil" - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/ansible" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" - "github.com/operator-framework/operator-sdk/internal/util/projutil" -) - -var apiFlags apiflags.APIFlags - -func newAddAPICmd() *cobra.Command { - apiCmd := &cobra.Command{ - Use: "api", - Short: "Adds a new api definition under pkg/apis", - Long: `operator-sdk add api --kind= --api-version -creates an API definition for a new custom resource. -This command must be run from the project root directory. - -For Go-based operators: - - - Creates the api definition for a new custom resource under pkg/apis. - - By default, this command runs Kubernetes deepcopy and CRD generators on - tagged types in all paths under pkg/apis. Go code is generated under - pkg/apis///zz_generated.deepcopy.go. Generation can be disabled with the - --skip-generation flag for Go-based operators. - -For Ansible-based operators: - - - Creates resource folder under /roles. - - watches.yaml is updated with new resource. - - deploy/role.yaml will be updated with apiGroup for new API. -CRD's are generated, or updated if they exist for a particular group + version + kind, under -deploy/crds/__crd.yaml; OpenAPI V3 validation YAML -is generated as a 'validation' object.`, - Example: ` # Create a new API, under an existing project. This command must be run from the project root directory. -# Go Example: - $ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService - -# Ansible Example - $ operator-sdk add api \ - --api-version=app.example.com/v1alpha1 \ - --kind=AppService -`, - RunE: apiRun, - } - - // Initialize flagSet struct with command flags - apiFlags.AddTo(apiCmd.Flags()) - - return apiCmd -} - -func apiRun(cmd *cobra.Command, args []string) error { - - projutil.MustInProjectRoot() - - operatorType := projutil.GetOperatorType() - if operatorType == projutil.OperatorTypeUnknown { - return projutil.ErrUnknownOperatorType{} - } - // Verify the incoming flags. - if err := apiFlags.VerifyCommonFlags(operatorType); err != nil { - return err - } - - log.Infof("Generating api version %s for kind %s.", apiFlags.APIVersion, apiFlags.Kind) - - switch operatorType { - case projutil.OperatorTypeGo: - return fmt.Errorf("the `add api` command is not supported for Go operators") - case projutil.OperatorTypeHelm: - return fmt.Errorf("the `add api` command is not supported for Helm operators") - case projutil.OperatorTypeAnsible: - if err := doAnsibleAPIScaffold(); err != nil { - return err - } - } - log.Info("API generation complete.") - return nil -} - -// TODO -// Consolidate scaffold func to be used by both "new" and "add api" commands. -func doAnsibleAPIScaffold() error { - // Create and validate new resource. - r, err := scaffold.NewResource(apiFlags.APIVersion, apiFlags.Kind) - if err != nil { - return fmt.Errorf("invalid apiVersion and kind: %v", err) - } - absProjectPath := projutil.MustGetwd() - cfg := &input.Config{ - AbsProjectPath: absProjectPath, - } - roleFiles := ansible.RolesFiles{Resource: *r} - roleTemplates := ansible.RolesTemplates{Resource: *r} - - // update watch.yaml for the given resource r. - if err := ansible.UpdateAnsibleWatchForResource(r, absProjectPath); err != nil { - return fmt.Errorf("failed to update the Watch manifest for the resource (%v, %v): (%v)", - r.APIVersion, r.Kind, err) - } - - s := &scaffold.Scaffold{} - err = s.Execute(cfg, - &scaffold.CR{Resource: r}, - &ansible.RolesReadme{Resource: *r}, - &ansible.RolesMetaMain{Resource: *r}, - &roleFiles, - &roleTemplates, - &ansible.RolesVarsMain{Resource: *r}, - &ansible.RolesDefaultsMain{Resource: *r}, - &ansible.RolesTasksMain{Resource: *r}, - &ansible.RolesHandlersMain{Resource: *r}, - ) - if err != nil { - return fmt.Errorf("new ansible api scaffold failed: %v", err) - } - if err = genutil.GenerateCRDNonGo("", *r, apiFlags.CrdVersion); err != nil { - return err - } - - // Remove placeholders from empty directories - err = os.Remove(filepath.Join(s.AbsProjectPath, roleFiles.Path)) - if err != nil { - return fmt.Errorf("new ansible api scaffold failed: %v", err) - } - err = os.Remove(filepath.Join(s.AbsProjectPath, roleTemplates.Path)) - if err != nil { - return fmt.Errorf("new ansible api scaffold failed: %v", err) - } - - // update deploy/role.yaml for the given resource r. - if err := scaffold.UpdateRoleForResource(r, absProjectPath); err != nil { - return fmt.Errorf("failed to update the RBAC manifest for the resource (%v, %v): (%v)", - r.APIVersion, r.Kind, err) - } - return nil -} diff --git a/cmd/operator-sdk/add/cmd.go b/cmd/operator-sdk/add/cmd.go index 51aa932978..37bb058eca 100644 --- a/cmd/operator-sdk/add/cmd.go +++ b/cmd/operator-sdk/add/cmd.go @@ -25,7 +25,6 @@ func NewCmd() *cobra.Command { Long: "", } - cmd.AddCommand(newAddAPICmd()) cmd.AddCommand(newAddCRDCmd()) return cmd } diff --git a/cmd/operator-sdk/cli/cli.go b/cmd/operator-sdk/cli/cli.go index b38c5ffbb2..ddd0ae36d6 100644 --- a/cmd/operator-sdk/cli/cli.go +++ b/cmd/operator-sdk/cli/cli.go @@ -20,7 +20,6 @@ import ( "github.com/operator-framework/operator-sdk/cmd/operator-sdk/cleanup" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate" - "github.com/operator-framework/operator-sdk/cmd/operator-sdk/new" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/olm" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/run" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard" @@ -38,9 +37,6 @@ import ( ) var commands = []*cobra.Command{ - // The "new" cmd provides a way to scaffold Helm/Ansible projects - // from the new CLI. - new.NewCmd(), scorecard.NewCmd(), build.NewCmd(), bundle.NewCmd(), diff --git a/cmd/operator-sdk/cli/legacy.go b/cmd/operator-sdk/cli/legacy.go index 8e4b7f8ec9..329f3ef943 100644 --- a/cmd/operator-sdk/cli/legacy.go +++ b/cmd/operator-sdk/cli/legacy.go @@ -19,10 +19,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/operator-framework/operator-sdk/cmd/operator-sdk/add" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/build" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion" - "github.com/operator-framework/operator-sdk/cmd/operator-sdk/new" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/olm" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/version" @@ -61,11 +59,9 @@ func GetCLIRoot() *cobra.Command { } root.AddCommand( - add.NewCmd(), build.NewCmd(), scorecard.NewCmd(), completion.NewCmd(), - new.NewCmd(), olm.NewCmd(), version.NewCmd(), ) @@ -95,7 +91,6 @@ func checkGoModulesForCmd(cmd *cobra.Command) (err error) { } var commandsToSkip = map[string]struct{}{ - "new": struct{}{}, // Handles this logic in cmd/operator-sdk/new "operator-sdk": struct{}{}, // Alias for "help" "help": struct{}{}, "completion": struct{}{}, diff --git a/cmd/operator-sdk/main.go b/cmd/operator-sdk/main.go index f75449dc7c..8db6554d9e 100644 --- a/cmd/operator-sdk/main.go +++ b/cmd/operator-sdk/main.go @@ -58,7 +58,6 @@ func main() { } // Run the KB CLI when not running in either legacy or new projects - // The new CLI still supports "operator-sdk new --type=Ansible/Helm" if err := cli.Run(); err != nil { log.Fatal(err) } diff --git a/cmd/operator-sdk/new/cmd.go b/cmd/operator-sdk/new/cmd.go deleted file mode 100644 index 96c7192818..0000000000 --- a/cmd/operator-sdk/new/cmd.go +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package new - -import ( - "fmt" - "os" - "os/exec" - "path/filepath" - "strings" - - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - - "github.com/operator-framework/operator-sdk/internal/flags/apiflags" - "github.com/operator-framework/operator-sdk/internal/genutil" - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/ansible" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" - "github.com/operator-framework/operator-sdk/internal/util/projutil" -) - -func NewCmd() *cobra.Command { //nolint:golint - /* - The nolint here is used to hide the warning - "func name will be used as new.NewCmd by other packages, - and that stutters; consider calling this Cmd" - which is a false positive. - */ - newCmd := &cobra.Command{ - Use: "new ", - Short: "Creates a new operator application", - Long: `The operator-sdk new command creates a new operator application and -generates a default directory layout based on the input . - - is the project name of the new operator. (e.g app-operator) -`, - Example: ` # Create a new project directory - $ mkdir $HOME/projects/example.com/ - $ cd $HOME/projects/example.com/ - - # Ansible project - $ operator-sdk new app-operator --type=ansible \ - --api-version=app.example.com/v1alpha1 \ - --kind=AppService -`, - RunE: newFunc, - } - - newCmd.Flags().StringVar(&operatorType, "type", "ansible", - "Type of operator to initialize (choices: \"ansible\")") - if err := newCmd.Flags().MarkHidden("type"); err != nil { - log.Fatalf("Failed to mark `type` flag for `new` subcommand as hidden") - } - - // todo(camilamacedo86): remove before 1.0.0 - newCmd.Flags().BoolVar(&gitInit, "git-init", false, - "Initialize the project directory as a git repository (default false)") - err := newCmd.Flags().MarkDeprecated("git-init", - "instead run `git init` once your project is created to use git") - if err != nil { - log.Fatal(err) - } - - newCmd.Flags().BoolVar(&generatePlaybook, "generate-playbook", false, - "Generate a playbook skeleton. (Only used for --type ansible)") - - // Initialize flagSet struct with common flags - apiFlags.AddTo(newCmd.Flags()) - - return newCmd -} - -var ( - apiFlags apiflags.APIFlags - operatorType string - projectName string - gitInit bool - generatePlaybook bool -) - -func newFunc(cmd *cobra.Command, args []string) error { - if err := parse(cmd, args); err != nil { - return err - } - mustBeNewProject() - if err := apiFlags.VerifyCommonFlags(operatorType); err != nil { - return err - } - - log.Infof("Creating new %s operator '%s'.", strings.Title(operatorType), projectName) - - switch operatorType { - case projutil.OperatorTypeAnsible: - if err := doAnsibleScaffold(); err != nil { - log.Fatal(err) - } - } - //todo: remove before 1.0.0 - if gitInit { - if err := initGit(); err != nil { - log.Fatal(err) - } - } - - log.Info("Project creation complete.") - return nil -} - -func parse(cmd *cobra.Command, args []string) error { - if len(args) != 1 { - return fmt.Errorf("command %s requires exactly one argument", cmd.CommandPath()) - } - projectName = args[0] - if len(projectName) == 0 { - return fmt.Errorf("project name must not be empty") - } - return nil -} - -// mustBeNewProject checks if the given project exists under the current diretory. -// it exits with error when the project exists. -func mustBeNewProject() { - fp := filepath.Join(projutil.MustGetwd(), projectName) - stat, err := os.Stat(fp) - if err != nil && os.IsNotExist(err) { - return - } - if err != nil { - log.Fatalf("Failed to determine if project (%v) exists", projectName) - } - if stat.IsDir() { - log.Fatalf("Project (%v) in (%v) path already exists. Please use a different project name or delete "+ - "the existing one", projectName, fp) - } -} - -func doAnsibleScaffold() error { - cfg := &input.Config{ - AbsProjectPath: filepath.Join(projutil.MustGetwd(), projectName), - ProjectName: projectName, - } - - resource, err := scaffold.NewResource(apiFlags.APIVersion, apiFlags.Kind) - if err != nil { - return fmt.Errorf("invalid apiVersion and kind: %v", err) - } - - roleFiles := ansible.RolesFiles{Resource: *resource} - roleTemplates := ansible.RolesTemplates{Resource: *resource} - - s := &scaffold.Scaffold{} - err = s.Execute(cfg, - &scaffold.ServiceAccount{}, - &scaffold.Role{}, - &scaffold.RoleBinding{}, - &scaffold.CR{Resource: resource}, - &ansible.BuildDockerfile{GeneratePlaybook: generatePlaybook}, - &ansible.RolesReadme{Resource: *resource}, - &ansible.RolesMetaMain{Resource: *resource}, - &roleFiles, - &roleTemplates, - &ansible.RolesVarsMain{Resource: *resource}, - &ansible.MoleculeTestLocalConverge{Resource: *resource}, - &ansible.RolesDefaultsMain{Resource: *resource}, - &ansible.RolesTasksMain{Resource: *resource}, - &ansible.MoleculeDefaultMolecule{}, - &ansible.MoleculeDefaultPrepare{}, - &ansible.MoleculeDefaultConverge{ - GeneratePlaybook: generatePlaybook, - Resource: *resource, - }, - &ansible.MoleculeDefaultVerify{}, - &ansible.RolesHandlersMain{Resource: *resource}, - &ansible.Watches{ - GeneratePlaybook: generatePlaybook, - Resource: *resource, - }, - &ansible.DeployOperator{}, - &ansible.Travis{}, - &ansible.RequirementsYml{}, - &ansible.MoleculeTestLocalMolecule{}, - &ansible.MoleculeTestLocalPrepare{}, - &ansible.MoleculeTestLocalVerify{}, - &ansible.MoleculeClusterMolecule{Resource: *resource}, - &ansible.MoleculeClusterCreate{}, - &ansible.MoleculeClusterPrepare{Resource: *resource}, - &ansible.MoleculeClusterConverge{}, - &ansible.MoleculeClusterVerify{Resource: *resource}, - &ansible.MoleculeClusterDestroy{Resource: *resource}, - &ansible.MoleculeTemplatesOperator{}, - ) - if err != nil { - return fmt.Errorf("new ansible scaffold failed: %v", err) - } - - if err = genutil.GenerateCRDNonGo(projectName, *resource, apiFlags.CrdVersion); err != nil { - return err - } - - // Remove placeholders from empty directories - err = os.Remove(filepath.Join(s.AbsProjectPath, roleFiles.Path)) - if err != nil { - return fmt.Errorf("new ansible scaffold failed: %v", err) - } - err = os.Remove(filepath.Join(s.AbsProjectPath, roleTemplates.Path)) - if err != nil { - return fmt.Errorf("new ansible scaffold failed: %v", err) - } - - // Decide on playbook. - if generatePlaybook { - log.Infof("Generating %s playbook.", strings.Title(operatorType)) - - err := s.Execute(cfg, - &ansible.Playbook{Resource: *resource}, - ) - if err != nil { - return fmt.Errorf("new ansible playbook scaffold failed: %v", err) - } - } - - // update deploy/role.yaml for the given resource r. - if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil { - return fmt.Errorf("failed to update the RBAC manifest for the resource (%v, %v): %v", - resource.APIVersion, resource.Kind, err) - } - return nil -} - -// todo(camilamacedo86): remove before 1.0.0 -// Deprecated: the git-init flag was deprecated since has no need to make the command run the git init. -// users are allowed to easily do that when they wish. This func is just used here to run the git-init -func execProjCmd(cmd string, args ...string) error { - dc := exec.Command(cmd, args...) - dc.Dir = filepath.Join(projutil.MustGetwd(), projectName) - return projutil.ExecCmd(dc) -} - -// todo(camilamacedo86): remove before 1.0.0 -// Deprecated: the git-init flag was deprecated since has no need to make the command run the git init. -// users are allowed to easily do that when they wish. -func initGit() error { - log.Info("Running git init") - if err := execProjCmd("git", "init"); err != nil { - return fmt.Errorf("failed to run git init: %v", err) - } - log.Info("Run git init done") - return nil -} diff --git a/internal/flags/apiflags/flags.go b/internal/flags/apiflags/flags.go deleted file mode 100644 index 6bc1ef9568..0000000000 --- a/internal/flags/apiflags/flags.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apiflags - -import ( - "fmt" - "strings" - - "github.com/spf13/pflag" - - gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd" -) - -type APIFlags struct { - SkipGeneration bool - APIVersion string - Kind string - CrdVersion string -} - -// AddTo - Add the reconcile period and watches file flags to the the flagset -// helpTextPrefix will allow you add a prefix to default help text. Joined by a space. -func (f *APIFlags) AddTo(flagSet *pflag.FlagSet) { - flagSet.StringVar(&f.APIVersion, "api-version", "", - "Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)") - - flagSet.StringVar(&f.Kind, "kind", "", - "Kubernetes resource Kind name. (e.g AppService)") - - flagSet.BoolVar(&f.SkipGeneration, "skip-generation", false, - "Skip generation of deepcopy and OpenAPI code and OpenAPI CRD specs") - - flagSet.StringVar(&f.CrdVersion, "crd-version", gencrd.DefaultCRDVersion, - "CRD version to generate") - -} - -// VerifyCommonFlags func is used to verify flags common to both "new" and "add api" commands. -func (f *APIFlags) VerifyCommonFlags(operatorType string) error { - if len(f.APIVersion) == 0 { - return fmt.Errorf("value of --api-version must not have empty value") - } - if len(f.Kind) == 0 { - return fmt.Errorf("value of --kind must not have empty value") - } - kindFirstLetter := string(f.Kind[0]) - if kindFirstLetter != strings.ToUpper(kindFirstLetter) { - return fmt.Errorf("value of --kind must start with an uppercase letter") - } - if strings.Count(f.APIVersion, "/") != 1 { - return fmt.Errorf("value of --api-version has wrong format (%v);"+ - " format must be $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)", f.APIVersion) - } - return nil -} diff --git a/internal/flags/apiflags/flags_test.go b/internal/flags/apiflags/flags_test.go deleted file mode 100644 index b24b9ccd31..0000000000 --- a/internal/flags/apiflags/flags_test.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apiflags - -import ( - "fmt" - "testing" - - "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" -) - -func TestAddTo(t *testing.T) { - testCases := []struct { - name string - apiFlags APIFlags - validate func(APIFlags, *pflag.FlagSet) error - }{ - { - // Populate FlagSet - name: "Populate FlagSet", - apiFlags: APIFlags{ - APIVersion: "app.example.com/v1alpha1", - Kind: "AppService", - SkipGeneration: false, - CrdVersion: "v1", - }, - validate: func(apiFlags APIFlags, flagSet *pflag.FlagSet) error { - val, err := flagSet.GetString("api-version") - if err != nil { - return err - } - if apiFlags.APIVersion != val { - return fmt.Errorf("apiVersion does not match") - } - - val, err = flagSet.GetString("kind") - if err != nil { - return err - } - if apiFlags.Kind != val { - return fmt.Errorf("kind does not match") - } - - boolVal, err := flagSet.GetBool("skip-generation") - if err != nil { - return err - } - if apiFlags.SkipGeneration != boolVal { - return fmt.Errorf("skipGeneration does not match") - } - - val, err = flagSet.GetString("crd-version") - if err != nil { - return err - } - if apiFlags.CrdVersion != val { - return fmt.Errorf("crdVersion does not match") - } - - return nil - }, - }, - } - - for _, tc := range testCases { - expFlags := &pflag.FlagSet{} - t.Run(tc.name, func(t *testing.T) { - tc.apiFlags.AddTo(expFlags) - if tc.validate != nil { - if err := tc.validate(tc.apiFlags, expFlags); err != nil { - t.Fatal("Unexpected error validating AddTo", err) - } - } - }) - } -} - -func TestVerifyCommonFlags(t *testing.T) { - testCases := []struct { - name string - apiFlags APIFlags - operatorType string - expError string - }{ - { - // Valid Go API Flags - name: "Valid Go API Flags", - apiFlags: APIFlags{ - APIVersion: "app.example.com/v1alpha1", - Kind: "AppService", - SkipGeneration: false, - }, - operatorType: "go", - expError: "", - }, - { - // Valid Ansible API Flags - name: "Valid Ansible API Flags", - apiFlags: APIFlags{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - CrdVersion: "v1", - }, - operatorType: "ansible", - expError: "", - }, - { - // Valid Ansible API Flags - name: "Valid Ansible API Flags-check dup", - apiFlags: APIFlags{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - }, - operatorType: "ansible", - expError: "", - }, - { - // Invalid Ansible API Flags - name: "Invalid Ansible API Flags-Kind not present", - apiFlags: APIFlags{ - APIVersion: "app.example.com/v1alpha1", - }, - operatorType: "ansible", - expError: "value of --kind must not have empty value", - }, - { - // Invalid Ansible API Flags - name: "Invalid Ansible API Flags-apiVersion not present", - apiFlags: APIFlags{ - Kind: "App", - }, - operatorType: "ansible", - expError: "value of --api-version must not have empty value", - }, - } - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - var result string - if err := tc.apiFlags.VerifyCommonFlags(tc.operatorType); err != nil { - result = err.Error() - } - assert.Equal(t, tc.expError, result) - }) - } -} diff --git a/internal/scaffold/ansible/OWNERS b/internal/scaffold/ansible/OWNERS deleted file mode 100644 index 9702fa3403..0000000000 --- a/internal/scaffold/ansible/OWNERS +++ /dev/null @@ -1,6 +0,0 @@ -approvers: - - fabianvf - - jmrodri -reviewers: - - fabianvf - - jmrodri diff --git a/internal/scaffold/ansible/build_dockerfile.go b/internal/scaffold/ansible/build_dockerfile.go deleted file mode 100644 index 856378322f..0000000000 --- a/internal/scaffold/ansible/build_dockerfile.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - "strings" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" - "github.com/operator-framework/operator-sdk/version" -) - -const BuildDockerfileFile = "Dockerfile" - -type BuildDockerfile struct { - input.Input - RolesDir string - ImageTag string - GeneratePlaybook bool -} - -// GetInput - gets the input -func (b *BuildDockerfile) GetInput() (input.Input, error) { - if b.Path == "" { - b.Path = filepath.Join(scaffold.BuildDir, BuildDockerfileFile) - } - b.TemplateBody = buildDockerfileAnsibleTmpl - b.Delims = AnsibleDelims - b.RolesDir = RolesDir - b.ImageTag = strings.TrimSuffix(version.Version, "+git") - return b.Input, nil -} - -const buildDockerfileAnsibleTmpl = `FROM quay.io/operator-framework/ansible-operator:[[.ImageTag]] - -COPY requirements.yml ${HOME}/requirements.yml -RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \ - && chmod -R ug+rwx ${HOME}/.ansible - -COPY watches.yaml ${HOME}/watches.yaml - -COPY [[.RolesDir]]/ ${HOME}/[[.RolesDir]]/ -[[- if .GeneratePlaybook ]] -COPY playbook.yml ${HOME}/playbook.yml -[[- end ]] -` diff --git a/internal/scaffold/ansible/constants.go b/internal/scaffold/ansible/constants.go deleted file mode 100644 index f21d85dbd1..0000000000 --- a/internal/scaffold/ansible/constants.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" -) - -const ( - filePathSep = string(filepath.Separator) - RolesDir = "roles" - MoleculeDir = "molecule" - MoleculeDefaultDir = MoleculeDir + filePathSep + "default" - MoleculeTestLocalDir = MoleculeDir + filePathSep + "test-local" - MoleculeClusterDir = MoleculeDir + filePathSep + "cluster" - MoleculeTemplatesDir = MoleculeDir + filePathSep + "templates" -) - -// AnsibleDelims is a slice of two strings representing the left and right delimiters for ansible templates. -// Arrays can't be constants but this should be a constant. -var AnsibleDelims = [2]string{"[[", "]]"} diff --git a/internal/scaffold/ansible/deploy_operator.go b/internal/scaffold/ansible/deploy_operator.go deleted file mode 100644 index b3f4bdffe0..0000000000 --- a/internal/scaffold/ansible/deploy_operator.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const DeployOperatorFile = "operator.yaml" - -type DeployOperator struct { - input.Input -} - -// GetInput - gets the input -func (d *DeployOperator) GetInput() (input.Input, error) { - if d.Path == "" { - d.Path = filepath.Join(scaffold.DeployDir, DeployOperatorFile) - } - d.TemplateBody = deployOperatorAnsibleTmpl - d.Delims = AnsibleDelims - - return d.Input, nil -} - -const deployOperatorAnsibleTmpl = `--- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: [[.ProjectName]] -spec: - replicas: 1 - selector: - matchLabels: - name: [[.ProjectName]] - template: - metadata: - labels: - name: [[.ProjectName]] - spec: - serviceAccountName: [[.ProjectName]] - containers: - - name: [[.ProjectName]] - # Replace this with the built image name - image: "REPLACE_IMAGE" - args: - - "--enable-leader-election" - - "--leader-election-id=[[.ProjectName]]" - imagePullPolicy: "Always" - volumeMounts: - - mountPath: /tmp/ansible-operator/runner - name: runner - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: "[[.ProjectName]]" - - name: ANSIBLE_GATHERING - value: explicit - livenessProbe: - httpGet: - path: /healthz - port: 6789 - initialDelaySeconds: 5 - periodSeconds: 3 - volumes: - - name: runner - emptyDir: {} -` diff --git a/internal/scaffold/ansible/input.go b/internal/scaffold/ansible/input.go deleted file mode 100644 index f2405a7d55..0000000000 --- a/internal/scaffold/ansible/input.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2019 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package ansible - -import ( - "github.com/operator-framework/operator-sdk/internal/scaffold/input" - "github.com/spf13/afero" -) - -// StaticInput is the input for scaffolding a static file with -// no parameters -type StaticInput struct { - input.Input -} - -// CustomRender return the template body unmodified -func (s *StaticInput) CustomRender() ([]byte, error) { - return []byte(s.TemplateBody), nil -} - -func (s StaticInput) SetFS(_ afero.Fs) {} diff --git a/internal/scaffold/ansible/molecule_cluster_converge.go b/internal/scaffold/ansible/molecule_cluster_converge.go deleted file mode 100644 index bb3816328d..0000000000 --- a/internal/scaffold/ansible/molecule_cluster_converge.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeClusterConvergeFile = "converge.yml" - -type MoleculeClusterConverge struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeClusterConverge) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeClusterDir, MoleculeClusterConvergeFile) - } - m.TemplateBody = moleculeClusterConvergeAnsibleTmpl - - return m.Input, nil -} - -const moleculeClusterConvergeAnsibleTmpl = `--- -- name: Converge - hosts: localhost - connection: local - gather_facts: no - collections: - - community.kubernetes - - tasks: - - name: Ensure operator image is set - fail: - msg: | - You must specify the OPERATOR_IMAGE environment variable in order to run the - 'cluster' scenario - when: not operator_image - - - name: Create the Operator Deployment - k8s: - namespace: '{{ namespace }}' - definition: "{{ lookup('template', '/'.join([template_dir, 'operator.yaml.j2'])) }}" - wait: yes - vars: - image: '{{ operator_image }}' - pull_policy: '{{ operator_pull_policy }}' -` diff --git a/internal/scaffold/ansible/molecule_cluster_create.go b/internal/scaffold/ansible/molecule_cluster_create.go deleted file mode 100644 index 765d61134c..0000000000 --- a/internal/scaffold/ansible/molecule_cluster_create.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeClusterCreateFile = "create.yml" - -type MoleculeClusterCreate struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeClusterCreate) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeClusterDir, MoleculeClusterCreateFile) - } - m.TemplateBody = moleculeClusterCreateAnsibleTmpl - - return m.Input, nil -} - -const moleculeClusterCreateAnsibleTmpl = `--- -- name: Create - hosts: localhost - connection: local - gather_facts: false - tasks: [] -` diff --git a/internal/scaffold/ansible/molecule_cluster_destroy.go b/internal/scaffold/ansible/molecule_cluster_destroy.go deleted file mode 100644 index d035533afa..0000000000 --- a/internal/scaffold/ansible/molecule_cluster_destroy.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeClusterDestroyFile = "destroy.yml" - -type MoleculeClusterDestroy struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (m *MoleculeClusterDestroy) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeClusterDir, MoleculeClusterDestroyFile) - } - m.TemplateBody = moleculeClusterDestroyAnsibleTmpl - m.Delims = AnsibleDelims - - return m.Input, nil -} - -const moleculeClusterDestroyAnsibleTmpl = `--- -- name: Destroy - hosts: localhost - connection: local - gather_facts: false - no_log: "{{ molecule_no_log }}" - collections: - - community.kubernetes - - tasks: - - name: Delete namespace - k8s: - api_version: v1 - kind: Namespace - name: '{{ namespace }}' - state: absent - wait: yes - - - name: Delete RBAC resources - k8s: - definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}" - namespace: '{{ namespace }}' - state: absent - wait: yes - with_items: - - role.yaml - - role_binding.yaml - - service_account.yaml - - - name: Delete Custom Resource Definition - k8s: - definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/[[.Resource.FullGroup]]_[[.Resource.Resource]]_crd.yaml'])) }}" - state: absent - wait: yes -` diff --git a/internal/scaffold/ansible/molecule_cluster_molecule.go b/internal/scaffold/ansible/molecule_cluster_molecule.go deleted file mode 100644 index 2cf5ecf744..0000000000 --- a/internal/scaffold/ansible/molecule_cluster_molecule.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeClusterMoleculeFile = "molecule.yml" - -type MoleculeClusterMolecule struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (m *MoleculeClusterMolecule) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeClusterDir, MoleculeClusterMoleculeFile) - } - m.TemplateBody = moleculeClusterMoleculeAnsibleTmpl - m.Delims = AnsibleDelims - - return m.Input, nil -} - -const moleculeClusterMoleculeAnsibleTmpl = `--- -dependency: - name: galaxy -driver: - name: delegated -lint: | - set -e - yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" . -platforms: -- name: cluster - groups: - - k8s -provisioner: - name: ansible - lint: | - set -e - ansible-lint - inventory: - group_vars: - all: - namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - host_vars: - localhost: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - deploy_dir: ${MOLECULE_PROJECT_DIRECTORY}/deploy - template_dir: ${MOLECULE_PROJECT_DIRECTORY}/molecule/templates - operator_image: ${OPERATOR_IMAGE:-""} - operator_pull_policy: ${OPERATOR_PULL_POLICY:-"Always"} - env: - K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"} -verifier: - name: ansible - lint: | - set -e - ansible-lint -` diff --git a/internal/scaffold/ansible/molecule_cluster_prepare.go b/internal/scaffold/ansible/molecule_cluster_prepare.go deleted file mode 100644 index 4b96e9fbb2..0000000000 --- a/internal/scaffold/ansible/molecule_cluster_prepare.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeClusterPrepareFile = "prepare.yml" - -type MoleculeClusterPrepare struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (m *MoleculeClusterPrepare) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeClusterDir, MoleculeClusterPrepareFile) - } - m.TemplateBody = moleculeClusterPrepareAnsibleTmpl - m.Delims = AnsibleDelims - - return m.Input, nil -} - -const moleculeClusterPrepareAnsibleTmpl = `--- -- name: Prepare - hosts: localhost - connection: local - gather_facts: false - no_log: "{{ molecule_no_log }}" - collections: - - community.kubernetes - - vars: - deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy" - - tasks: - - name: Create Custom Resource Definition - k8s: - definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/[[.Resource.FullGroup]]_[[.Resource.Resource]]_crd.yaml'])) }}" - - - name: Create namespace - k8s: - api_version: v1 - kind: Namespace - name: '{{ namespace }}' - - - name: Create RBAC resources - k8s: - definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}" - namespace: '{{ namespace }}' - with_items: - - role.yaml - - role_binding.yaml - - service_account.yaml -` diff --git a/internal/scaffold/ansible/molecule_cluster_verify.go b/internal/scaffold/ansible/molecule_cluster_verify.go deleted file mode 100644 index a7ddce4f0e..0000000000 --- a/internal/scaffold/ansible/molecule_cluster_verify.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeClusterVerifyFile = "verify.yml" - -type MoleculeClusterVerify struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (m *MoleculeClusterVerify) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeClusterDir, MoleculeClusterVerifyFile) - } - m.TemplateBody = moleculeClusterVerifyAnsibleTmpl - m.Delims = AnsibleDelims - - return m.Input, nil -} - -const moleculeClusterVerifyAnsibleTmpl = `--- -# This is an example playbook to execute Ansible tests. -- name: Verify - hosts: localhost - connection: local - gather_facts: no - collections: - - community.kubernetes - - vars: - custom_resource: "{{ lookup('template', '/'.join([deploy_dir, 'crds/[[.Resource.FullGroup]]_[[.Resource.Version]]_[[.Resource.LowerKind]]_cr.yaml'])) | from_yaml }}" - - tasks: - - name: Create the [[.Resource.FullGroup]]/[[.Resource.Version]].[[.Resource.Kind]] and wait for reconciliation to complete - k8s: - state: present - namespace: '{{ namespace }}' - definition: '{{ custom_resource }}' - wait: yes - wait_timeout: 300 - wait_condition: - type: Running - reason: Successful - status: "True" - - - name: Get Pods - k8s_info: - api_version: v1 - kind: Pod - namespace: '{{ namespace }}' - register: pods - - - name: Example assertion - assert: - that: (pods | length) > 0 -` diff --git a/internal/scaffold/ansible/molecule_default_converge.go b/internal/scaffold/ansible/molecule_default_converge.go deleted file mode 100644 index f55142e8b9..0000000000 --- a/internal/scaffold/ansible/molecule_default_converge.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeDefaultConvergeFile = "converge.yml" - -type MoleculeDefaultConverge struct { - input.Input - GeneratePlaybook bool - Resource scaffold.Resource -} - -// GetInput - gets the input -func (m *MoleculeDefaultConverge) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeDefaultDir, MoleculeDefaultConvergeFile) - } - m.TemplateBody = moleculeDefaultConvergeAnsibleTmpl - m.Delims = AnsibleDelims - return m.Input, nil -} - -const moleculeDefaultConvergeAnsibleTmpl = `--- -[[- if .GeneratePlaybook ]] -- import_playbook: '{{ playbook_dir }}/../../playbook.yml' -[[- end ]] - - [[- if not .GeneratePlaybook ]] -- name: Converge - hosts: localhost - connection: local - roles: - - [[.Resource.LowerKind]] - [[- end ]] -` diff --git a/internal/scaffold/ansible/molecule_default_molecule.go b/internal/scaffold/ansible/molecule_default_molecule.go deleted file mode 100644 index 378708fd43..0000000000 --- a/internal/scaffold/ansible/molecule_default_molecule.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeDefaultMoleculeFile = "molecule.yml" - -type MoleculeDefaultMolecule struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeDefaultMolecule) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeDefaultDir, MoleculeDefaultMoleculeFile) - } - m.TemplateBody = moleculeDefaultMoleculeAnsibleTmpl - - return m.Input, nil -} - -const moleculeDefaultMoleculeAnsibleTmpl = `--- -dependency: - name: galaxy -driver: - name: docker -lint: | - set -e - yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" . -platforms: -- name: kind-default - groups: - - k8s - image: bsycorp/kind:latest-${KUBE_VERSION:-1.17} - privileged: True - override_command: no - exposed_ports: - - 8443/tcp - - 10080/tcp - published_ports: - - 0.0.0.0:${TEST_CLUSTER_PORT:-9443}:8443/tcp - pre_build_image: yes -provisioner: - name: ansible - log: True - lint: | - set -e - ansible-lint - inventory: - group_vars: - all: - namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - host_vars: - localhost: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - env: - K8S_AUTH_KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles - KIND_PORT: '${TEST_CLUSTER_PORT:-9443}' -verifier: - name: ansible - lint: | - set -e - ansible-lint -` diff --git a/internal/scaffold/ansible/molecule_default_prepare.go b/internal/scaffold/ansible/molecule_default_prepare.go deleted file mode 100644 index 675919ac24..0000000000 --- a/internal/scaffold/ansible/molecule_default_prepare.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeDefaultPrepareFile = "prepare.yml" - -type MoleculeDefaultPrepare struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeDefaultPrepare) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeDefaultDir, MoleculeDefaultPrepareFile) - } - m.TemplateBody = moleculeDefaultPrepareAnsibleTmpl - - return m.Input, nil -} - -const moleculeDefaultPrepareAnsibleTmpl = `--- -- name: Prepare - hosts: k8s - gather_facts: no - tasks: - - name: Fetch the kubeconfig - fetch: - dest: '{{ kubeconfig_file }}' - flat: yes - src: /root/.kube/config - - - name: Change the kubeconfig port to the proper value - replace: - regexp: '8443' - replace: "{{ lookup('env', 'KIND_PORT') }}" - path: '{{ kubeconfig_file }}' - delegate_to: localhost - - - name: Wait for the Kubernetes API to become available (this could take a minute) - uri: - url: "http://localhost:10080/kubernetes-ready" - status_code: 200 - validate_certs: no - register: result - until: (result.status|default(-1)) == 200 - retries: 60 - delay: 5 -` diff --git a/internal/scaffold/ansible/molecule_default_verify.go b/internal/scaffold/ansible/molecule_default_verify.go deleted file mode 100644 index 564a590bd4..0000000000 --- a/internal/scaffold/ansible/molecule_default_verify.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeDefaultVerifyFile = "verify.yml" - -type MoleculeDefaultVerify struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeDefaultVerify) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeDefaultDir, MoleculeDefaultVerifyFile) - } - m.TemplateBody = moleculeDefaultVerifyAnsibleTmpl - - return m.Input, nil -} - -const moleculeDefaultVerifyAnsibleTmpl = `--- -- name: Verify - hosts: localhost - connection: local - tasks: - - name: Get all pods in {{ namespace }} - k8s_info: - api_version: v1 - kind: Pod - namespace: '{{ namespace }}' - register: pods - - - name: Output pods - debug: var=pods - - - name: Example assertion - assert: - that: true -` diff --git a/internal/scaffold/ansible/molecule_templates_operator.go b/internal/scaffold/ansible/molecule_templates_operator.go deleted file mode 100644 index 56249dd3e8..0000000000 --- a/internal/scaffold/ansible/molecule_templates_operator.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeTemplatesOperatorFile = "operator.yaml.j2" - -type MoleculeTemplatesOperator struct { - input.Input -} - -// GetInput - gets the input -func (m *MoleculeTemplatesOperator) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeTemplatesDir, MoleculeTemplatesOperatorFile) - } - m.TemplateBody = moleculeTemplatesOperatorAnsibleTmpl - m.Delims = AnsibleDelims - - return m.Input, nil -} - -const moleculeTemplatesOperatorAnsibleTmpl = `--- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: [[.ProjectName]] -spec: - replicas: 1 - selector: - matchLabels: - name: [[.ProjectName]] - template: - metadata: - labels: - name: [[.ProjectName]] - spec: - serviceAccountName: [[.ProjectName]] - containers: - - name: [[.ProjectName]] - # Replace this with the built image name - image: "{{ image }}" - imagePullPolicy: "{{ pull_policy }}" - volumeMounts: - - mountPath: /tmp/ansible-operator/runner - name: runner - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: "[[.ProjectName]]" - - name: ANSIBLE_GATHERING - value: explicit - livenessProbe: - httpGet: - path: /healthz - port: 6789 - initialDelaySeconds: 5 - periodSeconds: 3 - - volumes: - - name: runner - emptyDir: {} -` diff --git a/internal/scaffold/ansible/molecule_test_local_converge.go b/internal/scaffold/ansible/molecule_test_local_converge.go deleted file mode 100644 index b5e4cb2136..0000000000 --- a/internal/scaffold/ansible/molecule_test_local_converge.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeTestLocalConvergeFile = "converge.yml" - -type MoleculeTestLocalConverge struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (m *MoleculeTestLocalConverge) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeTestLocalDir, MoleculeTestLocalConvergeFile) - } - m.TemplateBody = moleculeTestLocalConvergeAnsibleTmpl - m.Delims = AnsibleDelims - - return m.Input, nil -} - -const moleculeTestLocalConvergeAnsibleTmpl = `--- -- name: Build Operator in Kubernetes docker container - hosts: k8s - collections: - - community.kubernetes - - vars: - image: [[.Resource.FullGroup]]/[[.ProjectName]]:testing - - tasks: - # using command so we don't need to install any dependencies - - name: Get existing image hash - command: docker images -q {{ image }} - register: prev_hash_raw - changed_when: false - - - name: Build Operator Image - command: docker build -f /build/build/Dockerfile -t {{ image }} /build - register: build_cmd - changed_when: not hash or (hash and hash not in cmd_out) - vars: - hash: '{{ prev_hash_raw.stdout }}' - cmd_out: '{{ "".join(build_cmd.stdout_lines[-2:]) }}' - -- name: Converge - hosts: localhost - connection: local - collections: - - community.kubernetes - - vars: - image: [[.Resource.FullGroup]]/[[.ProjectName]]:testing - operator_template: "{{ '/'.join([template_dir, 'operator.yaml.j2']) }}" - - tasks: - - name: Create the Operator Deployment - k8s: - namespace: '{{ namespace }}' - definition: "{{ lookup('template', operator_template) }}" - wait: yes - vars: - pull_policy: Never -` diff --git a/internal/scaffold/ansible/molecule_test_local_molecule.go b/internal/scaffold/ansible/molecule_test_local_molecule.go deleted file mode 100644 index e99527f964..0000000000 --- a/internal/scaffold/ansible/molecule_test_local_molecule.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeTestLocalMoleculeFile = "molecule.yml" - -type MoleculeTestLocalMolecule struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeTestLocalMolecule) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeTestLocalDir, MoleculeTestLocalMoleculeFile) - } - m.TemplateBody = moleculeTestLocalMoleculeAnsibleTmpl - - return m.Input, nil -} - -const moleculeTestLocalMoleculeAnsibleTmpl = `--- -dependency: - name: galaxy -driver: - name: docker -lint: | - set -e - yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" . -platforms: - - name: kind-test-local - groups: - - k8s - image: bsycorp/kind:latest-${KUBE_VERSION:-1.17} - privileged: true - override_command: false - exposed_ports: - - 8443/tcp - - 10080/tcp - published_ports: - - 0.0.0.0:${TEST_CLUSTER_PORT:-10443}:8443/tcp - pre_build_image: true - volumes: - - ${MOLECULE_PROJECT_DIRECTORY}:/build:Z -provisioner: - name: ansible - log: true - lint: - name: ansible-lint - inventory: - group_vars: - all: - namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - host_vars: - localhost: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - template_dir: ${MOLECULE_PROJECT_DIRECTORY}/molecule/templates - deploy_dir: ${MOLECULE_PROJECT_DIRECTORY}/deploy - env: - K8S_AUTH_KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles - KIND_PORT: '${TEST_CLUSTER_PORT:-10443}' -verifier: - name: ansible - lint: - name: ansible-lint -` diff --git a/internal/scaffold/ansible/molecule_test_local_prepare.go b/internal/scaffold/ansible/molecule_test_local_prepare.go deleted file mode 100644 index 68bb08f2c4..0000000000 --- a/internal/scaffold/ansible/molecule_test_local_prepare.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeTestLocalPrepareFile = "prepare.yml" - -type MoleculeTestLocalPrepare struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeTestLocalPrepare) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeTestLocalDir, MoleculeTestLocalPrepareFile) - } - m.TemplateBody = moleculeTestLocalPrepareAnsibleTmpl - - return m.Input, nil -} - -const moleculeTestLocalPrepareAnsibleTmpl = `--- -- import_playbook: ../default/prepare.yml -- import_playbook: ../cluster/prepare.yml -` diff --git a/internal/scaffold/ansible/molecule_test_local_verify.go b/internal/scaffold/ansible/molecule_test_local_verify.go deleted file mode 100644 index f730cec558..0000000000 --- a/internal/scaffold/ansible/molecule_test_local_verify.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const MoleculeTestLocalVerifyFile = "verify.yml" - -type MoleculeTestLocalVerify struct { - StaticInput -} - -// GetInput - gets the input -func (m *MoleculeTestLocalVerify) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join(MoleculeTestLocalDir, MoleculeTestLocalVerifyFile) - } - m.TemplateBody = moleculeTestLocalVerifyAnsibleTmpl - - return m.Input, nil -} - -const moleculeTestLocalVerifyAnsibleTmpl = `--- -- import_playbook: ../cluster/verify.yml -` diff --git a/internal/scaffold/ansible/playbook.go b/internal/scaffold/ansible/playbook.go deleted file mode 100644 index 5f4299e753..0000000000 --- a/internal/scaffold/ansible/playbook.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const PlaybookYamlFile = "playbook.yml" - -// Playbook - the playbook tmpl wrapper -type Playbook struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (p *Playbook) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = PlaybookYamlFile - } - p.TemplateBody = playbookTmpl - p.Delims = AnsibleDelims - return p.Input, nil -} - -const playbookTmpl = `--- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - - operator_sdk.util - - tasks: - - import_role: - name: "[[.Resource.LowerKind]]" -` diff --git a/internal/scaffold/ansible/requirements.go b/internal/scaffold/ansible/requirements.go deleted file mode 100644 index 25cd61eff5..0000000000 --- a/internal/scaffold/ansible/requirements.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -// RequirementsYml - A requirements file for Ansible collection dependencies -type RequirementsYml struct { - StaticInput -} - -// GetInput - gets the input -func (r *RequirementsYml) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = "requirements.yml" - } - r.TemplateBody = requirementsYmlTmpl - return r.Input, nil -} - -const requirementsYmlTmpl = `--- -collections: - - name: community.kubernetes - version: "<1.0.0" - - operator_sdk.util -` diff --git a/internal/scaffold/ansible/roles_defaults_main.go b/internal/scaffold/ansible/roles_defaults_main.go deleted file mode 100644 index 4a5a03ade3..0000000000 --- a/internal/scaffold/ansible/roles_defaults_main.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesDefaultsMainFile = "defaults" + filePathSep + "main.yml" - -type RolesDefaultsMain struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesDefaultsMain) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesDefaultsMainFile) - } - r.TemplateBody = rolesDefaultsMainAnsibleTmpl - r.Delims = AnsibleDelims - - return r.Input, nil -} - -const rolesDefaultsMainAnsibleTmpl = `--- -# defaults file for [[.Resource.LowerKind]] -` diff --git a/internal/scaffold/ansible/roles_files.go b/internal/scaffold/ansible/roles_files.go deleted file mode 100644 index 952830b76e..0000000000 --- a/internal/scaffold/ansible/roles_files.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesFilesDir = "files" + filePathSep + ".placeholder" - -type RolesFiles struct { - StaticInput - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesFiles) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesFilesDir) - } - r.TemplateBody = rolesFilesDirPlaceholder - return r.Input, nil -} - -const rolesFilesDirPlaceholder = `` diff --git a/internal/scaffold/ansible/roles_handlers_main.go b/internal/scaffold/ansible/roles_handlers_main.go deleted file mode 100644 index 7996f9144b..0000000000 --- a/internal/scaffold/ansible/roles_handlers_main.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesHandlersMainFile = "handlers" + filePathSep + "main.yml" - -type RolesHandlersMain struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesHandlersMain) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesHandlersMainFile) - } - r.TemplateBody = rolesHandlersMainAnsibleTmpl - r.Delims = AnsibleDelims - - return r.Input, nil -} - -const rolesHandlersMainAnsibleTmpl = `--- -# handlers file for [[.Resource.LowerKind]] -` diff --git a/internal/scaffold/ansible/roles_meta_main.go b/internal/scaffold/ansible/roles_meta_main.go deleted file mode 100644 index d0086e5dfc..0000000000 --- a/internal/scaffold/ansible/roles_meta_main.go +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesMetaMainFile = "meta" + filePathSep + "main.yml" - -type RolesMetaMain struct { - StaticInput - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesMetaMain) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesMetaMainFile) - } - r.TemplateBody = rolesMetaMainAnsibleTmpl - - return r.Input, nil -} - -const rolesMetaMainAnsibleTmpl = `--- -galaxy_info: - author: your name - description: your description - company: your company (optional) - - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY - license: license (GPLv2, CC-BY, etc) - - min_ansible_version: 2.9 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. - # To view available platforms and versions (or releases), visit: - # https://galaxy.ansible.com/api/v1/platforms/ - # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. - -dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. -collections: -- operator_sdk.util -- community.kubernetes -` diff --git a/internal/scaffold/ansible/roles_readme.go b/internal/scaffold/ansible/roles_readme.go deleted file mode 100644 index d2784ea291..0000000000 --- a/internal/scaffold/ansible/roles_readme.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesReadmeFile = "README.md" - -type RolesReadme struct { - StaticInput - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesReadme) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesReadmeFile) - } - r.TemplateBody = rolesReadmeAnsibleTmpl - - return r.Input, nil -} - -const rolesReadmeAnsibleTmpl = `Role Name -========= - -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, -if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. - -Role Variables --------------- - -A description of the settable variables for this role should go here, including any variables that are in -defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables -that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well - -Dependencies ------------- - -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set -for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for -users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } - -License -------- - -BSD - -Author Information ------------------- - -An optional section for the role authors to include contact information, or a website (HTML is not allowed). -` diff --git a/internal/scaffold/ansible/roles_tasks_main.go b/internal/scaffold/ansible/roles_tasks_main.go deleted file mode 100644 index d125ed19e8..0000000000 --- a/internal/scaffold/ansible/roles_tasks_main.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesTasksMainFile = "tasks" + filePathSep + "main.yml" - -type RolesTasksMain struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesTasksMain) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesTasksMainFile) - } - r.TemplateBody = rolesTasksMainAnsibleTmpl - r.Delims = AnsibleDelims - - return r.Input, nil -} - -const rolesTasksMainAnsibleTmpl = `--- -# tasks file for [[.Resource.LowerKind]] -` diff --git a/internal/scaffold/ansible/roles_templates.go b/internal/scaffold/ansible/roles_templates.go deleted file mode 100644 index 24cad2f91b..0000000000 --- a/internal/scaffold/ansible/roles_templates.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesTemplatesDir = "templates" + filePathSep + ".placeholder" - -type RolesTemplates struct { - StaticInput - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesTemplates) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesTemplatesDir) - } - r.TemplateBody = rolesTemplatesDirPlaceholder - return r.Input, nil -} - -const rolesTemplatesDirPlaceholder = `` diff --git a/internal/scaffold/ansible/roles_vars_main.go b/internal/scaffold/ansible/roles_vars_main.go deleted file mode 100644 index 9fc057233e..0000000000 --- a/internal/scaffold/ansible/roles_vars_main.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" -) - -const RolesVarsMainFile = "vars" + filePathSep + "main.yml" - -type RolesVarsMain struct { - input.Input - Resource scaffold.Resource -} - -// GetInput - gets the input -func (r *RolesVarsMain) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join(RolesDir, r.Resource.LowerKind, RolesVarsMainFile) - } - r.TemplateBody = rolesVarsMainAnsibleTmpl - r.Delims = AnsibleDelims - - return r.Input, nil -} - -const rolesVarsMainAnsibleTmpl = `--- -# vars file for [[.Resource.LowerKind]] -` diff --git a/internal/scaffold/ansible/testdata/invalid/emptywatchfile/watches.yaml b/internal/scaffold/ansible/testdata/invalid/emptywatchfile/watches.yaml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/internal/scaffold/ansible/testdata/invalid/invalid_watch/watches.yaml b/internal/scaffold/ansible/testdata/invalid/invalid_watch/watches.yaml deleted file mode 100644 index 9e121cc32d..0000000000 --- a/internal/scaffold/ansible/testdata/invalid/invalid_watch/watches.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - version: v1alpha1 - kind: App - role: app diff --git a/internal/scaffold/ansible/testdata/valid1/validWatches.yaml b/internal/scaffold/ansible/testdata/valid1/validWatches.yaml deleted file mode 100644 index 45e96eb6d6..0000000000 --- a/internal/scaffold/ansible/testdata/valid1/validWatches.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- version: v1alpha1 - group: mykind.example.com - kind: MyKind - role: mykind - -- version: v1alpha1 - group: app.example.com - kind: App - role: app diff --git a/internal/scaffold/ansible/testdata/valid2/validWatches.yaml b/internal/scaffold/ansible/testdata/valid2/validWatches.yaml deleted file mode 100644 index 27746bdecd..0000000000 --- a/internal/scaffold/ansible/testdata/valid2/validWatches.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- version: v1alpha1 - group: mykind.example.com - kind: MyKind - playbook: playbook.yml - -- version: v1alpha1 - group: app.example.com - kind: App - role: app diff --git a/internal/scaffold/ansible/travis.go b/internal/scaffold/ansible/travis.go deleted file mode 100644 index 37a3ed9026..0000000000 --- a/internal/scaffold/ansible/travis.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import "github.com/operator-framework/operator-sdk/internal/scaffold/input" - -const TravisFile = ".travis.yml" - -type Travis struct { - StaticInput -} - -// GetInput - gets the input -func (t *Travis) GetInput() (input.Input, error) { - if t.Path == "" { - t.Path = TravisFile - } - t.TemplateBody = travisAnsibleTmpl - - return t.Input, nil -} - -const travisAnsibleTmpl = `--- -services: docker -language: python -install: - - pip3 install docker molecule ansible-lint yamllint flake8 openshift jmespath -script: - - molecule test -s test-local -` diff --git a/internal/scaffold/ansible/watches.go b/internal/scaffold/ansible/watches.go deleted file mode 100644 index 19e0a9f57a..0000000000 --- a/internal/scaffold/ansible/watches.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "bytes" - "fmt" - "html/template" - "io/ioutil" - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/scaffold/input" - "github.com/operator-framework/operator-sdk/internal/util/fileutil" - "github.com/operator-framework/operator-sdk/pkg/ansible/watches" - - "gopkg.in/yaml.v2" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -const WatchesFile = "watches.yaml" - -type Watches struct { - input.Input - GeneratePlaybook bool - RolesDir string - Resource scaffold.Resource -} - -// GetInput - gets the input -func (w *Watches) GetInput() (input.Input, error) { - if w.Path == "" { - w.Path = WatchesFile - } - w.TemplateBody = watchesAnsibleTmpl - w.Delims = AnsibleDelims - w.RolesDir = RolesDir - return w.Input, nil -} - -// TODO Extract adding watch resource into its own func. -// UpdateAnsibleWatchForResource checks for duplicate GVK, and appends to existing Watch.yaml file. -func UpdateAnsibleWatchForResource(r *scaffold.Resource, absProjectPath string) error { - watchFilePath := filepath.Join(absProjectPath, WatchesFile) - watchYAML, err := ioutil.ReadFile(watchFilePath) - if err != nil { - return fmt.Errorf("failed to read watch manifest %v: %v", watchFilePath, err) - } - var buf bytes.Buffer - watchList := []watches.Watch{} - err = yaml.Unmarshal(watchYAML, &watchList) - if err != nil { - return fmt.Errorf("failed to unmarshal watch config %v ", err) - } - - gvk := schema.GroupVersionKind{ - Version: r.Version, - Group: r.FullGroup, - Kind: r.Kind, - } - - for _, watch := range watchList { - if watch.GroupVersionKind == gvk { - // dupe detected - return fmt.Errorf("duplicate GVK: %v", watch.GroupVersionKind.String()) - } - } - // Create new watch - watches := Watches{ - GeneratePlaybook: false, - Resource: scaffold.Resource{ - Kind: r.Kind, - FullGroup: r.FullGroup, - Version: r.Version, - LowerKind: r.LowerKind, - }, - } - tmpl, err := template.New("watches").Delims("[[", "]]").Parse(updateWatchesAnsibleTmpl) - if err != nil { - panic(err) - } - err = tmpl.Execute(&buf, watches) - if err != nil { - panic(err) - } - // Append new Watch content existing watch.yaml - watchYAML = append(watchYAML, buf.Bytes()...) - if err := ioutil.WriteFile(watchFilePath, watchYAML, fileutil.DefaultFileMode); err != nil { - return fmt.Errorf("failed to update %v: %v", watchFilePath, err) - } - return nil -} - -// TODO -// Currently we are using string template for initial creation for watches.yaml and STRUCT/YAML for updating -// new resources in watches.YAML. -// Consolidate to use STRUCT/YAML Marshalling for creating and updating resources in watches.yaml -const watchesAnsibleTmpl = `--- -- version: [[.Resource.Version]] - group: [[.Resource.FullGroup]] - kind: [[.Resource.Kind]] - [[- if .GeneratePlaybook ]] - playbook: playbook.yml - [[- else ]] - role: [[.Resource.LowerKind]] - [[- end ]] -` -const updateWatchesAnsibleTmpl = ` -- version: [[.Resource.Version]] - group: [[.Resource.FullGroup]] - kind: [[.Resource.Kind]] - [[- if .GeneratePlaybook ]] - playbook: playbook.yml - [[- else ]] - role: [[.Resource.LowerKind]] - [[- end ]] -` diff --git a/internal/scaffold/ansible/watches_test.go b/internal/scaffold/ansible/watches_test.go deleted file mode 100644 index 64a792236d..0000000000 --- a/internal/scaffold/ansible/watches_test.go +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ansible - -import ( - "fmt" - "io/ioutil" - "log" - "os" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/operator-framework/operator-sdk/internal/scaffold" - "github.com/operator-framework/operator-sdk/internal/util/fileutil" -) - -func TestUpdateAnsibleWatchForResource(t *testing.T) { - - watchFilePath1 := "./testdata/valid1/watches.yaml" - if err := ioutil.WriteFile(watchFilePath1, []byte(sampleWatch1), fileutil.DefaultFileMode); err != nil { - fmt.Printf("failed to initiate sample watch %v", err) - } - defer remove(watchFilePath1) - watchFilePath2 := "./testdata/valid2/watches.yaml" - if err := ioutil.WriteFile(watchFilePath2, []byte(sampleWatch2), fileutil.DefaultFileMode); err != nil { - fmt.Printf("failed to initiate sample watch %v", err) - } - defer remove(watchFilePath2) - - testCases := []struct { - name string - r *scaffold.Resource - absProjectPath string - expError string - expWatchesFile string - }{ - - { - //Valid watch - name: "Basic Valid Watch", - r: &scaffold.Resource{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - LowerKind: "app", - FullGroup: "app.example.com", - Version: "v1alpha1", - }, - absProjectPath: "./testdata/valid1", - expError: "", - expWatchesFile: "./testdata/valid1/validWatches.yaml", - }, - { - //Valid watch with playbbok - name: "Valid Watch With Playbook", - r: &scaffold.Resource{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - LowerKind: "app", - FullGroup: "app.example.com", - Version: "v1alpha1", - }, - absProjectPath: "./testdata/valid2", - expError: "", - expWatchesFile: "./testdata/valid2/validWatches.yaml", - }, - { - //Invalid Watch - name: "Duplicate GVK", - r: &scaffold.Resource{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - LowerKind: "app", - FullGroup: "app.example.com", - Version: "v1alpha1", - }, - absProjectPath: "./testdata/valid1", - expError: "duplicate GVK: app.example.com/v1alpha1, Kind=App", - }, - { - //Invalid Watch - name: "Empty Directory", - r: &scaffold.Resource{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - LowerKind: "app", - FullGroup: "app.example.com", - Version: "v1alpha1", - }, - absProjectPath: "./testdata", - expError: "failed to read watch manifest testdata/watches.yaml: " + - "open testdata/watches.yaml: no such file or directory", - }, - { - //Invalid Watch - name: "Invalid Watch file", - r: &scaffold.Resource{ - APIVersion: "app.example.com/v1alpha1", - Kind: "App", - LowerKind: "app", - FullGroup: "app.example.com", - Version: "v1alpha1", - }, - absProjectPath: "./testdata/invalid/invalid_watch", - expError: "failed to unmarshal watch config yaml: unmarshal errors:" + "\n" + - " line 2: cannot unmarshal !!map into []watches.Watch ", - }, - } - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - var result string - if err := UpdateAnsibleWatchForResource(tc.r, tc.absProjectPath); err != nil { - result = err.Error() - } - assert.Equal(t, tc.expError, result) - // Check watchfile content - if tc.expError == "" { - actualFilePath := tc.absProjectPath + "/watches.yaml" - expectedWatchFile, err := ioutil.ReadFile(tc.expWatchesFile) - if err != nil { - fmt.Printf("failed to read expectedWatchFile %v: %v", tc.expWatchesFile, err) - } - actualWatchFile, err := ioutil.ReadFile(actualFilePath) - if err != nil { - fmt.Printf("failed to read actualWatchFile %v: %v", actualFilePath, err) - } - assert.Equal(t, expectedWatchFile, actualWatchFile) - } - }) - } -} - -// remove removes path from disk. Used in defer statements. -func remove(path string) { - if err := os.RemoveAll(path); err != nil { - log.Fatal(err) - } -} - -const sampleWatch1 = `--- -- version: v1alpha1 - group: mykind.example.com - kind: MyKind - role: mykind -` - -const sampleWatch2 = `--- -- version: v1alpha1 - group: mykind.example.com - kind: MyKind - playbook: playbook.yml -` diff --git a/internal/util/projutil/project_util.go b/internal/util/projutil/project_util.go index ce5409d571..839a1fb901 100644 --- a/internal/util/projutil/project_util.go +++ b/internal/util/projutil/project_util.go @@ -39,9 +39,6 @@ const ( mainFile = "main.go" managerMainFile = "cmd" + fsep + "manager" + fsep + mainFile buildDockerfile = "build" + fsep + "Dockerfile" - rolesDir = "roles" - requirementsFile = "requirements.yml" - moleculeDir = "molecule" goModFile = "go.mod" defaultPermission = 0644 @@ -238,27 +235,16 @@ func IsOperatorGo() bool { } // IsOperatorAnsible returns true when the layout field in PROJECT file has the Ansible prefix key. -// NOTE: For the legacy, returns true when the project contains the roles and the molecule directory. func IsOperatorAnsible() bool { - // If the project is in the new layout, check the config file's plugin type. - if kbutil.HasProjectFile() { - cfg, err := kbutil.ReadConfig() - if err != nil { - log.Fatalf("Error reading config: %v", err) - } - return PluginKeyToOperatorType(cfg.Layout) == OperatorTypeAnsible - } - // todo(camilamacedo86): remove when the legacy layout is no longer supported - stat, err := os.Stat(rolesDir) - if (err == nil && stat.IsDir()) || os.IsExist(err) { - return true + if !kbutil.HasProjectFile() { + return false } - stat, err = os.Stat(moleculeDir) - if (err == nil && stat.IsDir()) || os.IsExist(err) { - return true + cfg, err := kbutil.ReadConfig() + if err != nil { + log.Fatalf("Error reading config: %v", err) } - _, err = os.Stat(requirementsFile) - return err == nil || os.IsExist(err) + return PluginKeyToOperatorType(cfg.Layout) == OperatorTypeAnsible + } // IsOperatorHelm returns true when the layout field in PROJECT file has the Helm prefix key. diff --git a/website/content/en/docs/cli/operator-sdk.md b/website/content/en/docs/cli/operator-sdk.md index cceac4a438..493ffabcaf 100644 --- a/website/content/en/docs/cli/operator-sdk.md +++ b/website/content/en/docs/cli/operator-sdk.md @@ -73,7 +73,6 @@ operator-sdk [flags] * [operator-sdk create](../operator-sdk_create) - Scaffold a Kubernetes API or webhook * [operator-sdk generate](../operator-sdk_generate) - Invokes a specific generator * [operator-sdk init](../operator-sdk_init) - Initialize a new project -* [operator-sdk new](../operator-sdk_new) - Creates a new operator application * [operator-sdk olm](../operator-sdk_olm) - Manage the Operator Lifecycle Manager installation in your cluster * [operator-sdk run](../operator-sdk_run) - Run an Operator in a variety of environments * [operator-sdk scorecard](../operator-sdk_scorecard) - Runs scorecard diff --git a/website/content/en/docs/cli/operator-sdk_new.md b/website/content/en/docs/cli/operator-sdk_new.md deleted file mode 100644 index 6a0bc0e27b..0000000000 --- a/website/content/en/docs/cli/operator-sdk_new.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: "operator-sdk new" ---- -## operator-sdk new - -Creates a new operator application - -### Synopsis - -The operator-sdk new command creates a new operator application and -generates a default directory layout based on the input <project-name>. - -<project-name> is the project name of the new operator. (e.g app-operator) - - -``` -operator-sdk new [flags] -``` - -### Examples - -``` - # Create a new project directory - $ mkdir $HOME/projects/example.com/ - $ cd $HOME/projects/example.com/ - - # Ansible project - $ operator-sdk new app-operator --type=ansible \ - --api-version=app.example.com/v1alpha1 \ - --kind=AppService - -``` - -### Options - -``` - --api-version string Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1) - --crd-version string CRD version to generate (default "v1") - --generate-playbook Generate a playbook skeleton. (Only used for --type ansible) - -h, --help help for new - --kind string Kubernetes resource Kind name. (e.g AppService) - --skip-generation Skip generation of deepcopy and OpenAPI code and OpenAPI CRD specs -``` - -### Options inherited from parent commands - -``` - --verbose Enable verbose logging -``` - -### SEE ALSO - -* [operator-sdk](../operator-sdk) - Development kit for building Kubernetes extensions and tools. -