Ver Fonte

fix: create kubeconfig locally

Kamesh Sampath há 4 anos atrás
pai
commit
3c31f35378
4 ficheiros alterados com 27 adições e 9 exclusões
  1. 2 1
      defaults/main.yml
  2. 10 1
      tasks/minikube_create.yml
  3. 13 2
      tasks/minikube_destroy.yml
  4. 2 5
      tasks/minikube_pre_reqs.yml

+ 2 - 1
defaults/main.yml

@@ -16,4 +16,5 @@ minikube_profiles:
      - registry
      - registry-aliases
      - metallb
-profile_name_query: 'valid[*].Name'
+profile_name_query: 'valid[*].Name'
+force_enable_addon: true

+ 10 - 1
tasks/minikube_create.yml

@@ -36,6 +36,11 @@
   debug:
     var: minikube_profiles
 
+- name: "Create Kubeconfig dir"
+  file:
+    state: directory
+    path: "{{ playbook_dir }}/.kube"
+
 - name: "Create minikube Kubernetes Cluster"
   command:
     argv:
@@ -56,6 +61,8 @@
   loop: "{{ minikube_profiles | dict2items }}"
   loop_control:
     label: "{{ item.key }}"
+  environment:
+    KUBECONFIG: "{{ playbook_dir }}/.kube/{{ item.key }}.kubeconfig"
   when: (item.value.create | bool) and not ( item.value.destroy | bool )
 
 - name: "Fail when cluster not started"
@@ -80,4 +87,6 @@
   changed_when: False
   loop_control:
     label: "Enabling addon '{{ item.1}}' on '{{ item.0.key }}'"
-  when: (item.0.value.create | bool) and not ( item.0.value.destroy | bool )
+  when:  ( ( item.0.value.create | bool ) and not ( item.0.value.destroy | bool ) ) or force_enable_addon
+  environment:
+    KUBECONFIG: "{{ playbook_dir }}/.kube/{{ item.0.key }}.kubeconfig"

+ 13 - 2
tasks/minikube_destroy.yml

@@ -13,11 +13,22 @@
     label: "{{ item.key }}"
   when: (item.value.destroy | bool ) and not ( item.value.create | bool)
 
+- name: "Cleanup kubeconfig files"
+  ansible.builtin.file:
+    path: "{{ playbook_dir }}/.kube/{{ item.key }}.kubeconfig"
+    state: absent
+  loop: "{{ minikube_profiles | dict2items }}"
+  loop_control:
+    label: "{{ item.key }}"
+  when: (item.value.destroy | bool ) and not ( item.value.create | bool)
+  register: kubeconfig_cleanup
+
 - name: "Debug Delete Cluster"
   debug:
     var: delete_test_res
-
-- name: Fail when not cleaned
+  when: kubeconfig_cleanup.changed
+  
+- name: "Fail when not cleaned"
   fail:
     msg: "Error while deleting minikube resources"
   when: delete_test_res.changed and item.rc != 0

+ 2 - 5
tasks/minikube_pre_reqs.yml

@@ -62,18 +62,15 @@
 
 - name: Create user local bin directory
   file:
-    path: /usr/local/bin
+    path: "{{ ansible_env.HOME }}/.local/bin"
     state: directory
-  become: yes
   when: need_to_download
 
 - name: Download minikube binary
   get_url:
     url: "{{ minikube_download_binary }}"
-    dest: "/usr/local/bin/minikube"
+    dest: "{{ ansible_env.HOME }}/.local/bin/minikube"
     mode: "0755"
-    force: yes
-  become: yes
   when: need_to_download
   register: downloaded_minikube