From 0250ea53700dc5335152ba2314916619fe8f020b Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Tue, 15 Dec 2020 16:33:26 +0000 Subject: [PATCH 1/3] e2e-tests: auto generate advanced molecule ansible tests --- .gitignore | 1 + Makefile | 1 + .../internal/ansible/advanced_molecule.go | 502 ++++++++++++++++++ .../{molecule.go => memcached_molecule.go} | 0 .../internal/ansible/testdata}/ansible.cfg | 0 .../testdata}/fixture_collection/galaxy.yml | 0 .../roles/dummy/tasks/main.yml | 0 .../testdata}/inventory/group_vars/test.yml | 0 .../ansible/testdata}/inventory/hosts | 0 .../ansible/testdata}/plugins/filter/test.py | 0 .../internal/ansible/testdata}/secret.yml | 0 .../ansible/testdata}/tasks/argstest_test.yml | 0 .../ansible/testdata}/tasks/casetest_test.yml | 0 .../testdata}/tasks/collectiontest_test.yml | 0 .../testdata}/tasks/inventorytest_test.yml | 0 .../tasks/reconciliationtest_test.yml | 0 .../testdata}/tasks/secretstest_test.yml | 0 .../testdata}/tasks/selectortest_test.yml | 0 .../testdata}/tasks/subresourcestest_test.yml | 0 .../internal/ansible/testdata}/watches.yaml | 0 hack/generate/samples/molecule/generate.go | 13 +- hack/tests/e2e-ansible-molecule.sh | 15 +- internal/ansible/OWNERS | 6 - test/ansible/.gitignore | 14 - test/ansible/Dockerfile | 23 - test/ansible/Makefile | 92 ---- test/ansible/PROJECT | 24 - .../crd/bases/test.example.com_argstests.yaml | 44 -- .../crd/bases/test.example.com_casetests.yaml | 44 -- .../test.example.com_collectiontests.yaml | 44 -- .../test.example.com_inventorytests.yaml | 44 -- .../test.example.com_reconciliationtests.yaml | 44 -- .../bases/test.example.com_selectortests.yaml | 44 -- .../test.example.com_subresourcestests.yaml | 44 -- test/ansible/config/crd/kustomization.yaml | 12 - .../ansible/config/default/kustomization.yaml | 26 - .../default/manager_auth_proxy_patch.yaml | 27 - .../ansible/config/manager/kustomization.yaml | 2 - test/ansible/config/manager/manager.yaml | 40 -- .../config/prometheus/kustomization.yaml | 2 - test/ansible/config/prometheus/monitor.yaml | 16 - .../config/rbac/argstest_editor_role.yaml | 24 - .../config/rbac/argstest_viewer_role.yaml | 20 - .../rbac/auth_proxy_client_clusterrole.yaml | 7 - test/ansible/config/rbac/auth_proxy_role.yaml | 13 - .../config/rbac/auth_proxy_role_binding.yaml | 12 - .../config/rbac/auth_proxy_service.yaml | 14 - test/ansible/config/rbac/kustomization.yaml | 12 - .../config/rbac/leader_election_role.yaml | 25 - .../rbac/leader_election_role_binding.yaml | 12 - test/ansible/config/rbac/role.yaml | 186 ------- test/ansible/config/rbac/role_binding.yaml | 13 - .../ansible/config/samples/kustomization.yaml | 3 - .../samples/test_v1alpha1_inventorytest.yaml | 8 - .../config/testing/debug_logs_patch.yaml | 14 - .../ansible/config/testing/kustomization.yaml | 24 - .../ansible/config/testing/manager_image.yaml | 12 - .../config/testing/pull_policy/Always.yaml | 12 - .../testing/pull_policy/IfNotPresent.yaml | 12 - .../config/testing/pull_policy/Never.yaml | 12 - test/ansible/molecule/default/converge.yml | 18 - test/ansible/molecule/default/create.yml | 6 - test/ansible/molecule/default/destroy.yml | 24 - test/ansible/molecule/default/kustomize.yml | 15 - test/ansible/molecule/default/molecule.yml | 36 -- test/ansible/molecule/default/prepare.yml | 28 - test/ansible/molecule/default/verify.yml | 58 -- test/ansible/molecule/kind/converge.yml | 31 -- test/ansible/molecule/kind/create.yml | 8 - test/ansible/molecule/kind/destroy.yml | 12 - test/ansible/molecule/kind/molecule.yml | 42 -- test/ansible/playbooks/argstest.yml | 20 - test/ansible/playbooks/casetest.yml | 17 - test/ansible/playbooks/inventorytest.yml | 12 - test/ansible/playbooks/reconciliationtest.yml | 50 -- test/ansible/playbooks/selectortest.yml | 16 - test/ansible/playbooks/subresourcestest.yml | 51 -- test/ansible/requirements.yml | 5 - .../roles/inventorytest/tasks/main.yml | 13 - 79 files changed, 522 insertions(+), 1499 deletions(-) create mode 100644 hack/generate/samples/internal/ansible/advanced_molecule.go rename hack/generate/samples/internal/ansible/{molecule.go => memcached_molecule.go} (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/ansible.cfg (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/fixture_collection/galaxy.yml (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/fixture_collection/roles/dummy/tasks/main.yml (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/inventory/group_vars/test.yml (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/inventory/hosts (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/plugins/filter/test.py (100%) rename {test/ansible/playbooks => hack/generate/samples/internal/ansible/testdata}/secret.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/argstest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/casetest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/collectiontest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/inventorytest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/reconciliationtest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/secretstest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/selectortest_test.yml (100%) rename {test/ansible/molecule/default => hack/generate/samples/internal/ansible/testdata}/tasks/subresourcestest_test.yml (100%) rename {test/ansible => hack/generate/samples/internal/ansible/testdata}/watches.yaml (100%) delete mode 100644 internal/ansible/OWNERS delete mode 100644 test/ansible/.gitignore delete mode 100644 test/ansible/Dockerfile delete mode 100644 test/ansible/Makefile delete mode 100644 test/ansible/PROJECT delete mode 100644 test/ansible/config/crd/bases/test.example.com_argstests.yaml delete mode 100644 test/ansible/config/crd/bases/test.example.com_casetests.yaml delete mode 100644 test/ansible/config/crd/bases/test.example.com_collectiontests.yaml delete mode 100644 test/ansible/config/crd/bases/test.example.com_inventorytests.yaml delete mode 100644 test/ansible/config/crd/bases/test.example.com_reconciliationtests.yaml delete mode 100644 test/ansible/config/crd/bases/test.example.com_selectortests.yaml delete mode 100644 test/ansible/config/crd/bases/test.example.com_subresourcestests.yaml delete mode 100644 test/ansible/config/crd/kustomization.yaml delete mode 100644 test/ansible/config/default/kustomization.yaml delete mode 100644 test/ansible/config/default/manager_auth_proxy_patch.yaml delete mode 100644 test/ansible/config/manager/kustomization.yaml delete mode 100644 test/ansible/config/manager/manager.yaml delete mode 100644 test/ansible/config/prometheus/kustomization.yaml delete mode 100644 test/ansible/config/prometheus/monitor.yaml delete mode 100644 test/ansible/config/rbac/argstest_editor_role.yaml delete mode 100644 test/ansible/config/rbac/argstest_viewer_role.yaml delete mode 100644 test/ansible/config/rbac/auth_proxy_client_clusterrole.yaml delete mode 100644 test/ansible/config/rbac/auth_proxy_role.yaml delete mode 100644 test/ansible/config/rbac/auth_proxy_role_binding.yaml delete mode 100644 test/ansible/config/rbac/auth_proxy_service.yaml delete mode 100644 test/ansible/config/rbac/kustomization.yaml delete mode 100644 test/ansible/config/rbac/leader_election_role.yaml delete mode 100644 test/ansible/config/rbac/leader_election_role_binding.yaml delete mode 100644 test/ansible/config/rbac/role.yaml delete mode 100644 test/ansible/config/rbac/role_binding.yaml delete mode 100644 test/ansible/config/samples/kustomization.yaml delete mode 100644 test/ansible/config/samples/test_v1alpha1_inventorytest.yaml delete mode 100644 test/ansible/config/testing/debug_logs_patch.yaml delete mode 100644 test/ansible/config/testing/kustomization.yaml delete mode 100644 test/ansible/config/testing/manager_image.yaml delete mode 100644 test/ansible/config/testing/pull_policy/Always.yaml delete mode 100644 test/ansible/config/testing/pull_policy/IfNotPresent.yaml delete mode 100644 test/ansible/config/testing/pull_policy/Never.yaml delete mode 100644 test/ansible/molecule/default/converge.yml delete mode 100644 test/ansible/molecule/default/create.yml delete mode 100644 test/ansible/molecule/default/destroy.yml delete mode 100644 test/ansible/molecule/default/kustomize.yml delete mode 100644 test/ansible/molecule/default/molecule.yml delete mode 100644 test/ansible/molecule/default/prepare.yml delete mode 100644 test/ansible/molecule/default/verify.yml delete mode 100644 test/ansible/molecule/kind/converge.yml delete mode 100644 test/ansible/molecule/kind/create.yml delete mode 100644 test/ansible/molecule/kind/destroy.yml delete mode 100644 test/ansible/molecule/kind/molecule.yml delete mode 100644 test/ansible/playbooks/argstest.yml delete mode 100644 test/ansible/playbooks/casetest.yml delete mode 100644 test/ansible/playbooks/inventorytest.yml delete mode 100644 test/ansible/playbooks/reconciliationtest.yml delete mode 100644 test/ansible/playbooks/selectortest.yml delete mode 100644 test/ansible/playbooks/subresourcestest.yml delete mode 100644 test/ansible/requirements.yml delete mode 100644 test/ansible/roles/inventorytest/tasks/main.yml diff --git a/.gitignore b/.gitignore index a73e7b6722..dab1d92fac 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ website/tech-doc-hugo # Ignore molecule samples testdata if it be generated in the testdata/ diretory testdata/ansible/memcached-molecule-operator +testdata/ansible/advanced-molecule-operator # Trash files *\.DS_Store diff --git a/Makefile b/Makefile index 085b41b699..7d51a607c0 100644 --- a/Makefile +++ b/Makefile @@ -165,6 +165,7 @@ test-e2e-ansible:: image/ansible-operator ## Run Ansible e2e tests go test -count=1 ./internal/ansible/proxy/... go test ./test/e2e-ansible -v -ginkgo.v test-e2e-ansible-molecule:: image/ansible-operator ## Run molecule-based Ansible e2e tests + go run ./hack/generate/samples/molecule/generate.go ./hack/tests/e2e-ansible-molecule.sh test-e2e-helm:: image/helm-operator ## Run Helm e2e tests go test ./test/e2e-helm -v -ginkgo.v diff --git a/hack/generate/samples/internal/ansible/advanced_molecule.go b/hack/generate/samples/internal/ansible/advanced_molecule.go new file mode 100644 index 0000000000..db18728f86 --- /dev/null +++ b/hack/generate/samples/internal/ansible/advanced_molecule.go @@ -0,0 +1,502 @@ +// 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" + "os/exec" + "path/filepath" + "strings" + + log "github.com/sirupsen/logrus" + kbtestutils "sigs.k8s.io/kubebuilder/v2/test/e2e/utils" + + "github.com/operator-framework/operator-sdk/hack/generate/samples/internal/pkg" + "github.com/operator-framework/operator-sdk/internal/testutils" +) + +// MoleculeAnsible defines the context for the sample +type AdvancedMolecule struct { + ctx *pkg.SampleContext +} + +// NewMoleculeAnsible return a MoleculeAnsible +func NewAdvancedMolecule(ctx *pkg.SampleContext) AdvancedMolecule { + return AdvancedMolecule{ctx} +} + +// Prepare the Context for the Memcached Ansible Sample +// Note that sample directory will be re-created and the context data for the sample +// will be set such as the domain and GVK. +func (ma *AdvancedMolecule) Prepare() { + log.Infof("destroying directory for memcached Ansible samples") + ma.ctx.Destroy() + + log.Infof("creating directory") + err := ma.ctx.Prepare() + pkg.CheckError("creating directory for Advanced Molecule Sample", err) + + log.Infof("setting domain and GVK") + // nolint:goconst + ma.ctx.Domain = "example.com" + // nolint:goconst + ma.ctx.Version = "v1alpha1" + ma.ctx.Group = "test" + ma.ctx.Kind = "InventoryTest" +} + +// Run the steps to create the Memcached Ansible Sample +func (ma *AdvancedMolecule) Run() { + log.Infof("creating the project") + err := ma.ctx.Init( + "--plugins", "ansible", + "--group", ma.ctx.Group, + "--version", ma.ctx.Version, + "--kind", ma.ctx.Kind, + "--domain", ma.ctx.Domain, + "--generate-role", + "--generate-playbook") + pkg.CheckError("creating the project", err) + + log.Infof("enabling multigroup support") + err = ma.ctx.AllowProjectBeMultiGroup() + pkg.CheckError("updating PROJECT file", err) + + inventoryRoleTask := filepath.Join(ma.ctx.Dir, "roles", "inventorytest", "tasks", "main.yml") + log.Infof("inserting code to inventory role task") + err = testutils.ReplaceInFile(inventoryRoleTask, "# tasks file for InventoryTest", inventoryRoleTaskFragment) + pkg.CheckError("replacing inventory task", err) + + log.Infof("updating inventorytest sample") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"), + "name: inventorytest-sample", "name: inventorytest-sample\n annotations:\n \"ansible.sdk.operatorframework.io/verbosity\": \"0\"") + pkg.CheckError("updating inventorytest sample", err) + + log.Infof("updating spec of inventorytest sample") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"), + "foo: bar", "size: 3") + pkg.CheckError("updating spec of inventorytest sample", err) + + ma.addPlaybooks() + ma.updatePlaybooks() + ma.addMocksFromTestdata() + ma.updateDockerfile() + ma.updateConfig() +} + +func (ma *AdvancedMolecule) updateConfig() { + log.Infof("adding customized roles") + err := testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "rbac", "role.yaml"), + "# +kubebuilder:scaffold:rules", cmRolesFragment) + pkg.CheckError("adding customized roles", err) + + log.Infof("adding manager arg") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"), + "args:\n - \"--enable-leader-election\"\n - \"--leader-election-id=advanced-molecule-operator\"", + "args:\n - \"--metrics-addr=127.0.0.1:8080\"\n - \"--enable-leader-election\"\n - \"--leader-election-id=advanced-molecule-operator\"\n - \"--ansible-args='--vault-password-file /opt/ansible/pwd.yml'\"") + pkg.CheckError("adding manager arg", err) + + log.Infof("adding manager env") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"), + "- name: ANSIBLE_GATHERING\n value: explicit", managerEnv) + pkg.CheckError("adding manager env", err) + + log.Infof("adding vaulting args to the proxy auth") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "default", "manager_auth_proxy_patch.yaml"), + "- \"--leader-election-id=advanced-molecule-operator\"", + "- \"--leader-election-id=advanced-molecule-operator\"\n - \"--ansible-args='--vault-password-file /opt/ansible/pwd.yml'\"") + pkg.CheckError("adding vaulting args to the proxy auth", err) + + log.Infof("adding task to not pull image to the config/testing") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "testing", "kustomization.yaml"), + "- manager_image.yaml", "- manager_image.yaml\n- pull_policy/Never.yaml") + pkg.CheckError("adding task to not pull image to the config/testing", err) +} + +func (ma *AdvancedMolecule) addMocksFromTestdata() { + log.Infof("adding ansible.cfg") + cmd := exec.Command("cp", "../../../hack/generate/samples/internal/ansible/testdata/ansible.cfg", ma.ctx.Dir) + _, err := ma.ctx.Run(cmd) + pkg.CheckError("adding ansible.cfg", err) + + log.Infof("adding plugins/") + cmd = exec.Command("cp", "-r", "../../../hack/generate/samples/internal/ansible/testdata/plugins/", filepath.Join(ma.ctx.Dir, "plugins/")) + _, err = ma.ctx.Run(cmd) + pkg.CheckError("adding plugins/", err) + + log.Infof("adding fixture_collection/") + cmd = exec.Command("cp", "-r", "../../../hack/generate/samples/internal/ansible/testdata/fixture_collection/", filepath.Join(ma.ctx.Dir, "fixture_collection/")) + _, err = ma.ctx.Run(cmd) + pkg.CheckError("adding fixture_collection/", err) + + log.Infof("replacing watches.yaml") + cmd = exec.Command("cp", "-r", "../../../hack/generate/samples/internal/ansible/testdata/watches.yaml", ma.ctx.Dir) + _, err = ma.ctx.Run(cmd) + pkg.CheckError("replacing watches.yaml", err) + + log.Infof("adding tasks/") + cmd = exec.Command("cp", "-r", "../../../hack/generate/samples/internal/ansible/testdata/tasks/", filepath.Join(ma.ctx.Dir, "molecule/default/")) + _, err = ma.ctx.Run(cmd) + pkg.CheckError("adding tasks/", err) + + log.Infof("adding secret playbook") + cmd = exec.Command("cp", "-r", "../../../hack/generate/samples/internal/ansible/testdata/secret.yml", filepath.Join(ma.ctx.Dir, "playbooks/secret.yml")) + _, err = ma.ctx.Run(cmd) + pkg.CheckError("adding secret playbook", err) + + log.Infof("adding inventory/") + cmd = exec.Command("cp", "-r", "../../../hack/generate/samples/internal/ansible/testdata/inventory/", filepath.Join(ma.ctx.Dir, "inventory/")) + _, err = ma.ctx.Run(cmd) + pkg.CheckError("adding inventory/", err) +} + +func (ma *AdvancedMolecule) updateDockerfile() { + log.Infof("replacing project Dockerfile to use ansible base image with the dev tag") + err := testutils.ReplaceRegexInFile(filepath.Join(ma.ctx.Dir, "Dockerfile"), "quay.io/operator-framework/ansible-operator:.*", "quay.io/operator-framework/ansible-operator:dev") + pkg.CheckError("replacing Dockerfile", err) + + log.Infof("inserting code to Dockerfile") + err = kbtestutils.InsertCode(filepath.Join(ma.ctx.Dir, "Dockerfile"), "COPY playbooks/ ${HOME}/playbooks/", dockerfileFragment) + pkg.CheckError("replacing Dockerfile", err) +} + +func (ma *AdvancedMolecule) updatePlaybooks() { + log.Infof("adding playbook for argstest") + err := testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "argstest.yml"), + originalPlaybookFragment, argsPlaybook) + pkg.CheckError("adding playbook for argstest", err) + + log.Infof("adding playbook for casetest") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "casetest.yml"), + originalPlaybookFragment, casePlaybook) + pkg.CheckError("adding playbook for casetest", err) + + log.Infof("adding playbook for inventorytest") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "inventorytest.yml"), + "---\n- hosts: localhost\n gather_facts: no\n collections:\n - community.kubernetes\n - operator_sdk.util\n tasks:\n - import_role:\n name: \"inventorytest\"", + inventoryPlaybook) + pkg.CheckError("adding playbook for inventorytest", err) + + log.Infof("adding playbook for reconciliationtest") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "reconciliationtest.yml"), + originalPlaybookFragment, reconciliationPlaybook) + pkg.CheckError("adding playbook for reconciliationtest", err) + + log.Infof("adding playbook for selectortest") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "selectortest.yml"), + originalPlaybookFragment, selectorPlaybook) + pkg.CheckError("adding playbook for selectortest", err) + + log.Infof("adding playbook for subresourcestest") + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "subresourcestest.yml"), + originalPlaybookFragment, subresourcesPlaybook) + pkg.CheckError("adding playbook for subresourcestest", err) +} + +func (ma *AdvancedMolecule) addPlaybooks() { + allPlaybookKinds := []string{ + "ArgsTest", + "CaseTest", + "CollectionTest", + "ReconciliationTest", + "SelectorTest", + "SubresourcesTest", + } + + // Crate API + for _, k := range allPlaybookKinds { + logMsgForKind := fmt.Sprintf("creating an API %s", k) + log.Infof(logMsgForKind) + err := ma.ctx.CreateAPI( + "--group", ma.ctx.Group, + "--version", ma.ctx.Version, + "--kind", k, + "--generate-playbook") + pkg.CheckError(logMsgForKind, err) + + k = strings.ToLower(k) + task := fmt.Sprintf("%s_test.yml", k) + logMsgForKind = fmt.Sprintf("removing FIXME assert from %s", task) + log.Infof(logMsgForKind) + err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", task), + fixmeAssert, "") + pkg.CheckError(logMsgForKind, err) + } +} + +const managerEnv = `- name: ANSIBLE_DEBUG_LOGS + value: "TRUE" + - name: ANSIBLE_GATHERING + value: explicit + - name: ANSIBLE_INVENTORY + value: /opt/ansible/inventory` + +const cmRolesFragment = ` ## + ## Base operator rules + ## + - apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - apps + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +# +kubebuilder:scaffold:rules` + +const originalPlaybookFragment = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + - operator_sdk.util + tasks: [] +` + +const dockerfileFragment = ` + +# Customizations done to check advanced scenarios +COPY inventory/ ${HOME}/inventory/ +COPY plugins/ ${HOME}/plugins/ +COPY ansible.cfg /etc/ansible/ansible.cfg +COPY fixture_collection/ /tmp/fixture_collection/ +USER root +RUN chmod -R ug+rwx /tmp/fixture_collection +USER 1001 +RUN ansible-galaxy collection build /tmp/fixture_collection/ --output-path /tmp/fixture_collection/ \ + && ansible-galaxy collection install /tmp/fixture_collection/operator_sdk-test_fixtures-0.0.0.tar.gz +RUN echo abc123 > /opt/ansible/pwd.yml \ + && ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml +` + +const inventoryRoleTaskFragment = ` +- when: sentinel | test + block: + - community.kubernetes.k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: inventory-cm + namespace: '{{ meta.namespace }}' + data: + sentinel: '{{ sentinel }}' + groups: '{{ groups | to_nice_yaml }}'` + +const argsPlaybook = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + tasks: + - name: Get the decrypted message variable + include_vars: + file: /opt/ansible/vars.yml + name: the_secret + - name: Create configmap + k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: '{{ meta.name }}' + namespace: '{{ meta.namespace }}' + data: + msg: The decrypted value is {{the_secret.the_secret}} +` + +const casePlaybook = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + tasks: + - name: Create configmap + k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: '{{ meta.name }}' + namespace: '{{ meta.namespace }}' + data: + shouldBeCamel: '{{ camelCaseVar | default("false") }}' +` + +const inventoryPlaybook = `--- +- hosts: test + gather_facts: no + tasks: + - import_role: + name: "inventorytest" + +- hosts: localhost + gather_facts: no + tasks: + - command: echo hello + - debug: msg='{{ "hello" | test }}'` + +const reconciliationPlaybook = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + tasks: + - name: retrieve configmap + k8s_info: + api_version: v1 + kind: ConfigMap + namespace: '{{ meta.namespace }}' + name: '{{ meta.name }}' + register: configmap + + - name: create configmap + k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: '{{ meta.name }}' + namespace: '{{ meta.namespace }}' + data: + iterations: '1' + when: configmap.resources|length == 0 + + - name: Update ConfigMap + k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: '{{ meta.name }}' + namespace: '{{ meta.namespace }}' + data: + iterations: '{{ (configmap.resources.0.data.iterations|int) + 1 }}' + when: configmap.resources|length > 0 and (configmap.resources.0.data.iterations|int) < 5 + + - name: retrieve configmap + k8s_info: + api_version: v1 + kind: ConfigMap + namespace: '{{ meta.namespace }}' + name: '{{ meta.name }}' + register: configmap + + - name: Using the requeue_after module + operator_sdk.util.requeue_after: + time: 1s + when: configmap.resources|length > 0 and (configmap.resources.0.data.iterations|int) < 5 +` + +const selectorPlaybook = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + tasks: + - name: Create configmap + k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: '{{ meta.name }}' + namespace: '{{ meta.namespace }}' + data: + hello: "world" +` + +const subresourcesPlaybook = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + - operator_sdk.util + + tasks: + - name: Deploy busybox pod + k8s: + definition: + apiVersion: v1 + kind: Pod + metadata: + name: '{{ meta.name }}-busybox' + namespace: '{{ meta.namespace }}' + spec: + containers: + - image: busybox + name: sleep + args: + - "/bin/sh" + - "-c" + - "while true ; do echo '{{ log_message }}' ; sleep 5 ; done" + wait: yes + + - name: Execute command in busybox pod + k8s_exec: + namespace: '{{ meta.namespace }}' + pod: '{{ meta.name }}-busybox' + command: '{{ exec_command }}' + register: exec_result + + - debug: var=exec_result + + - name: Get logs from busybox pod + k8s_log: + name: '{{ meta.name }}-busybox' + namespace: '{{ meta.namespace }}' + register: log_result + + - name: Write results to resource status + k8s_status: + api_version: test.example.com/v1alpha1 + kind: SubresourcesTest + name: '{{ meta.name }}' + namespace: '{{ meta.namespace }}' + status: + execCommandStdout: '{{ exec_result.stdout.strip() }}' + execCommandStderr: '{{ exec_result.stderr.strip() }}' + logs: '{{ log_result.log }}' +` + +// GenerateMoleculeAnsibleSample will call all actions to create the directory and generate the sample +// The Context to run the samples are not the same in the e2e test. In this way, note that it should NOT +// be called in the e2e tests since it will call the Prepare() to set the sample context and generate the files +// in the testdata directory. The e2e tests only ought to use the Run() method with the TestContext. +func GenerateMoleculeAdvancedAnsibleSample(path string) { + ctx, err := pkg.NewSampleContext(testutils.BinaryName, filepath.Join(path, "advanced-molecule-operator"), + "GO111MODULE=on") + pkg.CheckError("generating Ansible Molecule Advanced Operator context", err) + + molecule := NewAdvancedMolecule(&ctx) + molecule.Prepare() + molecule.Run() +} diff --git a/hack/generate/samples/internal/ansible/molecule.go b/hack/generate/samples/internal/ansible/memcached_molecule.go similarity index 100% rename from hack/generate/samples/internal/ansible/molecule.go rename to hack/generate/samples/internal/ansible/memcached_molecule.go diff --git a/test/ansible/ansible.cfg b/hack/generate/samples/internal/ansible/testdata/ansible.cfg similarity index 100% rename from test/ansible/ansible.cfg rename to hack/generate/samples/internal/ansible/testdata/ansible.cfg diff --git a/test/ansible/fixture_collection/galaxy.yml b/hack/generate/samples/internal/ansible/testdata/fixture_collection/galaxy.yml similarity index 100% rename from test/ansible/fixture_collection/galaxy.yml rename to hack/generate/samples/internal/ansible/testdata/fixture_collection/galaxy.yml diff --git a/test/ansible/fixture_collection/roles/dummy/tasks/main.yml b/hack/generate/samples/internal/ansible/testdata/fixture_collection/roles/dummy/tasks/main.yml similarity index 100% rename from test/ansible/fixture_collection/roles/dummy/tasks/main.yml rename to hack/generate/samples/internal/ansible/testdata/fixture_collection/roles/dummy/tasks/main.yml diff --git a/test/ansible/inventory/group_vars/test.yml b/hack/generate/samples/internal/ansible/testdata/inventory/group_vars/test.yml similarity index 100% rename from test/ansible/inventory/group_vars/test.yml rename to hack/generate/samples/internal/ansible/testdata/inventory/group_vars/test.yml diff --git a/test/ansible/inventory/hosts b/hack/generate/samples/internal/ansible/testdata/inventory/hosts similarity index 100% rename from test/ansible/inventory/hosts rename to hack/generate/samples/internal/ansible/testdata/inventory/hosts diff --git a/test/ansible/plugins/filter/test.py b/hack/generate/samples/internal/ansible/testdata/plugins/filter/test.py similarity index 100% rename from test/ansible/plugins/filter/test.py rename to hack/generate/samples/internal/ansible/testdata/plugins/filter/test.py diff --git a/test/ansible/playbooks/secret.yml b/hack/generate/samples/internal/ansible/testdata/secret.yml similarity index 100% rename from test/ansible/playbooks/secret.yml rename to hack/generate/samples/internal/ansible/testdata/secret.yml diff --git a/test/ansible/molecule/default/tasks/argstest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/argstest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/argstest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/argstest_test.yml diff --git a/test/ansible/molecule/default/tasks/casetest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/casetest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/casetest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/casetest_test.yml diff --git a/test/ansible/molecule/default/tasks/collectiontest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/collectiontest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/collectiontest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/collectiontest_test.yml diff --git a/test/ansible/molecule/default/tasks/inventorytest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/inventorytest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/inventorytest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/inventorytest_test.yml diff --git a/test/ansible/molecule/default/tasks/reconciliationtest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/reconciliationtest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/reconciliationtest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/reconciliationtest_test.yml diff --git a/test/ansible/molecule/default/tasks/secretstest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/secretstest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/secretstest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/secretstest_test.yml diff --git a/test/ansible/molecule/default/tasks/selectortest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/selectortest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/selectortest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/selectortest_test.yml diff --git a/test/ansible/molecule/default/tasks/subresourcestest_test.yml b/hack/generate/samples/internal/ansible/testdata/tasks/subresourcestest_test.yml similarity index 100% rename from test/ansible/molecule/default/tasks/subresourcestest_test.yml rename to hack/generate/samples/internal/ansible/testdata/tasks/subresourcestest_test.yml diff --git a/test/ansible/watches.yaml b/hack/generate/samples/internal/ansible/testdata/watches.yaml similarity index 100% rename from test/ansible/watches.yaml rename to hack/generate/samples/internal/ansible/testdata/watches.yaml diff --git a/hack/generate/samples/molecule/generate.go b/hack/generate/samples/molecule/generate.go index 5345a2af9b..69f330269f 100644 --- a/hack/generate/samples/molecule/generate.go +++ b/hack/generate/samples/molecule/generate.go @@ -35,6 +35,9 @@ func main() { // path is the path provided to generate the molecule sample path string + + // sample is the name of the mock was selected to be generated + sample string ) // testdata is the path where all samples are generate @@ -42,6 +45,7 @@ func main() { flag.StringVar(&binaryName, "bin", testutils.BinaryName, "Binary path that should be used") flag.StringVar(&path, "path", "", "Path where the molecule should be called") + flag.StringVar(&sample, "sample", "", "To generate only the selected option. Options: [advanced,memcached]") flag.Parse() @@ -59,5 +63,12 @@ func main() { log.Infof("creating Ansible Molecule Mock Sample") log.Infof("using the path: (%v)", path) - ansible.GenerateMoleculeAnsibleSample(path) + + if sample == "" || sample == "memcached" { + ansible.GenerateMoleculeAnsibleSample(path) + } + + if sample == "" || sample == "advanced" { + ansible.GenerateMoleculeAdvancedAnsibleSample(path) + } } diff --git a/hack/tests/e2e-ansible-molecule.sh b/hack/tests/e2e-ansible-molecule.sh index a68976860a..087db61fc7 100755 --- a/hack/tests/e2e-ansible-molecule.sh +++ b/hack/tests/e2e-ansible-molecule.sh @@ -17,14 +17,15 @@ pip3 install --user ansible-lint yamllint pip3 install --user docker==4.2.2 openshift jmespath ansible-galaxy collection install 'community.kubernetes:<1.0.0' -header_text "Creating molecule sample" -go run ./hack/generate/samples/molecule/generate.go --path=$TMPDIR +header_text "Copying molecule testdata scenarios" +cp -r $ROOTDIR/testdata/ansible/memcached-molecule-operator/ $TMPDIR/memcached-molecule-operator +cp -r $ROOTDIR/testdata/ansible/advanced-molecule-operator/ $TMPDIR/advanced-molecule-operator pushd "$TMPDIR" popd cd $TMPDIR/memcached-molecule-operator -header_text "Test Kind" +header_text "Running Kind test with memcached-molecule-operator/" make kustomize if [ -f ./bin/kustomize ] ; then KUSTOMIZE="$(realpath ./bin/kustomize)" @@ -33,12 +34,9 @@ else fi KUSTOMIZE_PATH=${KUSTOMIZE} TEST_OPERATOR_NAMESPACE=default molecule test -s kind -rm -rf $KUSTOMIZE -cd $TMPDIR/ -rm -rf memcached-molecule-operator -header_text "Test Ansible Molecule scenarios" -pushd "${ROOTDIR}/test/ansible" +header_text "Running Default test with advanced-molecule-operator/" +cd $TMPDIR/advanced-molecule-operator make kustomize if [ -f ./bin/kustomize ] ; then @@ -48,7 +46,6 @@ else fi DEST_IMAGE="quay.io/example/advanced-molecule-operator:v0.0.1" -sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/ansible-operator)(:.*)?/\1:dev/g' Dockerfile; rm -f Dockerfile.bak docker build -t "$DEST_IMAGE" --no-cache . load_image_if_kind "$DEST_IMAGE" KUSTOMIZE_PATH=$KUSTOMIZE OPERATOR_PULL_POLICY=Never OPERATOR_IMAGE=${DEST_IMAGE} TEST_OPERATOR_NAMESPACE=osdk-test molecule test diff --git a/internal/ansible/OWNERS b/internal/ansible/OWNERS deleted file mode 100644 index 9702fa3403..0000000000 --- a/internal/ansible/OWNERS +++ /dev/null @@ -1,6 +0,0 @@ -approvers: - - fabianvf - - jmrodri -reviewers: - - fabianvf - - jmrodri diff --git a/test/ansible/.gitignore b/test/ansible/.gitignore deleted file mode 100644 index 62fd3e3995..0000000000 --- a/test/ansible/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ - -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib -bin - -# editor and IDE paraphernalia -.idea -*.swp -*.swo -*~ diff --git a/test/ansible/Dockerfile b/test/ansible/Dockerfile deleted file mode 100644 index b29926583a..0000000000 --- a/test/ansible/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM quay.io/operator-framework/ansible-operator:v1.2.0 - -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 roles/ ${HOME}/roles/ -COPY playbooks/ ${HOME}/playbooks/ - -# Customizations done to check advanced scenarios -COPY inventory/ ${HOME}/inventory/ -COPY plugins/ ${HOME}/plugins/ -COPY ansible.cfg /etc/ansible/ansible.cfg -COPY fixture_collection/ /tmp/fixture_collection/ -USER root -RUN chmod -R ug+rwx /tmp/fixture_collection -USER 1001 -RUN ansible-galaxy collection build /tmp/fixture_collection/ --output-path /tmp/fixture_collection/ \ - && ansible-galaxy collection install /tmp/fixture_collection/operator_sdk-test_fixtures-0.0.0.tar.gz -RUN echo abc123 > /opt/ansible/pwd.yml \ - && ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml - diff --git a/test/ansible/Makefile b/test/ansible/Makefile deleted file mode 100644 index 1fdb988365..0000000000 --- a/test/ansible/Makefile +++ /dev/null @@ -1,92 +0,0 @@ -# Current Operator version -VERSION ?= 0.0.1 -# Default bundle image tag -BUNDLE_IMG ?= controller-bundle:$(VERSION) -# Options for 'bundle-build' -ifneq ($(origin CHANNELS), undefined) -BUNDLE_CHANNELS := --channels=$(CHANNELS) -endif -ifneq ($(origin DEFAULT_CHANNEL), undefined) -BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) -endif -BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) - -# Image URL to use all building/pushing image targets -IMG ?= controller:latest - -all: docker-build - -# Run against the configured Kubernetes cluster in ~/.kube/config -run: ansible-operator - $(ANSIBLE_OPERATOR) run - -# Install CRDs into a cluster -install: kustomize - $(KUSTOMIZE) build config/crd | kubectl apply -f - - -# Uninstall CRDs from a cluster -uninstall: kustomize - $(KUSTOMIZE) build config/crd | kubectl delete -f - - -# Deploy controller in the configured Kubernetes cluster in ~/.kube/config -deploy: kustomize - cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} - $(KUSTOMIZE) build config/default | kubectl apply -f - - -# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config -undeploy: kustomize - $(KUSTOMIZE) build config/default | kubectl delete -f - - -# Build the docker image -docker-build: - docker build . -t ${IMG} - -# Push the docker image -docker-push: - docker push ${IMG} - -PATH := $(PATH):$(PWD)/bin -SHELL := env PATH=$(PATH) /bin/sh -OS = $(shell uname -s | tr '[:upper:]' '[:lower:]') -ARCH = $(shell uname -m | sed 's/x86_64/amd64/') -OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/') -ARCHOPER = $(shell uname -m ) - -kustomize: -ifeq (, $(shell which kustomize 2>/dev/null)) - @{ \ - set -e ;\ - mkdir -p bin ;\ - curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\ - } -KUSTOMIZE=$(realpath ./bin/kustomize) -else -KUSTOMIZE=$(shell which kustomize) -endif - -ansible-operator: -ifeq (, $(shell which ansible-operator 2>/dev/null)) - @{ \ - set -e ;\ - mkdir -p bin ;\ - curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.2.0/ansible-operator-v1.2.0-$(ARCHOPER)-$(OSOPER) ;\ - mv ansible-operator-v1.2.0-$(ARCHOPER)-$(OSOPER) ./bin/ansible-operator ;\ - chmod +x ./bin/ansible-operator ;\ - } -ANSIBLE_OPERATOR=$(realpath ./bin/ansible-operator) -else -ANSIBLE_OPERATOR=$(shell which ansible-operator) -endif - -# Generate bundle manifests and metadata, then validate generated files. -.PHONY: bundle -bundle: kustomize - operator-sdk generate kustomize manifests -q - cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) - $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) - operator-sdk bundle validate ./bundle - -# Build the bundle image. -.PHONY: bundle-build -bundle-build: - docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . diff --git a/test/ansible/PROJECT b/test/ansible/PROJECT deleted file mode 100644 index fb5e744071..0000000000 --- a/test/ansible/PROJECT +++ /dev/null @@ -1,24 +0,0 @@ -domain: example.com -layout: ansible.sdk.operatorframework.io/v1 -multigroup: true -projectName: advanced-molecule-operator -resources: -- group: test - kind: InventoryTest - version: v1alpha1 -- group: test - kind: ArgsTest - version: v1alpha1 -- group: test - kind: CaseTest - version: v1alpha1 -- group: test - kind: CollectionTest - version: v1alpha1 -- group: test - kind: SelectorTest - version: v1alpha1 -- group: test - kind: SubresourcesTest - version: v1alpha1 -version: 3-alpha diff --git a/test/ansible/config/crd/bases/test.example.com_argstests.yaml b/test/ansible/config/crd/bases/test.example.com_argstests.yaml deleted file mode 100644 index 4370af5f84..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_argstests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: argstests.test.example.com -spec: - group: test.example.com - names: - kind: ArgsTest - listKind: ArgsTestList - plural: argstests - singular: argstest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: ArgsTest is the Schema for the argstests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of ArgsTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of ArgsTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/bases/test.example.com_casetests.yaml b/test/ansible/config/crd/bases/test.example.com_casetests.yaml deleted file mode 100644 index 639d2a77bc..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_casetests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: casetests.test.example.com -spec: - group: test.example.com - names: - kind: CaseTest - listKind: CaseTestList - plural: casetests - singular: casetest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: CaseTest is the Schema for the casetests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of CaseTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of CaseTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/bases/test.example.com_collectiontests.yaml b/test/ansible/config/crd/bases/test.example.com_collectiontests.yaml deleted file mode 100644 index af8a6c499f..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_collectiontests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: collectiontests.test.example.com -spec: - group: test.example.com - names: - kind: CollectionTest - listKind: CollectionTestList - plural: collectiontests - singular: collectiontest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: CollectionTest is the Schema for the collectiontests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of CollectionTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of CollectionTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/bases/test.example.com_inventorytests.yaml b/test/ansible/config/crd/bases/test.example.com_inventorytests.yaml deleted file mode 100644 index d10ff7c04a..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_inventorytests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: inventorytests.test.example.com -spec: - group: test.example.com - names: - kind: InventoryTest - listKind: InventoryTestList - plural: inventorytests - singular: inventorytest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: InventoryTest is the Schema for the inventorytests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of InventoryTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of InventoryTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/bases/test.example.com_reconciliationtests.yaml b/test/ansible/config/crd/bases/test.example.com_reconciliationtests.yaml deleted file mode 100644 index d8343116ff..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_reconciliationtests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: reconciliationtests.test.example.com -spec: - group: test.example.com - names: - kind: ReconciliationTest - listKind: ReconciliationTestList - plural: reconciliationtests - singular: reconciliationtest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: ReconciliationTest is the Schema for the reconciliationtests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of ReconciliationTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of ReconciliationTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/bases/test.example.com_selectortests.yaml b/test/ansible/config/crd/bases/test.example.com_selectortests.yaml deleted file mode 100644 index 2068942e73..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_selectortests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: selectortests.test.example.com -spec: - group: test.example.com - names: - kind: SelectorTest - listKind: SelectorTestList - plural: selectortests - singular: selectortest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: SelectorTest is the Schema for the selectortests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of SelectorTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of SelectorTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/bases/test.example.com_subresourcestests.yaml b/test/ansible/config/crd/bases/test.example.com_subresourcestests.yaml deleted file mode 100644 index 38c1d3a690..0000000000 --- a/test/ansible/config/crd/bases/test.example.com_subresourcestests.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: subresourcestests.test.example.com -spec: - group: test.example.com - names: - kind: SubresourcesTest - listKind: SubresourcesTestList - plural: subresourcestests - singular: subresourcestest - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: SubresourcesTest is the Schema for the subresourcestests API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec defines the desired state of SubresourcesTest - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of SubresourcesTest - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/ansible/config/crd/kustomization.yaml b/test/ansible/config/crd/kustomization.yaml deleted file mode 100644 index 4742ee14fa..0000000000 --- a/test/ansible/config/crd/kustomization.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# This kustomization.yaml is not intended to be run by itself, -# since it depends on service name and namespace that are out of this kustomize package. -# It should be run by config/default -resources: -- bases/test.example.com_inventorytests.yaml -- bases/test.example.com_argstests.yaml -- bases/test.example.com_casetests.yaml -- bases/test.example.com_collectiontests.yaml -- bases/test.example.com_selectortests.yaml -- bases/test.example.com_subresourcestests.yaml -- bases/test.example.com_reconciliationtests.yaml -# +kubebuilder:scaffold:crdkustomizeresource diff --git a/test/ansible/config/default/kustomization.yaml b/test/ansible/config/default/kustomization.yaml deleted file mode 100644 index 1307200548..0000000000 --- a/test/ansible/config/default/kustomization.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Adds namespace to all resources. -namespace: advanced-molecule-operator-system - -# Value of this field is prepended to the -# names of all resources, e.g. a deployment named -# "wordpress" becomes "alices-wordpress". -# Note that it should also match with the prefix (text before '-') of the namespace -# field above. -namePrefix: advanced-molecule-operator- - -# Labels to add to all resources and selectors. -#commonLabels: -# someName: someValue - -bases: -- ../crd -- ../rbac -- ../manager -# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. -#- ../prometheus - -patchesStrategicMerge: - # Protect the /metrics endpoint by putting it behind auth. - # If you want your controller-manager to expose the /metrics - # endpoint w/o any authn/z, please comment the following line. -- manager_auth_proxy_patch.yaml diff --git a/test/ansible/config/default/manager_auth_proxy_patch.yaml b/test/ansible/config/default/manager_auth_proxy_patch.yaml deleted file mode 100644 index 4fe5572c44..0000000000 --- a/test/ansible/config/default/manager_auth_proxy_patch.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# This patch inject a sidecar container which is a HTTP proxy for the -# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: kube-rbac-proxy - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 - args: - - "--secure-listen-address=0.0.0.0:8443" - - "--upstream=http://127.0.0.1:8080/" - - "--logtostderr=true" - - "--v=10" - ports: - - containerPort: 8443 - name: https - - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" - - "--enable-leader-election" - - "--leader-election-id=advanced-molecule-operator" - - "--ansible-args='--vault-password-file /opt/ansible/pwd.yml'" diff --git a/test/ansible/config/manager/kustomization.yaml b/test/ansible/config/manager/kustomization.yaml deleted file mode 100644 index 5c5f0b84cb..0000000000 --- a/test/ansible/config/manager/kustomization.yaml +++ /dev/null @@ -1,2 +0,0 @@ -resources: -- manager.yaml diff --git a/test/ansible/config/manager/manager.yaml b/test/ansible/config/manager/manager.yaml deleted file mode 100644 index cfee93297e..0000000000 --- a/test/ansible/config/manager/manager.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - labels: - control-plane: controller-manager - name: system ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system - labels: - control-plane: controller-manager -spec: - selector: - matchLabels: - control-plane: controller-manager - replicas: 1 - template: - metadata: - labels: - control-plane: controller-manager - spec: - containers: - - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" - - "--enable-leader-election" - - "--leader-election-id=advanced-molecule-operator" - - "--ansible-args='--vault-password-file /opt/ansible/pwd.yml'" - env: - - name: ANSIBLE_DEBUG_LOGS - value: "TRUE" - - name: ANSIBLE_GATHERING - value: explicit - - name: ANSIBLE_INVENTORY - value: /opt/ansible/inventory - image: controller:latest - terminationGracePeriodSeconds: 10 diff --git a/test/ansible/config/prometheus/kustomization.yaml b/test/ansible/config/prometheus/kustomization.yaml deleted file mode 100644 index ed137168a1..0000000000 --- a/test/ansible/config/prometheus/kustomization.yaml +++ /dev/null @@ -1,2 +0,0 @@ -resources: -- monitor.yaml diff --git a/test/ansible/config/prometheus/monitor.yaml b/test/ansible/config/prometheus/monitor.yaml deleted file mode 100644 index 1b44d4f617..0000000000 --- a/test/ansible/config/prometheus/monitor.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -# Prometheus Monitor Service (Metrics) -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - labels: - control-plane: controller-manager - name: controller-manager-metrics-monitor - namespace: system -spec: - endpoints: - - path: /metrics - port: https - selector: - matchLabels: - control-plane: controller-manager diff --git a/test/ansible/config/rbac/argstest_editor_role.yaml b/test/ansible/config/rbac/argstest_editor_role.yaml deleted file mode 100644 index b436fa9561..0000000000 --- a/test/ansible/config/rbac/argstest_editor_role.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# permissions for end users to edit argstests. -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: argstest-editor-role -rules: -- apiGroups: - - test.example.com - resources: - - argstests - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - test.example.com - resources: - - argstests/status - verbs: - - get diff --git a/test/ansible/config/rbac/argstest_viewer_role.yaml b/test/ansible/config/rbac/argstest_viewer_role.yaml deleted file mode 100644 index bba2d4f9c8..0000000000 --- a/test/ansible/config/rbac/argstest_viewer_role.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# permissions for end users to view argstests. -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: argstest-viewer-role -rules: -- apiGroups: - - test.example.com - resources: - - argstests - verbs: - - get - - list - - watch -- apiGroups: - - test.example.com - resources: - - argstests/status - verbs: - - get diff --git a/test/ansible/config/rbac/auth_proxy_client_clusterrole.yaml b/test/ansible/config/rbac/auth_proxy_client_clusterrole.yaml deleted file mode 100644 index bd4af137a9..0000000000 --- a/test/ansible/config/rbac/auth_proxy_client_clusterrole.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: metrics-reader -rules: -- nonResourceURLs: ["/metrics"] - verbs: ["get"] diff --git a/test/ansible/config/rbac/auth_proxy_role.yaml b/test/ansible/config/rbac/auth_proxy_role.yaml deleted file mode 100644 index 618f5e4177..0000000000 --- a/test/ansible/config/rbac/auth_proxy_role.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: proxy-role -rules: -- apiGroups: ["authentication.k8s.io"] - resources: - - tokenreviews - verbs: ["create"] -- apiGroups: ["authorization.k8s.io"] - resources: - - subjectaccessreviews - verbs: ["create"] diff --git a/test/ansible/config/rbac/auth_proxy_role_binding.yaml b/test/ansible/config/rbac/auth_proxy_role_binding.yaml deleted file mode 100644 index 48ed1e4b85..0000000000 --- a/test/ansible/config/rbac/auth_proxy_role_binding.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: proxy-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: proxy-role -subjects: -- kind: ServiceAccount - name: default - namespace: system diff --git a/test/ansible/config/rbac/auth_proxy_service.yaml b/test/ansible/config/rbac/auth_proxy_service.yaml deleted file mode 100644 index 6cf656be14..0000000000 --- a/test/ansible/config/rbac/auth_proxy_service.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - control-plane: controller-manager - name: controller-manager-metrics-service - namespace: system -spec: - ports: - - name: https - port: 8443 - targetPort: https - selector: - control-plane: controller-manager diff --git a/test/ansible/config/rbac/kustomization.yaml b/test/ansible/config/rbac/kustomization.yaml deleted file mode 100644 index 66c28338fe..0000000000 --- a/test/ansible/config/rbac/kustomization.yaml +++ /dev/null @@ -1,12 +0,0 @@ -resources: -- role.yaml -- role_binding.yaml -- leader_election_role.yaml -- leader_election_role_binding.yaml -# Comment the following 4 lines if you want to disable -# the auth proxy (https://github.com/brancz/kube-rbac-proxy) -# which protects your /metrics endpoint. -- auth_proxy_service.yaml -- auth_proxy_role.yaml -- auth_proxy_role_binding.yaml -- auth_proxy_client_clusterrole.yaml diff --git a/test/ansible/config/rbac/leader_election_role.yaml b/test/ansible/config/rbac/leader_election_role.yaml deleted file mode 100644 index 53e974910b..0000000000 --- a/test/ansible/config/rbac/leader_election_role.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# permissions to do leader election. -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: leader-election-role -rules: -- apiGroups: - - "" - resources: - - configmaps - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - "" - resources: - - events - verbs: - - create - - patch diff --git a/test/ansible/config/rbac/leader_election_role_binding.yaml b/test/ansible/config/rbac/leader_election_role_binding.yaml deleted file mode 100644 index eed16906f4..0000000000 --- a/test/ansible/config/rbac/leader_election_role_binding.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: leader-election-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: leader-election-role -subjects: -- kind: ServiceAccount - name: default - namespace: system diff --git a/test/ansible/config/rbac/role.yaml b/test/ansible/config/rbac/role.yaml deleted file mode 100644 index a023a52179..0000000000 --- a/test/ansible/config/rbac/role.yaml +++ /dev/null @@ -1,186 +0,0 @@ ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: manager-role -rules: - ## - ## Base operator rules - ## - - apiGroups: - - "" - resources: - - secrets - - pods - - pods/exec - - pods/log - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - inventorytests - - inventorytests/status - - inventorytests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - subresourcestests - - subresourcestests/status - - subresourcestests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - collectiontests - - collectiontests/status - - collectiontests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - selectortests - - selectortests/status - - selectortests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - casetests - - casetests/status - - casetests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - argstests - - argstests/status - - argstests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Rules for test.example.com/v1alpha1, Kind: InventoryTest - ## - - apiGroups: - - test.example.com - resources: - - reconciliationtests - - reconciliationtests/status - - reconciliationtests/finalizers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - ## - ## Base operator rules - ## - - apiGroups: - - "" - resources: - - configmaps - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - apps - resources: - - configmaps - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -# +kubebuilder:scaffold:rules diff --git a/test/ansible/config/rbac/role_binding.yaml b/test/ansible/config/rbac/role_binding.yaml deleted file mode 100644 index 98f87829e9..0000000000 --- a/test/ansible/config/rbac/role_binding.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: manager-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: manager-role -subjects: -- kind: ServiceAccount - name: default - namespace: system diff --git a/test/ansible/config/samples/kustomization.yaml b/test/ansible/config/samples/kustomization.yaml deleted file mode 100644 index e353c59b27..0000000000 --- a/test/ansible/config/samples/kustomization.yaml +++ /dev/null @@ -1,3 +0,0 @@ -## Append samples you want in your CSV to this file as resources ## -resources: -- test_v1alpha1_inventorytest.yaml diff --git a/test/ansible/config/samples/test_v1alpha1_inventorytest.yaml b/test/ansible/config/samples/test_v1alpha1_inventorytest.yaml deleted file mode 100644 index 2792063349..0000000000 --- a/test/ansible/config/samples/test_v1alpha1_inventorytest.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: test.example.com/v1alpha1 -kind: InventoryTest -metadata: - name: inventorytest-sample - annotations: - "ansible.sdk.operatorframework.io/verbosity": "0" -spec: - size: 3 diff --git a/test/ansible/config/testing/debug_logs_patch.yaml b/test/ansible/config/testing/debug_logs_patch.yaml deleted file mode 100644 index 3e31e2fba1..0000000000 --- a/test/ansible/config/testing/debug_logs_patch.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - env: - - name: ANSIBLE_DEBUG_LOGS - value: "TRUE" diff --git a/test/ansible/config/testing/kustomization.yaml b/test/ansible/config/testing/kustomization.yaml deleted file mode 100644 index 9757d27f74..0000000000 --- a/test/ansible/config/testing/kustomization.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# Adds namespace to all resources. -namespace: osdk-test - -namePrefix: osdk- - -# Labels to add to all resources and selectors. -#commonLabels: -# someName: someValue - -patchesStrategicMerge: -- manager_image.yaml -- pull_policy/Never.yaml -- debug_logs_patch.yaml -- ../default/manager_auth_proxy_patch.yaml - -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: -- ../crd -- ../rbac -- ../manager -images: -- name: testing - newName: testing-operator diff --git a/test/ansible/config/testing/manager_image.yaml b/test/ansible/config/testing/manager_image.yaml deleted file mode 100644 index e44f542d9b..0000000000 --- a/test/ansible/config/testing/manager_image.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - image: testing diff --git a/test/ansible/config/testing/pull_policy/Always.yaml b/test/ansible/config/testing/pull_policy/Always.yaml deleted file mode 100644 index 6b0a8e2a8a..0000000000 --- a/test/ansible/config/testing/pull_policy/Always.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - imagePullPolicy: Always diff --git a/test/ansible/config/testing/pull_policy/IfNotPresent.yaml b/test/ansible/config/testing/pull_policy/IfNotPresent.yaml deleted file mode 100644 index 2f52f496cd..0000000000 --- a/test/ansible/config/testing/pull_policy/IfNotPresent.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - imagePullPolicy: IfNotPresent diff --git a/test/ansible/config/testing/pull_policy/Never.yaml b/test/ansible/config/testing/pull_policy/Never.yaml deleted file mode 100644 index 86f13d8164..0000000000 --- a/test/ansible/config/testing/pull_policy/Never.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - imagePullPolicy: Never diff --git a/test/ansible/molecule/default/converge.yml b/test/ansible/molecule/default/converge.yml deleted file mode 100644 index 0633db9849..0000000000 --- a/test/ansible/molecule/default/converge.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Converge - hosts: localhost - connection: local - gather_facts: no - collections: - - community.kubernetes - - tasks: - - name: Create Namespace - k8s: - api_version: v1 - kind: Namespace - name: '{{ namespace }}' - - - import_tasks: kustomize.yml - vars: - state: present diff --git a/test/ansible/molecule/default/create.yml b/test/ansible/molecule/default/create.yml deleted file mode 100644 index 1eeaf9226e..0000000000 --- a/test/ansible/molecule/default/create.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Create - hosts: localhost - connection: local - gather_facts: false - tasks: [] diff --git a/test/ansible/molecule/default/destroy.yml b/test/ansible/molecule/default/destroy.yml deleted file mode 100644 index af55e4f174..0000000000 --- a/test/ansible/molecule/default/destroy.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: Destroy - hosts: localhost - connection: local - gather_facts: false - collections: - - community.kubernetes - - tasks: - - import_tasks: kustomize.yml - vars: - state: absent - - - name: Destroy Namespace - k8s: - api_version: v1 - kind: Namespace - name: '{{ namespace }}' - state: absent - - - name: Unset pull policy - command: '{{ kustomize }} edit remove patch pull_policy/{{ operator_pull_policy }}.yaml' - args: - chdir: '{{ config_dir }}/testing' diff --git a/test/ansible/molecule/default/kustomize.yml b/test/ansible/molecule/default/kustomize.yml deleted file mode 100644 index f3d888c2f3..0000000000 --- a/test/ansible/molecule/default/kustomize.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: Build kustomize testing overlay - # load_restrictor must be set to none so we can load patch files from the default overlay - command: '{{ kustomize }} build --load_restrictor none .' - args: - chdir: '{{ config_dir }}/testing' - register: resources - changed_when: false - -- name: Set resources to {{ state }} - k8s: - definition: '{{ item }}' - state: '{{ state }}' - wait: yes - loop: '{{ resources.stdout | from_yaml_all | list }}' diff --git a/test/ansible/molecule/default/molecule.yml b/test/ansible/molecule/default/molecule.yml deleted file mode 100644 index ea58004dce..0000000000 --- a/test/ansible/molecule/default/molecule.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -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 }}' - config_dir: ${MOLECULE_PROJECT_DIRECTORY}/config - samples_dir: ${MOLECULE_PROJECT_DIRECTORY}/config/samples - operator_image: ${OPERATOR_IMAGE:-""} - operator_pull_policy: ${OPERATOR_PULL_POLICY:-"Always"} - kustomize: ${KUSTOMIZE_PATH:-kustomize} - env: - K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"} -verifier: - name: ansible - lint: | - set -e - ansible-lint diff --git a/test/ansible/molecule/default/prepare.yml b/test/ansible/molecule/default/prepare.yml deleted file mode 100644 index 7d9f3f1b76..0000000000 --- a/test/ansible/molecule/default/prepare.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -- name: Prepare - hosts: localhost - connection: local - gather_facts: false - - tasks: - - name: Ensure operator image is set - fail: - msg: | - You must specify the OPERATOR_IMAGE environment variable in order to run the - 'default' scenario - when: not operator_image - - - name: Set testing image - command: '{{ kustomize }} edit set image testing={{ operator_image }}' - args: - chdir: '{{ config_dir }}/testing' - - - name: Set pull policy - command: '{{ kustomize }} edit add patch pull_policy/{{ operator_pull_policy }}.yaml' - args: - chdir: '{{ config_dir }}/testing' - - - name: Set testing namespace - command: '{{ kustomize }} edit set namespace {{ namespace }}' - args: - chdir: '{{ config_dir }}/testing' diff --git a/test/ansible/molecule/default/verify.yml b/test/ansible/molecule/default/verify.yml deleted file mode 100644 index 8670d557a1..0000000000 --- a/test/ansible/molecule/default/verify.yml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- name: Verify - hosts: localhost - connection: local - gather_facts: no - collections: - - community.kubernetes - - vars: - ctrl_label: control-plane=controller-manager - - tasks: - - block: - - name: Import all test files from tasks/ - include_tasks: '{{ item }}' - with_fileglob: - - tasks/*_test.yml - rescue: - - name: Retrieve relevant resources - k8s_info: - api_version: '{{ item.api_version }}' - kind: '{{ item.kind }}' - namespace: '{{ namespace }}' - loop: - - api_version: v1 - kind: Pod - - api_version: apps/v1 - kind: Deployment - - api_version: v1 - kind: Secret - - api_version: v1 - kind: ConfigMap - register: debug_resources - - - name: Retrieve Pod logs - k8s_log: - name: '{{ item.metadata.name }}' - namespace: '{{ namespace }}' - container: manager - loop: "{{ q('k8s', api_version='v1', kind='Pod', namespace=namespace, label_selector=ctrl_label) }}" - register: debug_logs - - - name: Output gathered resources - debug: - var: debug_resources - - - name: Output gathered logs - debug: - var: item.log_lines - loop: '{{ debug_logs.results }}' - - - name: Re-emit failure - vars: - failed_task: - name: '{{ ansible_failed_task.name }}' - result: '{{ ansible_failed_result }}' - fail: - msg: '{{ failed_task }}' diff --git a/test/ansible/molecule/kind/converge.yml b/test/ansible/molecule/kind/converge.yml deleted file mode 100644 index dbd27374a5..0000000000 --- a/test/ansible/molecule/kind/converge.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- name: Converge - hosts: localhost - connection: local - gather_facts: no - - tasks: - - name: Build Ansible dev base image - make: - chdir: '{{ project_dir }}/../../' - target: image-build-ansible - # Not important, but maybe should fix someday - changed_when: false - - - name: Build operator image - docker_image: - build: - path: '{{ project_dir }}' - pull: no - name: '{{ operator_image }}' - tag: latest - push: no - source: build - force_source: yes - - - name: Load image into kind cluster - command: kind load docker-image --name osdk-test '{{ operator_image }}' - register: result - changed_when: '"not yet present" in result.stdout' - -- import_playbook: ../default/converge.yml diff --git a/test/ansible/molecule/kind/create.yml b/test/ansible/molecule/kind/create.yml deleted file mode 100644 index 66a84a14f7..0000000000 --- a/test/ansible/molecule/kind/create.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Create - hosts: localhost - connection: local - gather_facts: false - tasks: - - name: Create test kind cluster - command: kind create cluster --name osdk-test --kubeconfig {{ kubeconfig }} diff --git a/test/ansible/molecule/kind/destroy.yml b/test/ansible/molecule/kind/destroy.yml deleted file mode 100644 index 77b75a1d57..0000000000 --- a/test/ansible/molecule/kind/destroy.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Destroy - hosts: localhost - connection: local - gather_facts: false - collections: - - community.kubernetes - - tasks: - - name: Destroy test kind cluster - command: kind delete cluster --name osdk-test --kubeconfig {{ kubeconfig }} - diff --git a/test/ansible/molecule/kind/molecule.yml b/test/ansible/molecule/kind/molecule.yml deleted file mode 100644 index d4361f32fc..0000000000 --- a/test/ansible/molecule/kind/molecule.yml +++ /dev/null @@ -1,42 +0,0 @@ ---- -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 - playbooks: - prepare: ../default/prepare.yml - verify: ../default/verify.yml - lint: | - set -e - ansible-lint - inventory: - group_vars: - all: - namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - host_vars: - localhost: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - config_dir: ${MOLECULE_PROJECT_DIRECTORY}/config - samples_dir: ${MOLECULE_PROJECT_DIRECTORY}/config/samples - project_dir: ${MOLECULE_PROJECT_DIRECTORY} - operator_image: testing-operator - operator_pull_policy: "Never" - kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" - kustomize: ${KUSTOMIZE_PATH:-kustomize} - env: - K8S_AUTH_KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig -verifier: - name: ansible - lint: | - set -e - ansible-lint diff --git a/test/ansible/playbooks/argstest.yml b/test/ansible/playbooks/argstest.yml deleted file mode 100644 index c7a6670d12..0000000000 --- a/test/ansible/playbooks/argstest.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - tasks: - - name: Get the decrypted message variable - include_vars: - file: /opt/ansible/vars.yml - name: the_secret - - name: Create configmap - k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: '{{ meta.name }}' - namespace: '{{ meta.namespace }}' - data: - msg: The decrypted value is {{the_secret.the_secret}} diff --git a/test/ansible/playbooks/casetest.yml b/test/ansible/playbooks/casetest.yml deleted file mode 100644 index 083416793a..0000000000 --- a/test/ansible/playbooks/casetest.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - tasks: - - name: Create configmap - k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: '{{ meta.name }}' - namespace: '{{ meta.namespace }}' - data: - shouldBeCamel: '{{ camelCaseVar | default("false") }}' - diff --git a/test/ansible/playbooks/inventorytest.yml b/test/ansible/playbooks/inventorytest.yml deleted file mode 100644 index 3f57edac2d..0000000000 --- a/test/ansible/playbooks/inventorytest.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: test - gather_facts: no - tasks: - - import_role: - name: "inventorytest" - -- hosts: localhost - gather_facts: no - tasks: - - command: echo hello - - debug: msg='{{ "hello" | test }}' diff --git a/test/ansible/playbooks/reconciliationtest.yml b/test/ansible/playbooks/reconciliationtest.yml deleted file mode 100644 index 9045f4441b..0000000000 --- a/test/ansible/playbooks/reconciliationtest.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - tasks: - - name: retrieve configmap - k8s_info: - api_version: v1 - kind: ConfigMap - namespace: '{{ meta.namespace }}' - name: '{{ meta.name }}' - register: configmap - - - name: create configmap - k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: '{{ meta.name }}' - namespace: '{{ meta.namespace }}' - data: - iterations: '1' - when: configmap.resources|length == 0 - - - name: Update ConfigMap - k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: '{{ meta.name }}' - namespace: '{{ meta.namespace }}' - data: - iterations: '{{ (configmap.resources.0.data.iterations|int) + 1 }}' - when: configmap.resources|length > 0 and (configmap.resources.0.data.iterations|int) < 5 - - - name: retrieve configmap - k8s_info: - api_version: v1 - kind: ConfigMap - namespace: '{{ meta.namespace }}' - name: '{{ meta.name }}' - register: configmap - - - name: Using the requeue_after module - operator_sdk.util.requeue_after: - time: 1s - when: configmap.resources|length > 0 and (configmap.resources.0.data.iterations|int) < 5 diff --git a/test/ansible/playbooks/selectortest.yml b/test/ansible/playbooks/selectortest.yml deleted file mode 100644 index 0016b497b4..0000000000 --- a/test/ansible/playbooks/selectortest.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - tasks: - - name: Create configmap - k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: '{{ meta.name }}' - namespace: '{{ meta.namespace }}' - data: - hello: "world" diff --git a/test/ansible/playbooks/subresourcestest.yml b/test/ansible/playbooks/subresourcestest.yml deleted file mode 100644 index c5702951c7..0000000000 --- a/test/ansible/playbooks/subresourcestest.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - - operator_sdk.util - - tasks: - - name: Deploy busybox pod - k8s: - definition: - apiVersion: v1 - kind: Pod - metadata: - name: '{{ meta.name }}-busybox' - namespace: '{{ meta.namespace }}' - spec: - containers: - - image: busybox - name: sleep - args: - - "/bin/sh" - - "-c" - - "while true ; do echo '{{ log_message }}' ; sleep 5 ; done" - wait: yes - - - name: Execute command in busybox pod - k8s_exec: - namespace: '{{ meta.namespace }}' - pod: '{{ meta.name }}-busybox' - command: '{{ exec_command }}' - register: exec_result - - - debug: var=exec_result - - - name: Get logs from busybox pod - k8s_log: - name: '{{ meta.name }}-busybox' - namespace: '{{ meta.namespace }}' - register: log_result - - - name: Write results to resource status - k8s_status: - api_version: test.example.com/v1alpha1 - kind: SubresourcesTest - name: '{{ meta.name }}' - namespace: '{{ meta.namespace }}' - status: - execCommandStdout: '{{ exec_result.stdout.strip() }}' - execCommandStderr: '{{ exec_result.stderr.strip() }}' - logs: '{{ log_result.log }}' diff --git a/test/ansible/requirements.yml b/test/ansible/requirements.yml deleted file mode 100644 index 8a661f8b95..0000000000 --- a/test/ansible/requirements.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -collections: - - name: community.kubernetes - version: "<1.0.0" - - operator_sdk.util diff --git a/test/ansible/roles/inventorytest/tasks/main.yml b/test/ansible/roles/inventorytest/tasks/main.yml deleted file mode 100644 index a6ab21d46c..0000000000 --- a/test/ansible/roles/inventorytest/tasks/main.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- when: sentinel | test - block: - - community.kubernetes.k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: inventory-cm - namespace: '{{ meta.namespace }}' - data: - sentinel: '{{ sentinel }}' - groups: '{{ groups | to_nice_yaml }}' From 4d5b8839067a7f26155002fdd88f8fb7698becbe Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Fri, 18 Dec 2020 17:43:34 +0000 Subject: [PATCH 2/3] latest layout fmt --- .../internal/ansible/advanced_molecule.go | 335 ++++++++++-------- 1 file changed, 183 insertions(+), 152 deletions(-) diff --git a/hack/generate/samples/internal/ansible/advanced_molecule.go b/hack/generate/samples/internal/ansible/advanced_molecule.go index db18728f86..28aee6e761 100644 --- a/hack/generate/samples/internal/ansible/advanced_molecule.go +++ b/hack/generate/samples/internal/ansible/advanced_molecule.go @@ -76,17 +76,37 @@ func (ma *AdvancedMolecule) Run() { inventoryRoleTask := filepath.Join(ma.ctx.Dir, "roles", "inventorytest", "tasks", "main.yml") log.Infof("inserting code to inventory role task") - err = testutils.ReplaceInFile(inventoryRoleTask, "# tasks file for InventoryTest", inventoryRoleTaskFragment) + const inventoryRoleTaskFragment = ` +- when: sentinel | test + block: + - community.kubernetes.k8s: + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: inventory-cm + namespace: '{{ meta.namespace }}' + data: + sentinel: '{{ sentinel }}' + groups: '{{ groups | to_nice_yaml }}'` + err = testutils.ReplaceInFile( + inventoryRoleTask, + "# tasks file for InventoryTest", + inventoryRoleTaskFragment) pkg.CheckError("replacing inventory task", err) log.Infof("updating inventorytest sample") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"), - "name: inventorytest-sample", "name: inventorytest-sample\n annotations:\n \"ansible.sdk.operatorframework.io/verbosity\": \"0\"") + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"), + "name: inventorytest-sample", + inventorysampleFragment) pkg.CheckError("updating inventorytest sample", err) log.Infof("updating spec of inventorytest sample") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"), - "foo: bar", "size: 3") + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"), + "foo: bar", + "size: 3") pkg.CheckError("updating spec of inventorytest sample", err) ma.addPlaybooks() @@ -98,30 +118,75 @@ func (ma *AdvancedMolecule) Run() { func (ma *AdvancedMolecule) updateConfig() { log.Infof("adding customized roles") - err := testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "rbac", "role.yaml"), - "# +kubebuilder:scaffold:rules", cmRolesFragment) + const cmRolesFragment = ` ## + ## Base operator rules + ## + - apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - apps + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +# +kubebuilder:scaffold:rules` + err := testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "config", "rbac", "role.yaml"), + "# +kubebuilder:scaffold:rules", + cmRolesFragment) pkg.CheckError("adding customized roles", err) log.Infof("adding manager arg") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"), - "args:\n - \"--enable-leader-election\"\n - \"--leader-election-id=advanced-molecule-operator\"", - "args:\n - \"--metrics-addr=127.0.0.1:8080\"\n - \"--enable-leader-election\"\n - \"--leader-election-id=advanced-molecule-operator\"\n - \"--ansible-args='--vault-password-file /opt/ansible/pwd.yml'\"") + const ansibleVaultArg = ` + - "--ansible-args='--vault-password-file /opt/ansible/pwd.yml'"` + err = kbtestutils.InsertCode( + filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"), + "- \"--leader-election-id=advanced-molecule-operator\"", + ansibleVaultArg) pkg.CheckError("adding manager arg", err) log.Infof("adding manager env") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"), - "- name: ANSIBLE_GATHERING\n value: explicit", managerEnv) + const managerEnv = ` + - name: ANSIBLE_DEBUG_LOGS + value: "TRUE" + - name: ANSIBLE_INVENTORY + value: /opt/ansible/inventory` + err = kbtestutils.InsertCode( + filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"), + "value: explicit", + managerEnv) pkg.CheckError("adding manager env", err) log.Infof("adding vaulting args to the proxy auth") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "default", "manager_auth_proxy_patch.yaml"), - "- \"--leader-election-id=advanced-molecule-operator\"", - "- \"--leader-election-id=advanced-molecule-operator\"\n - \"--ansible-args='--vault-password-file /opt/ansible/pwd.yml'\"") + const managerAuthArgs = ` + - "--ansible-args='--vault-password-file /opt/ansible/pwd.yml'"` + err = kbtestutils.InsertCode( + filepath.Join(ma.ctx.Dir, "config", "default", "manager_auth_proxy_patch.yaml"), + "- \"--enable-leader-election\"", + managerAuthArgs) pkg.CheckError("adding vaulting args to the proxy auth", err) log.Infof("adding task to not pull image to the config/testing") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "testing", "kustomization.yaml"), - "- manager_image.yaml", "- manager_image.yaml\n- pull_policy/Never.yaml") + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "config", "testing", "kustomization.yaml"), + "- manager_image.yaml", + "- manager_image.yaml\n- pull_policy/Never.yaml") pkg.CheckError("adding task to not pull image to the config/testing", err) } @@ -164,124 +229,14 @@ func (ma *AdvancedMolecule) addMocksFromTestdata() { func (ma *AdvancedMolecule) updateDockerfile() { log.Infof("replacing project Dockerfile to use ansible base image with the dev tag") - err := testutils.ReplaceRegexInFile(filepath.Join(ma.ctx.Dir, "Dockerfile"), "quay.io/operator-framework/ansible-operator:.*", "quay.io/operator-framework/ansible-operator:dev") + err := testutils.ReplaceRegexInFile( + filepath.Join(ma.ctx.Dir, "Dockerfile"), + "quay.io/operator-framework/ansible-operator:.*", + "quay.io/operator-framework/ansible-operator:dev") pkg.CheckError("replacing Dockerfile", err) log.Infof("inserting code to Dockerfile") - err = kbtestutils.InsertCode(filepath.Join(ma.ctx.Dir, "Dockerfile"), "COPY playbooks/ ${HOME}/playbooks/", dockerfileFragment) - pkg.CheckError("replacing Dockerfile", err) -} - -func (ma *AdvancedMolecule) updatePlaybooks() { - log.Infof("adding playbook for argstest") - err := testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "argstest.yml"), - originalPlaybookFragment, argsPlaybook) - pkg.CheckError("adding playbook for argstest", err) - - log.Infof("adding playbook for casetest") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "casetest.yml"), - originalPlaybookFragment, casePlaybook) - pkg.CheckError("adding playbook for casetest", err) - - log.Infof("adding playbook for inventorytest") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "inventorytest.yml"), - "---\n- hosts: localhost\n gather_facts: no\n collections:\n - community.kubernetes\n - operator_sdk.util\n tasks:\n - import_role:\n name: \"inventorytest\"", - inventoryPlaybook) - pkg.CheckError("adding playbook for inventorytest", err) - - log.Infof("adding playbook for reconciliationtest") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "reconciliationtest.yml"), - originalPlaybookFragment, reconciliationPlaybook) - pkg.CheckError("adding playbook for reconciliationtest", err) - - log.Infof("adding playbook for selectortest") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "selectortest.yml"), - originalPlaybookFragment, selectorPlaybook) - pkg.CheckError("adding playbook for selectortest", err) - - log.Infof("adding playbook for subresourcestest") - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "playbooks", "subresourcestest.yml"), - originalPlaybookFragment, subresourcesPlaybook) - pkg.CheckError("adding playbook for subresourcestest", err) -} - -func (ma *AdvancedMolecule) addPlaybooks() { - allPlaybookKinds := []string{ - "ArgsTest", - "CaseTest", - "CollectionTest", - "ReconciliationTest", - "SelectorTest", - "SubresourcesTest", - } - - // Crate API - for _, k := range allPlaybookKinds { - logMsgForKind := fmt.Sprintf("creating an API %s", k) - log.Infof(logMsgForKind) - err := ma.ctx.CreateAPI( - "--group", ma.ctx.Group, - "--version", ma.ctx.Version, - "--kind", k, - "--generate-playbook") - pkg.CheckError(logMsgForKind, err) - - k = strings.ToLower(k) - task := fmt.Sprintf("%s_test.yml", k) - logMsgForKind = fmt.Sprintf("removing FIXME assert from %s", task) - log.Infof(logMsgForKind) - err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", task), - fixmeAssert, "") - pkg.CheckError(logMsgForKind, err) - } -} - -const managerEnv = `- name: ANSIBLE_DEBUG_LOGS - value: "TRUE" - - name: ANSIBLE_GATHERING - value: explicit - - name: ANSIBLE_INVENTORY - value: /opt/ansible/inventory` - -const cmRolesFragment = ` ## - ## Base operator rules - ## - - apiGroups: - - "" - resources: - - configmaps - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - apps - resources: - - configmaps - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -# +kubebuilder:scaffold:rules` - -const originalPlaybookFragment = `--- -- hosts: localhost - gather_facts: no - collections: - - community.kubernetes - - operator_sdk.util - tasks: [] -` - -const dockerfileFragment = ` + const dockerfileFragment = ` # Customizations done to check advanced scenarios COPY inventory/ ${HOME}/inventory/ @@ -296,22 +251,16 @@ RUN ansible-galaxy collection build /tmp/fixture_collection/ --output-path /tmp/ RUN echo abc123 > /opt/ansible/pwd.yml \ && ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml ` + err = kbtestutils.InsertCode( + filepath.Join(ma.ctx.Dir, "Dockerfile"), + "COPY playbooks/ ${HOME}/playbooks/", + dockerfileFragment) + pkg.CheckError("replacing Dockerfile", err) +} -const inventoryRoleTaskFragment = ` -- when: sentinel | test - block: - - community.kubernetes.k8s: - definition: - apiVersion: v1 - kind: ConfigMap - metadata: - name: inventory-cm - namespace: '{{ meta.namespace }}' - data: - sentinel: '{{ sentinel }}' - groups: '{{ groups | to_nice_yaml }}'` - -const argsPlaybook = `--- +func (ma *AdvancedMolecule) updatePlaybooks() { + log.Infof("adding playbook for argstest") + const argsPlaybook = `--- - hosts: localhost gather_facts: no collections: @@ -332,8 +281,14 @@ const argsPlaybook = `--- data: msg: The decrypted value is {{the_secret.the_secret}} ` + err := testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "playbooks", "argstest.yml"), + originalPlaybookFragment, + argsPlaybook) + pkg.CheckError("adding playbook for argstest", err) -const casePlaybook = `--- + log.Infof("adding playbook for casetest") + const casePlaybook = `--- - hosts: localhost gather_facts: no collections: @@ -350,8 +305,14 @@ const casePlaybook = `--- data: shouldBeCamel: '{{ camelCaseVar | default("false") }}' ` + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "playbooks", "casetest.yml"), + originalPlaybookFragment, + casePlaybook) + pkg.CheckError("adding playbook for casetest", err) -const inventoryPlaybook = `--- + log.Infof("adding playbook for inventorytest") + const inventoryPlaybook = `--- - hosts: test gather_facts: no tasks: @@ -363,8 +324,14 @@ const inventoryPlaybook = `--- tasks: - command: echo hello - debug: msg='{{ "hello" | test }}'` + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "playbooks", "inventorytest.yml"), + "---\n- hosts: localhost\n gather_facts: no\n collections:\n - community.kubernetes\n - operator_sdk.util\n tasks:\n - import_role:\n name: \"inventorytest\"", + inventoryPlaybook) + pkg.CheckError("adding playbook for inventorytest", err) -const reconciliationPlaybook = `--- + log.Infof("adding playbook for reconciliationtest") + const reconciliationPlaybook = `--- - hosts: localhost gather_facts: no collections: @@ -415,8 +382,14 @@ const reconciliationPlaybook = `--- time: 1s when: configmap.resources|length > 0 and (configmap.resources.0.data.iterations|int) < 5 ` + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "playbooks", "reconciliationtest.yml"), + originalPlaybookFragment, + reconciliationPlaybook) + pkg.CheckError("adding playbook for reconciliationtest", err) -const selectorPlaybook = `--- + log.Infof("adding playbook for selectortest") + const selectorPlaybook = `--- - hosts: localhost gather_facts: no collections: @@ -433,8 +406,14 @@ const selectorPlaybook = `--- data: hello: "world" ` + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "playbooks", "selectortest.yml"), + originalPlaybookFragment, + selectorPlaybook) + pkg.CheckError("adding playbook for selectortest", err) -const subresourcesPlaybook = `--- + log.Infof("adding playbook for subresourcestest") + const subresourcesPlaybook = `--- - hosts: localhost gather_facts: no collections: @@ -486,6 +465,58 @@ const subresourcesPlaybook = `--- execCommandStderr: '{{ exec_result.stderr.strip() }}' logs: '{{ log_result.log }}' ` + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "playbooks", "subresourcestest.yml"), + originalPlaybookFragment, + subresourcesPlaybook) + pkg.CheckError("adding playbook for subresourcestest", err) +} + +func (ma *AdvancedMolecule) addPlaybooks() { + allPlaybookKinds := []string{ + "ArgsTest", + "CaseTest", + "CollectionTest", + "ReconciliationTest", + "SelectorTest", + "SubresourcesTest", + } + + // Crate API + for _, k := range allPlaybookKinds { + logMsgForKind := fmt.Sprintf("creating an API %s", k) + log.Infof(logMsgForKind) + err := ma.ctx.CreateAPI( + "--group", ma.ctx.Group, + "--version", ma.ctx.Version, + "--kind", k, + "--generate-playbook") + pkg.CheckError(logMsgForKind, err) + + k = strings.ToLower(k) + task := fmt.Sprintf("%s_test.yml", k) + logMsgForKind = fmt.Sprintf("removing FIXME assert from %s", task) + log.Infof(logMsgForKind) + err = testutils.ReplaceInFile( + filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", task), + fixmeAssert, + "") + pkg.CheckError(logMsgForKind, err) + } +} + +const originalPlaybookFragment = `--- +- hosts: localhost + gather_facts: no + collections: + - community.kubernetes + - operator_sdk.util + tasks: [] +` + +const inventorysampleFragment = `name: inventorytest-sample + annotations: + "ansible.sdk.operatorframework.io/verbosity": "0"` // GenerateMoleculeAnsibleSample will call all actions to create the directory and generate the sample // The Context to run the samples are not the same in the e2e test. In this way, note that it should NOT From 1cd915069f99b684386aabc8aa5febcbeb72967a Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Fri, 18 Dec 2020 18:33:12 +0000 Subject: [PATCH 3/3] fix typo austin review --- hack/generate/samples/internal/ansible/advanced_molecule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/generate/samples/internal/ansible/advanced_molecule.go b/hack/generate/samples/internal/ansible/advanced_molecule.go index 28aee6e761..e066339fa4 100644 --- a/hack/generate/samples/internal/ansible/advanced_molecule.go +++ b/hack/generate/samples/internal/ansible/advanced_molecule.go @@ -27,7 +27,7 @@ import ( "github.com/operator-framework/operator-sdk/internal/testutils" ) -// MoleculeAnsible defines the context for the sample +// AdvancedMolecule defines the context for the sample type AdvancedMolecule struct { ctx *pkg.SampleContext }