Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/prevent unneeded installs #96

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions roles/cert-manager/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,73 @@
---
- name: Add cert-manager helm repo
kubernetes.core.helm_repository:
name: jetstack
repo_url: https://charts.jetstack.io
- name: Get cluster infos
kubernetes.core.k8s_cluster_info:
register: cluster_infos

# Installation des CRDs indépendamment du chart helm.
# Recommandé en production.
# Voir : https://cert-manager.io/docs/installation/helm
- name: Download cert-manager CRDs
ansible.builtin.uri:
url: https://github.com/cert-manager/cert-manager/releases/download/{{ dsc.certmanager.chartVersion }}/cert-manager.crds.yaml
return_content: true
register: cert_manager_crds

- name: Apply CRDs
kubernetes.core.k8s:
state: present
definition: "{{ cert_manager_crds.content | from_yaml_all }}"

- name: Set cert-manager helm values
- name: Check if cert-manager api exists
ansible.builtin.set_fact:
cm_values: {}
cm_api: "{{ cluster_infos.apis['cert-manager.io/v1'] | default('absent') }}"

- name: Check if cert-manager-webhook exists
kubernetes.core.k8s_info:
kind: MutatingWebhookConfiguration
name: cert-manager-webhook
register: cm_mwhc

- name: Merge with proxy settings
when: dsc.proxy.enabled
- name: Install cert-manager
when: (cm_api == 'absent') or (cm_mwhc.resources | length == 0)
block:
- name: Generate proxy values
ansible.builtin.set_fact:
cm_proxy_values: "{{ lookup('template', 'proxy-values.yaml.j2') | from_yaml }}"
- name: Merge with cm proxy values
- name: Add cert-manager helm repo
kubernetes.core.helm_repository:
name: jetstack
repo_url: https://charts.jetstack.io

# Installation des CRDs indépendamment du chart helm.
# Recommandé en production.
# Voir : https://cert-manager.io/docs/installation/helm
- name: Download cert-manager CRDs
ansible.builtin.uri:
url: https://github.com/cert-manager/cert-manager/releases/download/{{ dsc.certmanager.chartVersion }}/cert-manager.crds.yaml
return_content: true
register: cert_manager_crds

- name: Apply CRDs
kubernetes.core.k8s:
state: present
definition: "{{ cert_manager_crds.content | from_yaml_all }}"

- name: Set cert-manager helm values
ansible.builtin.set_fact:
cm_values: "{{ cm_values | combine(cm_proxy_values, recursive=True, list_merge='append') }}"
cm_values: {}

- name: Deploy helm
kubernetes.core.helm:
# force: true
name: cert-manager
chart_ref: jetstack/cert-manager
chart_version: "{{ dsc.certmanager.chartVersion }}"
release_namespace: cert-manager
create_namespace: true
values: "{{ cm_values }}"
- name: Merge with proxy settings
when: dsc.proxy.enabled
block:
- name: Generate proxy values
ansible.builtin.set_fact:
cm_proxy_values: "{{ lookup('template', 'proxy-values.yaml.j2') | from_yaml }}"
- name: Merge with cm proxy values
ansible.builtin.set_fact:
cm_values: "{{ cm_values | combine(cm_proxy_values, recursive=True, list_merge='append') }}"

- name: Wait cert-manager to initialize
kubernetes.core.k8s_info:
kind: Endpoints
namespace: cert-manager
name: cert-manager-webhook
register: endpoint
until: endpoint.resources[0].subsets[0].addresses[0] is defined
retries: 15
delay: 5
- name: Deploy helm
kubernetes.core.helm:
# force: true
name: cert-manager
chart_ref: jetstack/cert-manager
chart_version: "{{ dsc.certmanager.chartVersion }}"
release_namespace: cert-manager
create_namespace: true
values: "{{ cm_values }}"

- name: Wait cert-manager to initialize
kubernetes.core.k8s_info:
kind: Endpoints
namespace: cert-manager
name: cert-manager-webhook
register: endpoint
until: endpoint.resources[0].subsets[0].addresses[0] is defined
retries: 15
delay: 5

- name: Create Let's Encrypt ClusterIssuer
kubernetes.core.k8s:
Expand Down
2 changes: 1 addition & 1 deletion roles/cloudnativepg/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ansible.builtin.set_fact:
cnpg_api: "{{ cluster_infos.apis['postgresql.cnpg.io/v1'] | default('absent') }}"

- name: Chek if cnpg-mutating-webhook-configuration exists
- name: Check if cnpg-mutating-webhook-configuration exists
kubernetes.core.k8s_info:
kind: MutatingWebhookConfiguration
name: cnpg-mutating-webhook-configuration
Expand Down
32 changes: 21 additions & 11 deletions roles/confSyncer/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
---
- name: Add helm repo
kubernetes.core.helm_repository:
name: appscode
repo_url: https://charts.appscode.com/stable/
- name: Get existing kubed pods
kubernetes.core.k8s_info:
kind: Pod
label_selectors:
- "app.kubernetes.io/name=kubed"
register: kubed_pods

- name: Deploy helm
kubernetes.core.helm:
name: kubed
chart_ref: appscode/kubed
chart_version: "{{ dsc.kubed.chartVersion }}"
release_namespace: openshift-infra
create_namespace: true
- name: Install kubed
when: kubed_pods.resources | length == 0
block:
- name: Add helm repo
kubernetes.core.helm_repository:
name: appscode
repo_url: https://charts.appscode.com/stable/

- name: Deploy helm
kubernetes.core.helm:
name: kubed
chart_ref: appscode/kubed
chart_version: "{{ dsc.kubed.chartVersion }}"
release_namespace: openshift-infra
create_namespace: true