Skip to content

Commit

Permalink
Added custom context name (#315)
Browse files Browse the repository at this point in the history
* Added custom context name

Signed-off-by: Vivek Sarin <[email protected]>
Signed-off-by: Derek Nola <[email protected]>
Co-authored-by: Vivek Sarin <[email protected]>
Co-authored-by: Derek Nola <[email protected]>
  • Loading branch information
3 people authored Apr 1, 2024
1 parent 6c14e5d commit c84c1ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions inventory-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ k3s_cluster:
extra_agent_args: ""

# Optional vars

Check warning on line 22 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[comments-indentation]

Comment not indented like content

Check warning on line 22 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

22:3 [comments-indentation] comment not indented like content
# cluster_context: k3s-ansible

Check warning on line 23 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[comments-indentation]

Comment not indented like content

Check warning on line 23 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

23:5 [comments-indentation] comment not indented like content
# api_port: 6443
# k3s_server_location: /var/lib/rancher/k3s
# systemd_dir: /etc/systemd/system
Expand Down
1 change: 1 addition & 0 deletions roles/k3s_server/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ systemd_dir: "/etc/systemd/system"
api_port: 6443

Check warning on line 4 in roles/k3s_server/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (vars: api_port)
kubeconfig: ~/.kube/config.new

Check warning on line 5 in roles/k3s_server/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (vars: kubeconfig)
user_kubectl: true
cluster_context: k3s-ansible
6 changes: 3 additions & 3 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@
changed_when:
- csa_result.rc == 0

- name: Setup kubeconfig k3s-ansible context on control node
- name: Setup kubeconfig context on control node - {{ cluster_context }}
when: kubeconfig != "~/.kube/config"
ansible.builtin.replace:
path: "{{ kubeconfig }}"
regexp: 'name: default'
replace: 'name: k3s-ansible'
replace: 'name: {{ cluster_context }}'
delegate_to: 127.0.0.1
become: false

- name: Merge with any existing kubeconfig on control node
when: kubeconfig != "~/.kube/config"
ansible.builtin.shell: |
TFILE=$(mktemp)
KUBECONFIG={{ kubeconfig }} kubectl config set-context k3s-ansible --user=k3s-ansible --cluster=k3s-ansible
KUBECONFIG={{ kubeconfig }} kubectl config set-context {{ cluster_context }} --user={{ cluster_context }} --cluster={{ cluster_context }}

Check warning on line 136 in roles/k3s_server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

136:121 [line-length] line too long (149 > 120 characters)
KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE}
mv ${TFILE} {{ kubeconfig }}
delegate_to: 127.0.0.1
Expand Down

0 comments on commit c84c1ce

Please sign in to comment.