|
| 1 | +================= |
| 2 | +Kayobe Automation |
| 3 | +================= |
| 4 | + |
| 5 | +What is Kayobe Automation |
| 6 | +========================= |
| 7 | + |
| 8 | +`Kayobe automation <https://github.com/stackhpc/kayobe-automation/>`__ is a collection of scripts and tools that enable the automation of kayobe related operations through the use of CI/CD platforms such as those provided by GitHub and GitLab. |
| 9 | +Kayobe automation provides users an easy process of performing tasks such as; overcloud service deploy, config-diff, tempest testing and many more. |
| 10 | +With it being integrated into platforms such as GitHub or GitLab it builds a close relationship between the contents of the deployments kayobe configuration and what is currently deployed. |
| 11 | +This is because operations such as opening a pull request will trigger a config diff to be generated providing insight on what impact it might have on services or a tempest test that could be scheduled to run daily providing knowledge of faults earlier than before. |
| 12 | + |
| 13 | +Kayobe automation has been designed to be independent of any CI/CD platform with all tasks running inside of a purpose build Kayobe container. |
| 14 | +However, platform specific workflows need to be deployed to bridge the gap between the contents of Kayobe Automation and these CI/CD platforms. |
| 15 | +To achieve this work has been carried to template workflows as deployment specific choices have to be made when writing workflows, such as; multiple environment support, container registry location and secret sharing. |
| 16 | +The templating of workflows is offered through the `stackhpc.kayobe_workflows <https://github.com/stackhpc/ansible-collection-kayobe-workflows/>`__ collection which currently supports GitHub workflows and should enable the easy and error free deployment of workflows. |
| 17 | + |
| 18 | +GitHub Deployment |
| 19 | +================= |
| 20 | + |
| 21 | +To enable Kayobe Automation where GitHub Actions is used please follow the steps described below starting with the deployment the runners. |
| 22 | + |
| 23 | +Runner Deployment |
| 24 | +----------------- |
| 25 | + |
| 26 | +1. Identify a suitable host for hosting the runners. |
| 27 | + GitHub runners need to be deployed on a host which has not had Docker deployed using kolla. |
| 28 | + This is because GitHub runners cannot provide `network options when running in a container <https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontaineroptions>`__. |
| 29 | + |
| 30 | + Ideally an Infra VM could be used here or failing that the control host. |
| 31 | + Wherever it is deployed the host will need access to the :code:`admin_network`, :code:`public_network` and the :code:`pulp registry` on the seed. |
| 32 | + |
| 33 | +2. Edit the environments :code:`inventory/groups` to add the predefined :code:`github-runners` group to :code:`infra-vms` |
| 34 | + |
| 35 | +.. code-block:: ini |
| 36 | +
|
| 37 | + [infra-vms:children] |
| 38 | + github-runners |
| 39 | +
|
| 40 | +3. Edit the environments :code:`inventory/hosts` to define the host(s) that will host the runners. |
| 41 | + |
| 42 | +.. code-block:: ini |
| 43 | +
|
| 44 | + [github-runner] |
| 45 | + runner-01 |
| 46 | +
|
| 47 | +4. Provide all the relevant Kayobe :code:`group_vars` for :code:`github-runners` under :code:`inventory/hosts/github-runners` |
| 48 | + * `infra-vms` ensuring all required `infra_vm_extra_network_interface` are defined |
| 49 | + * `network-interfaces` |
| 50 | + * `python-interpreter.yml` ensuring that `ansible_python_interpreter: /usr/bin/python3` has been set |
| 51 | + |
| 52 | +5. Create `runner.yml` file which will contain the variables required to deploy a series of runners |
| 53 | + |
| 54 | +.. code-block:: yaml |
| 55 | +
|
| 56 | + --- |
| 57 | + runner_user: VM_USER_NAME_HERE |
| 58 | + github_account: ORG_NAME_HERE |
| 59 | + github_repo: KAYOBE_CONFIG_REPO_NAME_HERE |
| 60 | + access_token: "{{ secrets_github_access_token }}" |
| 61 | +
|
| 62 | + base_runner_dir: /opt/actions-runner |
| 63 | +
|
| 64 | + default_runner_labels: |
| 65 | + - kayobe |
| 66 | + - openstack |
| 67 | +
|
| 68 | + github_runners: |
| 69 | + runner_01: {} |
| 70 | + runner_02: {} |
| 71 | + runner_03: {} |
| 72 | +
|
| 73 | + docker_users: |
| 74 | + - "{{ runner_user }}" |
| 75 | +
|
| 76 | + pip_install_packages: |
| 77 | + - name: docker |
| 78 | +
|
| 79 | +If using multiple environments add an extra label to :code:`default_runner_labels` to distinguish these runners from runners belonging to other environments. |
| 80 | +Also feel free to change the number of runners and their names. |
| 81 | + |
| 82 | +6. Obtain a personal access token that would enable the registration of GitHub runners against the `github_account` and `github_repo` defined above. |
| 83 | + This token ideally should be `fine-grain personal access token <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token>`__ which may require the organisation to enable such tokens beforehand steps can be found `here <https://docs.github.com/en/organizations/managing-programmatic-access-to-your-organization/setting-a-personal-access-token-policy-for-your-organization>`__ |
| 84 | + The repository permissions for a fine-grain personal access token should be; :code:`Actions: R/W, Administration: R/W, Metadata: R` |
| 85 | + Once obtained the key add to :code:`secrets.yml` under :code:`secrets_github_access_token` |
| 86 | + |
| 87 | +7. Run :code:`kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/deploy-github-runner.yml` |
| 88 | + |
| 89 | +8. Check runners have registered properly by visiting the repositories :code:`Action` tab -> :code:`Runners` -> :code:`Self-hosted runners` |
| 90 | + |
| 91 | +9. Repeat the above steps for each environment you intend to deploy runners within. |
| 92 | + You can share the fine-grain access token between environments. |
| 93 | + |
| 94 | +Workflow Deployment |
| 95 | +------------------- |
| 96 | + |
| 97 | +1. Edit `inventory/group_vars/github-writer/writer.yml` in the base configuration making the appropriate changes to your deployments specific needs see documentation for `stackhpc.kayobe_workflows.github <https://github.com/stackhpc/ansible-collection-kayobe-workflows/tree/main/roles/github>`__ |
| 98 | + |
| 99 | +2. Run :code:`kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/write-workflows.yml` |
| 100 | + |
| 101 | +3. Add all required secrets to repository either via the GitHub UI or GitHub CLI (may require repository owner) |
| 102 | + * KAYOBE_AUTOMATION_SSH_PRIVATE_KEY |
| 103 | + * KAYOBE_VAULT_PASSWORD |
| 104 | + * REGISTRY_PASSWORD |
| 105 | + * TEMPEST_OPENRC |
| 106 | + |
| 107 | +Note if using multiple environments and are not sharing secrets between environments then each of must have the environment name prefix for each enviromment for example |
| 108 | + * PRODUCTION_KAYOBE_AUTOMATION_SSH_PRIVATE_KEY |
| 109 | + * PRODUCTION_KAYOBE_VAULT_PASSWORD |
| 110 | + * PRODUCTION_REGISTRY_PASSWORD |
| 111 | + * PRODUCTION_TEMPEST_OPENRC |
| 112 | + * STAGING_KAYOBE_AUTOMATION_SSH_PRIVATE_KEY |
| 113 | + * STAGING_KAYOBE_VAULT_PASSWORD |
| 114 | + * STAGING_REGISTRY_PASSWORD |
| 115 | + * STAGING_TEMPEST_OPENRC |
| 116 | + |
| 117 | +4. Commit and push all newly generated workflows found under :code:`.github/workflows` |
| 118 | + |
| 119 | +Final Steps |
| 120 | +----------- |
| 121 | + |
| 122 | +Some final steps include the following; running config-diff will require that :code:`.automation.conf/config.sh` contains a list :code:`KAYOBE_CONFIG_VAULTED_FILES_PATHS_EXTRA` of all vaulted files contained within the config. |
| 123 | +All such files can be found with :code:`grep -r "$ANSIBLE_VAULT;1.1;AES256" .` though make sure NOT to include `kolla/passwords.yml` and `secrets.yml` |
| 124 | +Also make sure tempest has been configured appropriately in :code:`.automation.conf/config.sh` to meet the limitations of a given deployment such as not using a too high of :code:`TEMPEST_CONCURRENCY` value and that overrides and load/skips lists are correct. |
| 125 | +Finally, once all the workflows and configuration has been pushed and reviewed you can build a kayobe image using `Build Kayobe Docker Image` once succesfully built and pushed to a container registry other workflows can be used. |
0 commit comments