-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Add option to use preexisting clusters for DR clusters #12
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
Open
darkdoc
wants to merge
1
commit into
validatedpatterns:main
Choose a base branch
from
darkdoc:byoc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,225 @@ | ||||||
| --- | ||||||
| - name: Validates that the regional clusters are good to use (byoc) | ||||||
| hosts: localhost | ||||||
| connection: local | ||||||
| gather_facts: false | ||||||
| roles: | ||||||
| - role: rhvp.cluster_utils.pattern_settings | ||||||
|
Check failure on line 7 in ansible/playbooks/validate_byoc.yml
|
||||||
| vars: | ||||||
| pattern_dir: "{{ playbook_dir }}/../../" | ||||||
| - role: rhvp.cluster_utils.find_vp_secrets | ||||||
| vars: | ||||||
| byoc_enabled: false | ||||||
| tasks: | ||||||
| - name: Set fact for clsutergroup name | ||||||
| ansible.builtin.set_fact: | ||||||
| clustergroup_name: "{{ values_global.main.clusterGroupName }}" | ||||||
|
|
||||||
| - name: Load values-{clustergroup_name}.yaml | ||||||
| ansible.builtin.set_fact: | ||||||
| values_clustergroup: "{{ lookup('file', pattern_dir + '/values-' + clustergroup_name + '.yaml') | from_yaml }}" | ||||||
|
|
||||||
| - name: Set fact for thew rdr app | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ansible.builtin.set_fact: | ||||||
| rdr_app: "{{ values_clustergroup.clusterGroup.applications.rdr }}" | ||||||
|
|
||||||
| - name: Load rdr values yaml | ||||||
| ansible.builtin.set_fact: | ||||||
| rdr_values: "{{ lookup('file', pattern_dir + rdr_app.path + '/values.yaml') | from_yaml }}" | ||||||
|
|
||||||
| - name: Set byoc for the playbook | ||||||
| ansible.builtin.set_fact: | ||||||
| byoc_enabled: true | ||||||
| when: | ||||||
| - ((rdr_app.overrides | default([]) | selectattr('name', 'eq', 'byoc')|first).value | default(false)) or (rdr_values.byoc) | ||||||
|
|
||||||
| - name: Set fact for secretStore backend | ||||||
| ansible.builtin.set_fact: | ||||||
| secrets_backing_store: "{{ values_global.global.secretStore.backend | default('vault') }}" | ||||||
| when: byoc_enabled | ||||||
|
|
||||||
| - name: Parse secrets data | ||||||
| no_log: "{{ hide_sensitive_output | default(true) }}" | ||||||
| rhvp.cluster_utils.parse_secrets_info: | ||||||
| values_secrets_plaintext: "{{ values_secrets_data }}" | ||||||
| secrets_backing_store: "{{ secrets_backing_store }}" | ||||||
| register: secrets_results | ||||||
| when: byoc_enabled | ||||||
|
|
||||||
| - name: Check byoc if we need to | ||||||
| when: byoc_enabled | ||||||
| block: | ||||||
| - name: Set facts for dr clusters backend | ||||||
| ansible.builtin.set_fact: | ||||||
| clusters: | ||||||
| primary_cluster: "{{ secrets_results.parsed_secrets['ocp-primary_cluster_kubeconfig'].fields.kubeconfig }}" | ||||||
| secondary_cluster: "{{ secrets_results.parsed_secrets['ocp-secondary_cluster_kubeconfig'].fields.kubeconfig }}" | ||||||
|
|
||||||
| - name: Get a tempfile for the kubeconfigs | ||||||
| ansible.builtin.tempfile: | ||||||
| state: directory | ||||||
| register: kubeconfigs_tempfolder | ||||||
|
|
||||||
| - name: Store pull secrets in tempfile | ||||||
| ansible.builtin.copy: | ||||||
| dest: "{{ kubeconfigs_tempfolder.path }}/{{ cluster.key }}" | ||||||
| content: "{{ cluster.value }}" | ||||||
| mode: "0644" | ||||||
| loop_control: | ||||||
| loop_var: cluster | ||||||
| label: "{{ cluster.key }}" | ||||||
| loop: "{{ clusters | dict2items }}" | ||||||
|
|
||||||
| - name: Check that both DR clusters are reachable | ||||||
| kubernetes.core.k8s_cluster_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/{{ cluster.key }}" | ||||||
| register: api_status | ||||||
| loop_control: | ||||||
| loop_var: cluster | ||||||
| label: "{{ cluster.key }}" | ||||||
| loop: "{{ clusters | dict2items }}" | ||||||
|
|
||||||
| - name: Hub cluster version | ||||||
| kubernetes.core.k8s_info: | ||||||
| api: config.openshift.io/v1 | ||||||
| kind: ClusterVersion | ||||||
| name: version | ||||||
| register: hub_clusterversion_raw | ||||||
|
|
||||||
| - name: Primary cluster version | ||||||
| kubernetes.core.k8s_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/primary_cluster" | ||||||
| api: config.openshift.io/v1 | ||||||
| kind: ClusterVersion | ||||||
| name: version | ||||||
| register: primary_clusterversion_raw | ||||||
|
|
||||||
| - name: Secondary cluster version | ||||||
| kubernetes.core.k8s_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/secondary_cluster" | ||||||
| api: config.openshift.io/v1 | ||||||
| kind: ClusterVersion | ||||||
| name: version | ||||||
| register: secondary_clusterversion_raw | ||||||
|
|
||||||
| - name: Set fact for cluster minor.major versions | ||||||
| ansible.builtin.set_fact: | ||||||
| primary_cluster_version: "{{ primary_clusterversion_raw.resources[0].status.desired.version.split('.')[:2] | join('.') }}" | ||||||
| secondary_cluster_version: "{{ secondary_clusterversion_raw.resources[0].status.desired.version.split('.')[:2] | join('.') }}" | ||||||
| hub_cluster_version: "{{ hub_clusterversion_raw.resources[0].status.desired.version.split('.')[:2] | join('.') }}" | ||||||
|
|
||||||
| - name: Validate BYOC DR Clusters have the same minor version between 4.18 and 4.20 | ||||||
| ansible.builtin.assert: | ||||||
| that: | ||||||
| - hub_cluster_version is ansible.builtin.version("4.18", ">=") | ||||||
| - hub_cluster_version is ansible.builtin.version("4.20", "<=") | ||||||
| - primary_cluster_version is ansible.builtin.version(hub_cluster_version) | ||||||
| - secondary_cluster_version is ansible.builtin.version(hub_cluster_version) | ||||||
| fail_msg: | | ||||||
| FATAL: BYOC DR Clusters have different versions: | ||||||
| Primary: {{ primary_cluster_version }}, Secondary: {{ secondary_cluster_version }} HUB: {{ hub_cluster_version }}). | ||||||
| Currently only same minor verion supported by ramenDR and odf. | ||||||
|
|
||||||
| - name: Hub cluster network | ||||||
| kubernetes.core.k8s_info: | ||||||
| api: config.openshift.io/v1 | ||||||
| kind: Network | ||||||
| name: cluster | ||||||
| register: hub_clusternetwork_raw | ||||||
|
|
||||||
| - name: Primary cluster network | ||||||
| kubernetes.core.k8s_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/primary_cluster" | ||||||
| api: config.openshift.io/v1 | ||||||
| kind: Network | ||||||
| name: cluster | ||||||
| register: primary_clusternetwork_raw | ||||||
|
|
||||||
| - name: Secondary cluster network | ||||||
| kubernetes.core.k8s_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/secondary_cluster" | ||||||
| api: config.openshift.io/v1 | ||||||
| kind: Network | ||||||
| name: cluster | ||||||
| register: secondary_clusternetwork_raw | ||||||
|
|
||||||
| - name: Set fact for cluster network vars | ||||||
| ansible.builtin.set_fact: | ||||||
| hub_cluster_cluster_cidr: "{{ hub_clusternetwork_raw.resources[0].spec.clusterNetwork[0].cidr }}" | ||||||
| hub_cluster_service_cidr: "{{ hub_clusternetwork_raw.resources[0].spec.serviceNetwork[0] }}" | ||||||
| primary_cluster_cluster_cidr: "{{ primary_clusternetwork_raw.resources[0].spec.clusterNetwork[0].cidr }}" | ||||||
| primary_cluster_service_cidr: "{{ primary_clusternetwork_raw.resources[0].spec.serviceNetwork[0] }}" | ||||||
| secondary_cluster_cluster_cidr: "{{ secondary_clusternetwork_raw.resources[0].spec.clusterNetwork[0].cidr }}" | ||||||
| secondary_cluster_service_cidr: "{{ secondary_clusternetwork_raw.resources[0].spec.serviceNetwork[0] }}" | ||||||
|
|
||||||
| - name: Validate BYOC DR Clusters have non overlapping pod networks. | ||||||
| ansible.builtin.assert: | ||||||
| that: | ||||||
| - not (hub_cluster_cluster_cidr | ansible.utils.ipaddr(primary_cluster_cluster_cidr)) | ||||||
| - not (hub_cluster_cluster_cidr | ansible.utils.ipaddr(secondary_cluster_cluster_cidr)) | ||||||
| - not (primary_cluster_cluster_cidr | ansible.utils.ipaddr(secondary_cluster_cluster_cidr)) | ||||||
| fail_msg: | | ||||||
| FATAL: BYOC DR Clusters have overlapping pod networks : | ||||||
| Primary: {{ primary_cluster_cluster_cidr }}, Secondary: {{ secondary_cluster_cluster_cidr }} HUB: {{ hub_cluster_cluster_cidr }}). | ||||||
|
|
||||||
| - name: Validate BYOC DR Clusters have non overlapping service networks. | ||||||
| ansible.builtin.assert: | ||||||
| that: | ||||||
| - not (hub_cluster_service_cidr | ansible.utils.ipaddr(primary_cluster_service_cidr)) | ||||||
| - not (hub_cluster_service_cidr | ansible.utils.ipaddr(secondary_cluster_service_cidr)) | ||||||
| - not (primary_cluster_service_cidr | ansible.utils.ipaddr(secondary_cluster_service_cidr)) | ||||||
| fail_msg: | | ||||||
| FATAL: BYOC DR Clusters have overlapping service networks: | ||||||
| Primary: {{ primary_cluster_service_cidr }}, Secondary: {{ secondary_cluster_service_cidr }} HUB: {{ hub_cluster_service_cidr }}). | ||||||
|
|
||||||
| - name: Get primary cluster node info | ||||||
| kubernetes.core.k8s_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/primary_cluster" | ||||||
| kind: Node | ||||||
| label_selectors: | ||||||
| - node-role.kubernetes.io/worker | ||||||
| register: primary_nodes_raw | ||||||
|
|
||||||
| - name: Build instance type list (primary) | ||||||
| set_fact: | ||||||
| primary_worker_instance_types: "{{ primary_worker_instance_types | default([]) + [ item.metadata.labels['node.kubernetes.io/instance-type'] ] }}" | ||||||
| loop: "{{ primary_nodes_raw.resources }}" | ||||||
| loop_control: | ||||||
| label: "{{ item.metadata.name }}" | ||||||
| when: item.metadata.labels is defined and | ||||||
| 'node.kubernetes.io/instance-type' in item.metadata.labels | ||||||
|
|
||||||
| - name: Make instance types unique (primary-cluster) | ||||||
| set_fact: | ||||||
| primary_worker_instance_types: "{{ primary_worker_instance_types | unique }}" | ||||||
|
|
||||||
| - name: Get secondary cluster node info | ||||||
| kubernetes.core.k8s_info: | ||||||
| kubeconfig: "{{ kubeconfigs_tempfolder.path }}/secondary_cluster" | ||||||
| kind: Node | ||||||
| label_selectors: | ||||||
| - node-role.kubernetes.io/worker | ||||||
| register: secondary_nodes_raw | ||||||
|
|
||||||
| - name: Build instance type list (secondary) | ||||||
| set_fact: | ||||||
| secondary_worker_instance_types: "{{ secondary_worker_instance_types | default([]) + [ item.metadata.labels['node.kubernetes.io/instance-type'] ] }}" | ||||||
| loop_control: | ||||||
| label: "{{ item.metadata.name }}" | ||||||
| loop: "{{ secondary_nodes_raw.resources }}" | ||||||
| when: item.metadata.labels is defined and | ||||||
| 'node.kubernetes.io/instance-type' in item.metadata.labels | ||||||
|
|
||||||
| - name: Make instance types unique (primary-cluster) | ||||||
| set_fact: | ||||||
| secondary_worker_instance_types: "{{ secondary_worker_instance_types | unique }}" | ||||||
|
|
||||||
| - name: Validate BYOC DR Clusters have metal node to run virtual machine workload | ||||||
| ansible.builtin.assert: | ||||||
| that: | ||||||
| - primary_worker_instance_types | select('search', 'metal') | list | length > 0 | ||||||
| - secondary_worker_instance_types | select('search', 'metal') | list | length > 0 | ||||||
| fail_msg: | | ||||||
| FATAL: BYOC DR Clusters have no metal nodes: | ||||||
| Primary: {{ primary_worker_instance_types }}). | ||||||
| Secondary: {{ primary_worker_instance_types }}). | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.