-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to import existing clusters (#334)
* Add option to import existing clusters Signed-off-by: Jakub Stejskal <[email protected]> * Allow to specify already existing clusters Signed-off-by: Jakub Stejskal <[email protected]> --------- Signed-off-by: Jakub Stejskal <[email protected]>
- Loading branch information
Showing
23 changed files
with
302 additions
and
376 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
120 changes: 34 additions & 86 deletions
120
install/roles/automation-hub/tasks/common/setup_cluster_kubeconfig.yaml
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,109 +1,57 @@ | ||
# Get cluster URL | ||
|
||
- name: "Check if {{ cluster.name }} cluster config exists in {{ hive_namespace }} namespace" | ||
kubernetes.core.k8s_info: | ||
kubeconfig: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
namespace: "{{ hive_namespace }}" | ||
kind: ClusterDeployment | ||
name: "{{ cluster.name }}" | ||
verify_ssl: no | ||
ignore_errors: true | ||
register: cluster_present | ||
|
||
- name: "Wait for ClusterDeployment {{ cluster.name }} readiness" | ||
kubernetes.core.k8s_info: | ||
kubeconfig: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
namespace: "{{ hive_namespace }}" | ||
kind: ClusterDeployment | ||
name: "{{ cluster.name }}" | ||
wait: true | ||
wait_timeout: 5 | ||
verify_ssl: no | ||
wait_condition: | ||
type: Provisioned | ||
status: True | ||
reason: Provisioned | ||
when: cluster_present.resources != [] | ||
ignore_errors: true | ||
register: readiness | ||
|
||
- debug: | ||
msg: "{{ readiness }}" | ||
################################## | ||
#### Set kubeconfig data from yaml | ||
################################## | ||
- name: "Debug na zacatku" | ||
debug: | ||
msg: "{{ clusters_dict }}" | ||
|
||
- name: "Update facts for {{ cluster.name }}" | ||
- name: "Update facts for {{ cluster.name }} - kubeconfig based" | ||
ansible.utils.update_fact: | ||
updates: | ||
- path: "clusters_dict['{{ cluster.name }}'].exists" | ||
value: "{{ cluster_present.resources != [] }}" | ||
- path: "clusters_dict['{{ cluster.name }}'].provisioned" | ||
value: "{{ readiness.failed == False }}" | ||
when: cluster_present.resources != [] | ||
register: updated_data_ready | ||
- path: "clusters_dict['{{ cluster.name }}'].serverUrl" | ||
value: "{{ cluster.kubeconfig.serverUrl }}" | ||
- path: "clusters_dict['{{ cluster.name }}'].provisionRefName" | ||
value: "{{ cluster.name }}" | ||
register: updated_data | ||
when: cluster.kubeconfig is defined | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data.clusters_dict }}" | ||
when: cluster.kubeconfig is defined | ||
|
||
- name: "Update facts for {{ cluster.name }}" | ||
ansible.utils.update_fact: | ||
updates: | ||
- path: "clusters_dict['{{ cluster.name }}'].exists" | ||
value: "{{ cluster_present.resources != [] }}" | ||
value: True | ||
- path: "clusters_dict['{{ cluster.name }}'].provisioned" | ||
value: False | ||
when: cluster_present.resources == [] | ||
register: updated_data_not_ready | ||
value: True | ||
when: cluster.kubeconfig is defined | ||
register: kubeconfig_defined | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data_not_ready.clusters_dict }}" | ||
when: updated_data_not_ready.clusters_dict is defined | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data_ready.clusters_dict }}" | ||
when: updated_data_ready.clusters_dict is defined | ||
|
||
- debug: | ||
msg: "{{ clusters_dict }}" | ||
|
||
- name: "Get cluster {{ cluster.name }} API URL" | ||
shell: "oc get clusterdeployment {{ cluster.name }} -n {{ hive_namespace }} -o=jsonpath='{.status.apiURL}'" | ||
environment: | ||
KUBECONFIG: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
register: serverUrl_output | ||
when: clusters_dict[cluster.name].provisioned | ||
|
||
- name: "Get cluster {{ cluster.name }} provisionRef name" | ||
shell: "oc get clusterdeployment {{ cluster.name }} -n {{ hive_namespace }} -o=jsonpath='{.status.provisionRef.name}'" | ||
environment: | ||
KUBECONFIG: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
register: provisionRefName_output | ||
when: clusters_dict[cluster.name].provisioned | ||
|
||
- name: "Extract kubeconfig for cluster {{ cluster.name }}" | ||
shell: "oc extract secret/{{ provisionRefName_output.stdout }}-admin-kubeconfig -n {{ hive_namespace }} --to=- --keys=kubeconfig" | ||
environment: | ||
KUBECONFIG: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
register: kubeconfig_output | ||
when: clusters_dict[cluster.name].provisioned | ||
|
||
- name: "Update facts for {{ cluster.name }}" | ||
ansible.utils.update_fact: | ||
updates: | ||
- path: "clusters_dict['{{ cluster.name }}'].serverUrl" | ||
value: "{{ serverUrl_output.stdout }}" | ||
- path: "clusters_dict['{{ cluster.name }}'].provisionRefName" | ||
value: "{{ provisionRefName_output.stdout }}" | ||
register: updated_data | ||
when: clusters_dict[cluster.name].provisioned | ||
clusters_dict: "{{ kubeconfig_defined.clusters_dict }}" | ||
when: cluster.kubeconfig is defined | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data.clusters_dict }}" | ||
when: clusters_dict[cluster.name].provisioned | ||
kubeconfig_data: "{{ cluster.kubeconfig.kubeconfig }}" | ||
when: cluster.kubeconfig is defined | ||
|
||
- name: Create kubeconfig for {{ cluster.name }} | ||
copy: | ||
content: "{{ kubeconfig_output.stdout }}" | ||
content: "{{ kubeconfig_data | b64decode }}" | ||
dest: "{{ kubeconfig_path }}/{{ cluster.name }}" | ||
when: clusters_dict[cluster.name].provisioned | ||
when: cluster.kubeconfig is defined | ||
|
||
##################### | ||
#### Common part #### | ||
##################### | ||
- name: Set proper rights for kubeconfigs on {{ cluster.name }} | ||
file: | ||
path: "{{ kubeconfig_path }}/{{ cluster.name }}" | ||
mode: '0755' | ||
when: clusters_dict[cluster.name].provisioned | ||
|
||
- name: "Debug na konci" | ||
debug: | ||
msg: "{{ clusters_dict }}" |
111 changes: 111 additions & 0 deletions
111
install/roles/automation-hub/tasks/common/setup_cluster_kubeconfig_hive.yaml
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Get cluster URL in Hive | ||
- name: "Check if {{ cluster.name }} cluster config exists in {{ hive_namespace }} namespace" | ||
kubernetes.core.k8s_info: | ||
kubeconfig: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
namespace: "{{ hive_namespace }}" | ||
kind: ClusterDeployment | ||
name: "{{ cluster.name }}" | ||
verify_ssl: no | ||
ignore_errors: true | ||
register: cluster_present | ||
|
||
- name: "Wait for ClusterDeployment {{ cluster.name }} readiness" | ||
kubernetes.core.k8s_info: | ||
kubeconfig: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
namespace: "{{ hive_namespace }}" | ||
kind: ClusterDeployment | ||
name: "{{ cluster.name }}" | ||
wait: true | ||
wait_timeout: 5 | ||
verify_ssl: no | ||
wait_condition: | ||
type: Provisioned | ||
status: True | ||
reason: Provisioned | ||
when: cluster_present.resources != [] and cluster.kubeconfig is undefined | ||
ignore_errors: true | ||
register: readiness | ||
|
||
- debug: | ||
msg: "{{ readiness }}" | ||
|
||
- name: "Update facts for {{ cluster.name }}" | ||
ansible.utils.update_fact: | ||
updates: | ||
- path: "clusters_dict['{{ cluster.name }}'].exists" | ||
value: "{{ cluster_present.resources != [] }}" | ||
- path: "clusters_dict['{{ cluster.name }}'].provisioned" | ||
value: "{{ readiness.failed == False }}" | ||
when: cluster_present.resources != [] | ||
register: updated_data_ready | ||
|
||
- name: "Update facts for {{ cluster.name }}" | ||
ansible.utils.update_fact: | ||
updates: | ||
- path: "clusters_dict['{{ cluster.name }}'].exists" | ||
value: "{{ cluster_present.resources != [] }}" | ||
- path: "clusters_dict['{{ cluster.name }}'].provisioned" | ||
value: False | ||
when: cluster_present.resources == [] | ||
register: updated_data_not_ready | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data_not_ready.clusters_dict }}" | ||
when: updated_data_not_ready.clusters_dict is defined | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data_ready.clusters_dict }}" | ||
when: updated_data_ready.clusters_dict is defined | ||
|
||
- debug: | ||
msg: "{{ clusters_dict }}" | ||
|
||
- name: "Get cluster {{ cluster.name }} API URL" | ||
shell: "oc get clusterdeployment {{ cluster.name }} -n {{ hive_namespace }} -o=jsonpath='{.status.apiURL}'" | ||
environment: | ||
KUBECONFIG: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
register: serverUrl_output | ||
when: clusters_dict[cluster.name].provisioned and cluster.kubeconfig is undefined | ||
|
||
- name: "Get cluster {{ cluster.name }} provisionRef name" | ||
shell: "oc get clusterdeployment {{ cluster.name }} -n {{ hive_namespace }} -o=jsonpath='{.status.provisionRef.name}'" | ||
environment: | ||
KUBECONFIG: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
register: provisionRefName_output | ||
when: clusters_dict[cluster.name].provisioned and cluster.kubeconfig is undefined | ||
|
||
- name: "Extract kubeconfig for cluster {{ cluster.name }}" | ||
shell: "oc extract secret/{{ provisionRefName_output.stdout }}-admin-kubeconfig -n {{ hive_namespace }} --to=- --keys=kubeconfig" | ||
environment: | ||
KUBECONFIG: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
register: kubeconfig_output | ||
when: clusters_dict[cluster.name].provisioned and cluster.kubeconfig is undefined | ||
|
||
- name: "Update facts for {{ cluster.name }}" | ||
ansible.utils.update_fact: | ||
updates: | ||
- path: "clusters_dict['{{ cluster.name }}'].serverUrl" | ||
value: "{{ serverUrl_output.stdout }}" | ||
- path: "clusters_dict['{{ cluster.name }}'].provisionRefName" | ||
value: "{{ provisionRefName_output.stdout }}" | ||
register: updated_data | ||
when: clusters_dict[cluster.name].provisioned and cluster.kubeconfig is undefined | ||
|
||
- set_fact: | ||
clusters_dict: "{{ updated_data.clusters_dict }}" | ||
when: clusters_dict[cluster.name].provisioned and cluster.kubeconfig is undefined | ||
|
||
- name: Create kubeconfig for {{ cluster.name }} | ||
copy: | ||
content: "{{ kubeconfig_output.stdout }}" | ||
dest: "{{ kubeconfig_path }}/{{ cluster.name }}" | ||
when: clusters_dict[cluster.name].provisioned and cluster.kubeconfig is undefined | ||
|
||
##################### | ||
#### Common part #### | ||
##################### | ||
- name: Set proper rights for kubeconfigs on {{ cluster.name }} | ||
file: | ||
path: "{{ kubeconfig_path }}/{{ cluster.name }}" | ||
mode: '0755' | ||
when: clusters_dict[cluster.name].provisioned |
21 changes: 0 additions & 21 deletions
21
install/roles/automation-hub/tasks/infra-setup/delete/delete_kubed.yaml
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
install/roles/automation-hub/tasks/infra-setup/delete/delete_kubernetes-replicator.yaml
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
- name: Delete Kubernetes Replicator on infra clusters | ||
kubernetes.core.k8s: | ||
kubeconfig: "{{ kubeconfig_path }}/{{ infra_context_name }}" | ||
namespace: "kube-system" | ||
state: absent | ||
apply: true | ||
template: templates/kubernetes-replicator/kubernetes-replicator.yaml.j2 | ||
verify_ssl: no | ||
|
||
- name: Delete Kubernetes Replicator on worker clusters | ||
kubernetes.core.k8s: | ||
kubeconfig: "{{ kubeconfig_path }}/{{ worker.name }}" | ||
namespace: "kube-system" | ||
state: absent | ||
apply: true | ||
template: templates/kubernetes-replicator/kubernetes-replicator.yaml.j2 | ||
verify_ssl: no | ||
loop: "{{ clusters_dict.values() }}" | ||
loop_control: | ||
loop_var: worker |
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
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
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
Oops, something went wrong.