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

Gather just the necessary facts #5955

Merged
merged 2 commits into from
Apr 17, 2020
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
14 changes: 14 additions & 0 deletions cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
- { role: kubespray-defaults }
- { role: bootstrap-os, tags: bootstrap-os}

- name: Gather facts
import_playbook: facts.yml

- hosts: k8s-cluster:etcd
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -50,6 +54,7 @@
environment: "{{ proxy_env }}"

- hosts: etcd
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -61,6 +66,7 @@
when: not etcd_kubeadm_enabled| default(false)

- hosts: k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -72,13 +78,15 @@
when: not etcd_kubeadm_enabled| default(false)

- hosts: k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
- { role: kubernetes/node, tags: node }
environment: "{{ proxy_env }}"

- hosts: kube-master
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -87,6 +95,7 @@
- { role: kubernetes-apps/cluster_roles, tags: cluster-roles }

- hosts: k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -95,19 +104,22 @@
- { role: kubernetes/node-label, tags: node-label }

- hosts: calico-rr
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
- { role: network_plugin/calico/rr, tags: ['network', 'calico_rr'] }

- hosts: kube-master[0]
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
- { role: kubernetes-apps/rotate_tokens, tags: rotate_tokens, when: "secret_changed|default(false)" }
- { role: win_nodes/kubernetes_patch, tags: ["master", "win_nodes"] }

- hosts: kube-master
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -118,13 +130,15 @@
- { role: kubernetes-apps/external_provisioner, tags: external-provisioner }

- hosts: kube-master
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
- { role: kubernetes-apps, tags: apps }
environment: "{{ proxy_env }}"

- hosts: k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand Down
2 changes: 2 additions & 0 deletions docs/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This should be the easiest.

You can use `--limit=node1` to limit Kubespray to avoid disturbing other nodes in the cluster.

Before using `--limit` run playbook `facts.yml` without the limit to refresh facts cache for all nodes.

### 3) Drain the node that will be removed

```sh
Expand Down
19 changes: 19 additions & 0 deletions facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Gather facts
hosts: k8s-cluster:etcd:calico-rr
gather_facts: False
tasks:
- name: Gather minimal facts
setup:
gather_subset: '!all'

- name: Gather necessary facts
setup:
gather_subset: '!all,!min,network,hardware'
filter: "{{ item }}"
loop:
- ansible_distribution_major_version
- ansible_default_ipv4
- ansible_all_ipv4_addresses
- ansible_memtotal_mb
- ansible_swaptotal_mb
7 changes: 5 additions & 2 deletions remove-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
- { role: kubespray-defaults }
- { role: remove-node/pre-remove, tags: pre-remove }

- name: Gather facts
import_playbook: facts.yml

- hosts: "{{ node | default('kube-node') }}"
gather_facts: yes
gather_facts: no
roles:
- { role: kubespray-defaults }
- { role: reset, tags: reset, when: reset_nodes|default(True) }

# Currently cannot remove first master or etcd
- hosts: "{{ node | default('kube-master[1:]:etcd[:1]') }}"
gather_facts: yes
gather_facts: no
roles:
- { role: kubespray-defaults }
- { role: remove-node/post-remove, tags: post-remove }
5 changes: 3 additions & 2 deletions reset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
- { role: kubespray-defaults}
- { role: bastion-ssh-config, tags: ["localhost", "bastion"]}

- hosts: all
gather_facts: true
- name: Gather facts
import_playbook: facts.yml

- hosts: etcd:k8s-cluster:calico-rr
gather_facts: False
vars_prompt:
name: "reset_confirmation"
prompt: "Are you sure you want to reset cluster state? Type 'yes' to reset your cluster."
Expand Down
5 changes: 5 additions & 0 deletions scale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
- { role: kubespray-defaults }
- { role: bootstrap-os, tags: bootstrap-os}

- name: Gather facts
import_playbook: facts.yml

- name: Generate the etcd certificates beforehand
hosts: etcd
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -58,6 +62,7 @@

- name: Target only workers to get kubelet installed and checking in on any new nodes
hosts: kube-node
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand Down
15 changes: 15 additions & 0 deletions upgrade-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
- { role: kubespray-defaults }
- { role: bootstrap-os, tags: bootstrap-os}

- name: Gather facts
import_playbook: facts.yml

- name: Download images to ansible host cache via first kube-master node
hosts: kube-master[0]
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults, when: "not skip_downloads and download_run_once and not download_localhost"}
Expand All @@ -55,6 +59,7 @@

- name: Prepare nodes for upgrade
hosts: k8s-cluster:etcd:calico-rr
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -64,6 +69,7 @@

- name: Upgrade container engine on non-cluster nodes
hosts: etcd:calico-rr:!k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
serial: "{{ serial | default('20%') }}"
roles:
Expand All @@ -72,6 +78,7 @@
environment: "{{ proxy_env }}"

- hosts: etcd
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -83,6 +90,7 @@
when: not etcd_kubeadm_enabled | default(false)

- hosts: k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand All @@ -94,6 +102,7 @@
when: not etcd_kubeadm_enabled | default(false)

- name: Handle upgrades to master components first to maintain backwards compat.
gather_facts: False
hosts: kube-master
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
serial: 1
Expand All @@ -112,6 +121,7 @@

- name: Upgrade calico and external cloud provider on all masters and nodes
hosts: kube-master:kube-node
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
serial: "{{ serial | default('20%') }}"
roles:
Expand All @@ -123,6 +133,7 @@

- name: Finally handle worker upgrades, based on given batch size
hosts: kube-node:!kube-master
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
serial: "{{ serial | default('20%') }}"
roles:
Expand All @@ -136,27 +147,31 @@
environment: "{{ proxy_env }}"

- hosts: kube-master[0]
gather_facts: False
any_errors_fatal: true
roles:
- { role: kubespray-defaults }
- { role: kubernetes-apps/rotate_tokens, tags: rotate_tokens, when: "secret_changed|default(false)" }
- { role: win_nodes/kubernetes_patch, tags: ["master", "win_nodes"] }

- hosts: calico-rr
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
- { role: network_plugin/calico/rr, tags: network }
environment: "{{ proxy_env }}"

- hosts: kube-master
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
- { role: kubernetes-apps, tags: apps }
environment: "{{ proxy_env }}"

- hosts: k8s-cluster
gather_facts: False
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
roles:
- { role: kubespray-defaults }
Expand Down