diff --git a/ansible/add-on-roles/garbagecollection/README.md b/ansible/add-on-roles/garbagecollection/README.md new file mode 100644 index 00000000..c53e9ad1 --- /dev/null +++ b/ansible/add-on-roles/garbagecollection/README.md @@ -0,0 +1,12 @@ +# garbagecollection + +this add-on adds a KubeConfig Machineconfiguration as per https://cloud.redhat.com/blog/image-garbage-collection-in-openshift +This can be used to have a tighter garbagecollection for the images. This may be useful in environments with low disk volume + +## Role Variables + +see [defaults](defaults/main.yml) + +## License + +Apache 2.0 \ No newline at end of file diff --git a/ansible/add-on-roles/garbagecollection/defaults/main.yml b/ansible/add-on-roles/garbagecollection/defaults/main.yml new file mode 100644 index 00000000..4d997c51 --- /dev/null +++ b/ansible/add-on-roles/garbagecollection/defaults/main.yml @@ -0,0 +1,3 @@ +garbagecollection_high_treshold_percent: 66 +garbagecollection_low_treshold_percent: 50 +garbagecollection_minimum_age: "5m30s" diff --git a/ansible/add-on-roles/garbagecollection/meta/main.yml b/ansible/add-on-roles/garbagecollection/meta/main.yml new file mode 100644 index 00000000..6edfcb8c --- /dev/null +++ b/ansible/add-on-roles/garbagecollection/meta/main.yml @@ -0,0 +1,20 @@ +galaxy_info: + author: Steffen Luetzenkirchen + description: configures tight garbage collection for ocp4 + company: Red Hat + + license: Apache-2.0 + + min_ansible_version: 2.9 + + platforms: + - name: OpenShift + versions: + - all + galaxy_tags: + [] + +dependencies: + [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/ansible/add-on-roles/garbagecollection/tasks/post-install.yml b/ansible/add-on-roles/garbagecollection/tasks/post-install.yml new file mode 100644 index 00000000..d59e62ad --- /dev/null +++ b/ansible/add-on-roles/garbagecollection/tasks/post-install.yml @@ -0,0 +1,18 @@ +--- +- name: Ensure GarbageCollection machineconfig + delegate_to: localhost + kubernetes.core.k8s: + state: present + kubeconfig: "{{ k8s_kubeconfig }}" + host: "{{ k8s_host }}" + ca_cert: "{{ k8s_ca_cert }}" + client_cert: "{{ k8s_client_cert }}" + client_key: "{{ k8s_client_key }}" + definition: "{{ lookup('template', 'templates/cluster-garbagecollection-machineconfig.yml.j2') }}" + vars: + role: "{{ loop_role }}" + with_items: + - master + - worker + loop_control: + loop_var: loop_role diff --git a/ansible/add-on-roles/garbagecollection/templates/cluster-garbagecollection-machineconfig.yml.j2 b/ansible/add-on-roles/garbagecollection/templates/cluster-garbagecollection-machineconfig.yml.j2 new file mode 100644 index 00000000..fd2aa302 --- /dev/null +++ b/ansible/add-on-roles/garbagecollection/templates/cluster-garbagecollection-machineconfig.yml.j2 @@ -0,0 +1,14 @@ +apiVersion: machineconfiguration.openshift.io/v1 +kind: KubeletConfig +metadata: + labels: + machineconfiguration.openshift.io/role: {{ role }} + name: 60-{{ role }}-kubeconfig-tight-garbage +spec: + kubeletConfig: + imageGCHighThresholdPercent: {{ garbagecollection_high_treshold_percent }} + imageGCLowThresholdPercent: {{ garbagecollection_low_treshold_percent }} + imageMinimumGCAge: "{{ garbagecollection_minimum_age }} " + machineConfigPoolSelector: + matchLabels: + pools.operator.machineconfiguration.openshift.io/{{ role }}: "" \ No newline at end of file diff --git a/ansible/roles/openshift-4-cluster/tasks/create.yml b/ansible/roles/openshift-4-cluster/tasks/create.yml index 1a42ca86..7fad1354 100644 --- a/ansible/roles/openshift-4-cluster/tasks/create.yml +++ b/ansible/roles/openshift-4-cluster/tasks/create.yml @@ -137,4 +137,6 @@ - name: Include post installation tasks ansible.builtin.include_tasks: post-install.yml - tags: post-install + tags: + - post-install + - post-install-add-ons diff --git a/ansible/roles/openshift-4-cluster/tasks/post-install-add-ons.yml b/ansible/roles/openshift-4-cluster/tasks/post-install-add-ons.yml index 1919e03a..41d55429 100644 --- a/ansible/roles/openshift-4-cluster/tasks/post-install-add-ons.yml +++ b/ansible/roles/openshift-4-cluster/tasks/post-install-add-ons.yml @@ -1,13 +1,19 @@ --- - name: Include vars of stuff.yaml into the 'stuff' variable (2.2). ansible.builtin.include_vars: "{{ playbook_dir }}/../add-ons.yml" + tags: + - post-install + - post-install-add-ons - name: "Handle post_install_add_ons (include_role)" ansible.builtin.include_role: name: "{{ item.name }}" tasks_from: "{{ item.tasks_from | default('main.yml') }}" + apply: + tags: + - post-install + - post-install-add-ons tags: - post-install - - add-ons - post-install-add-ons with_items: "{{ post_install_add_ons | default ([]) }}"