Skip to content

Commit 6d91a84

Browse files
authored
Merge branch 'master' into linting
2 parents 8af0f0b + 6eeb7a6 commit 6d91a84

File tree

11 files changed

+94
-4
lines changed

11 files changed

+94
-4
lines changed

common/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# common
2+
3+
Contains common roles for deploying the metal-stack.
4+
5+
## Roles
6+
7+
| Role Name | Description |
8+
| ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
9+
| [defaults](roles/defaults) | Provides defaults both relevant for partition and control-plane, it also provides a release vector mapping for metal-roles |
10+
| [metal-deployment-token](roles/metal-deployment-token) | Creates an V2 admin token that can be used during the deployment to create API resources |
11+
| [metal-v2-client](roles/metal-v2-client) | Installs metal-stack-api |

common/roles/defaults/defaults/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ metal_stack_release:
1515
# control plane
1616
metal_api_image_tag: "docker-images.metal-stack.control-plane.metal-api.tag"
1717
metal_api_image_name: "docker-images.metal-stack.control-plane.metal-api.name"
18+
metal_api_version: "projects.metal-stack.api.version"
1819
metal_apiserver_image_tag: "docker-images.metal-stack.control-plane.metal-apiserver.tag"
1920
metal_apiserver_image_name: "docker-images.metal-stack.control-plane.metal-apiserver.name"
2021
metal_metalctl_image_tag: "docker-images.metal-stack.control-plane.metalctl.tag"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# metal-deployment-token
2+
3+
This role can be used to create a short-lives admin deployment token intended for deploying infra services. Typically these require a dedicated tenant and a specific api token. The token is created through the metal-apiserver CLI through Kubernetes pod exec. So, it is required to have a connection to the Kubernetes cluster where the metal-apiserver is running.
4+
5+
All tasks for this are run on the deployment machine (`localhost`). The token is then exported with the name `metal_deployment_admin_token` as an Ansible fact for the `localhost`.
6+
7+
If a connection to the control plane Kubernetes cluster is unwanted, another option for the deployment would be to create a long-lived token for the deployment and just set `metal_deployment_admin_token` in `host_vars` for `localhost`. Then this role can be quickly swapped in or out.
8+
9+
Please note that the created token has admin privileges by nature and expires fairly quickly. The created token is only intended to live during a CI deployment. It should not be stored on a target host.
10+
11+
## Requirements
12+
13+
- The metal-stack V2 API client needs to be installed (see [metal-v2-client role](../metal-v2-client/))
14+
15+
## Variables
16+
17+
You can look up all the default values of this role [here](defaults/main.yaml).
18+
19+
| Name | Mandatory | Description |
20+
| --------------------------------- | --------- | ----------------------------------- |
21+
| metal_deployment_token_admin_role | | The admin role to be created |
22+
| metal_deployment_token_expiration | | The expiration of the created token |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
metal_deployment_token_admin_role: ADMIN_ROLE_EDITOR
3+
metal_deployment_token_expiration: 1h
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
galaxy_info:
3+
role_name: metal-deployment-token
4+
author: metal-stack
5+
description: This role creates a deployment token and exports it in order to deploy infra services with it.
6+
license: MIT
7+
min_ansible_version: "2.18"
8+
galaxy_tags: []
9+
10+
platforms:
11+
- name: GenericLinux
12+
versions:
13+
- all
14+
15+
dependencies:
16+
- role: ansible-common
17+
- role: metal-roles/common/roles/defaults
18+
- role: metal-roles/control-plane/roles/defaults
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
- name: Create admin api token for the deployment
3+
block:
4+
5+
- name: Wait until the metal-apiserver is running
6+
kubernetes.core.k8s_info:
7+
kind: Deployment
8+
name: metal-apiserver
9+
namespace: "{{ metal_control_plane_namespace }}"
10+
wait: yes
11+
wait_sleep: 1
12+
wait_timeout: 60
13+
14+
- name: Get metal-apiserver pods
15+
set_fact:
16+
_metal_apiserver_pod: "{{ (lookup('k8s', api_version='v1', kind='Pod', namespace=metal_control_plane_namespace, label_selector='app=metal-apiserver') | list_wrap)[0].get('metadata', {}).get('name') }}"
17+
18+
- name: Generate deployment token
19+
no_log: true
20+
kubernetes.core.k8s_exec:
21+
namespace: "{{ metal_control_plane_namespace }}"
22+
pod: "{{ _metal_apiserver_pod }}"
23+
command: |
24+
/server token
25+
--description=ansible-ci-deployment
26+
--admin-role={{ metal_deployment_token_admin_role }}
27+
--expiration={{ metal_deployment_token_expiration }}
28+
register: _generated_token
29+
30+
- name: Set deployment token
31+
set_fact:
32+
metal_deployment_admin_token: "{{ _generated_token.stdout_lines[-1] }}"
33+
34+
delegate_to: localhost
35+
run_once: true
36+
when: metal_deployment_admin_token is not defined
File renamed without changes.
File renamed without changes.
File renamed without changes.

control-plane/roles/metal-v2-client/tasks/main.yaml renamed to common/roles/metal-v2-client/tasks/main.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
- name: Gather releases
3-
setup_yaml:
4-
52
- name: Install metal-stack-api
63
block:
4+
- name: Gather releases
5+
setup_yaml:
6+
77
- name: Install metal-stack-api client library {{ metal_api_version }}
88
pip:
99
name:

0 commit comments

Comments
 (0)