-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 55 additions & 32 deletions
87
...mmon/ansible/playbooks/roles/upgrade/tasks/kubernetes/update-kubeadm-image-repository.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,57 @@ | ||
--- | ||
# Note: Usage of the --config flag for reconfiguring the cluster during upgrade is not recommended since v1.16 | ||
- name: upgrade-master | Get value of imageRepository from kubeadm-config ConfigMap | ||
shell: kubeadm config view | ||
changed_when: false | ||
register: result | ||
|
||
- name: upgrade-master | Set current value of imageRepository as fact | ||
set_fact: | ||
kubeadm_image_repository: "{{ (result.stdout|from_yaml).imageRepository }}" | ||
|
||
- name: upgrade-master | Set new value for imageRepository as fact | ||
set_fact: | ||
new_kubeadm_image_repository: >- | ||
{%- if kubeadm_image_repository is search(':') -%} | ||
{{ kubeadm_image_repository | regex_replace('^(?P<host>.+):(?P<port>\d+)', image_registry_address) }} | ||
{%- else -%} | ||
{{ image_registry_address }}/{{ kubeadm_image_repository }} | ||
{%- endif -%} | ||
- name: upgrade-master | Patch imageRepository in kubeadm-config ConfigMap | ||
when: | ||
- kubeadm_image_repository != new_kubeadm_image_repository | ||
environment: | ||
KUBECONFIG: /home/{{ admin_user.name }}/.kube/config | ||
shell: |- | ||
set -o pipefail && | ||
# do not use --export option since it has been deprecated in 1.14 | ||
kubectl get cm kubeadm-config -n kube-system -o yaml | | ||
sed 's|imageRepository: {{ kubeadm_image_repository }}|imageRepository: {{ new_kubeadm_image_repository }}|g' | | ||
xargs --null -I config_map_content \ | ||
kubectl patch cm kubeadm-config -n kube-system --patch config_map_content | ||
args: | ||
executable: /bin/bash | ||
block: | ||
- name: upgrade-master | Get kubeadm-config configmap | ||
shell: | | ||
kubectl get configmap kubeadm-config \ | ||
--namespace kube-system \ | ||
--output yaml | ||
environment: | ||
KUBECONFIG: &KUBECONFIG /etc/kubernetes/admin.conf | ||
register: shell_kubeadm_configmap | ||
changed_when: false | ||
|
||
- name: upgrade-master | Patch kubeadm-config configmap (update-kubeadm-image-repository.yml) | ||
when: | ||
- _image_repository_updated != _image_repository # skip the task if nothing changed | ||
shell: | | ||
kubectl patch configmap kubeadm-config \ | ||
--namespace kube-system \ | ||
--patch "$KUBEADM_CONFIGMAP_DOCUMENT" | ||
environment: | ||
KUBECONFIG: *KUBECONFIG | ||
# Render an altered kubeadm-config configmap document | ||
KUBEADM_CONFIGMAP_DOCUMENT: >- | ||
{{ _document | combine(_update2, recursive=true) | to_nice_yaml(indent=2) }} | ||
vars: | ||
# Parse yaml payload | ||
_document: >- | ||
{{ shell_kubeadm_configmap.stdout | from_yaml }} | ||
# Extract cluster config | ||
_cluster_config: >- | ||
{{ _document.data.ClusterConfiguration | from_yaml }} | ||
_image_repository: >- | ||
{{ _cluster_config.imageRepository }} | ||
_image_repository_updated: >- | ||
{%- if _image_repository is search(':') -%} | ||
{{ _image_repository | regex_replace('^(?P<host>.+):(?P<port>\d+)', image_registry_address) }} | ||
{%- else -%} | ||
{{ image_registry_address }}/{{ _image_repository }} | ||
{%- endif -%} | ||
# Prepare the cluster config patch | ||
_update1: | ||
imageRepository: "{{ _image_repository_updated }}" | ||
|
||
_cluster_config_updated: >- | ||
{{ _cluster_config | combine(_update1, recursive=true) }} | ||
# Prepare the final update for the whole document | ||
_update2: | ||
data: | ||
ClusterConfiguration: >- | ||
{{ _cluster_config_updated | to_nice_yaml(indent=2) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters