|
| 1 | +--- |
| 2 | + |
| 3 | +- name: Prepare |
| 4 | + hosts: k8s |
| 5 | + gather_facts: no |
| 6 | + vars: |
| 7 | + kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" |
| 8 | + tasks: |
| 9 | + - name: delete the kubeconfig if present |
| 10 | + file: |
| 11 | + path: '{{ kubeconfig }}' |
| 12 | + state: absent |
| 13 | + delegate_to: localhost |
| 14 | + |
| 15 | + - name: Fetch the kubeconfig |
| 16 | + fetch: |
| 17 | + dest: '{{ kubeconfig }}' |
| 18 | + flat: yes |
| 19 | + src: /root/.kube/config |
| 20 | + |
| 21 | + - name: Change the kubeconfig port to the proper value |
| 22 | + replace: |
| 23 | + regexp: 8443 |
| 24 | + replace: "{{ lookup('env', 'KIND_PORT') }}" |
| 25 | + path: '{{ kubeconfig }}' |
| 26 | + delegate_to: localhost |
| 27 | + |
| 28 | + - name: Wait for the Kubernetes API to become available (this could take a minute) |
| 29 | + uri: |
| 30 | + url: "https://localhost:8443/apis" |
| 31 | + status_code: 200 |
| 32 | + validate_certs: no |
| 33 | + register: result |
| 34 | + until: (result.status|default(-1)) == 200 |
| 35 | + retries: 60 |
| 36 | + delay: 5 |
| 37 | + |
| 38 | +- name: Prepare operator resources |
| 39 | + hosts: localhost |
| 40 | + connection: local |
| 41 | + vars: |
| 42 | + ansible_python_interpreter: '{{ ansible_playbook_python }}' |
| 43 | + deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy" |
| 44 | + tasks: |
| 45 | + - name: Ensure specified namespace is present |
| 46 | + k8s: |
| 47 | + api_version: v1 |
| 48 | + kind: Namespace |
| 49 | + name: '{{ namespace }}' |
| 50 | + |
| 51 | + - name: Create RBAC resources and Service |
| 52 | + k8s: |
| 53 | + namespace: '{{ namespace }}' |
| 54 | + definition: |
| 55 | + - apiVersion: v1 |
| 56 | + kind: ServiceAccount |
| 57 | + metadata: |
| 58 | + name: mc-router |
| 59 | + - apiVersion: rbac.authorization.k8s.io/v1 |
| 60 | + kind: ClusterRole |
| 61 | + metadata: |
| 62 | + name: services-watcher |
| 63 | + rules: |
| 64 | + - apiGroups: [""] |
| 65 | + resources: ["services"] |
| 66 | + verbs: ["watch","list"] |
| 67 | + - apiVersion: rbac.authorization.k8s.io/v1 |
| 68 | + kind: ClusterRoleBinding |
| 69 | + metadata: |
| 70 | + name: mc-router-services-watcher |
| 71 | + subjects: |
| 72 | + - kind: ServiceAccount |
| 73 | + name: mc-router |
| 74 | + namespace: '{{ namespace }}' |
| 75 | + roleRef: |
| 76 | + kind: ClusterRole |
| 77 | + name: services-watcher |
| 78 | + apiGroup: rbac.authorization.k8s.io |
| 79 | + - apiVersion: v1 |
| 80 | + kind: Service |
| 81 | + metadata: |
| 82 | + name: mc-router |
| 83 | + spec: |
| 84 | + type: NodePort |
| 85 | + ports: |
| 86 | + - targetPort: web |
| 87 | + name: web |
| 88 | + port: 8080 |
| 89 | + - targetPort: proxy |
| 90 | + name: proxy |
| 91 | + port: 25565 |
| 92 | + selector: |
| 93 | + run: mc-router |
0 commit comments