forked from openstack-k8s-operators/ci-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reusing of deployed OCP cluster.
Reuse an existing deployed OCP cluster by dev-scripts or ci-framework. Signed-off-by: Pragadeeswaran Sathyanarayanan <[email protected]>
- Loading branch information
1 parent
450e8d5
commit 1c78a48
Showing
4 changed files
with
156 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
# Copyright Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# Check for existing deployment | ||
|
||
|
||
- name: Determine if the role was run with cifmw_devscripts_use_layers. | ||
ansible.builtin.find: | ||
file_type: "file" | ||
path: "{{ cifmw_devscripts_config.working_dir }}" | ||
patterns: "{{ cifmw_devscripts_config.cluster_name }}_*.xml" | ||
register: overlay_results | ||
|
||
- name: Using existing deployment layer for creating OCP cluster. | ||
when: >- | ||
( | ||
cifmw_devscripts_config.num_masters | int + | ||
cifmw_devscripts_config.num_workers | int | ||
) == overlay_results.matched | ||
ansible.builtin.set_fact: | ||
cifmw_devscripts_use_base_layer: true | ||
|
||
- name: Gather dev-scripts deployed cluster auth information. | ||
when: not cifmw_devscripts_use_base_layer | default(false) | bool | ||
ansible.builtin.stat: | ||
path: >- | ||
{{ | ||
[ | ||
cifmw_devscripts_repo_dir, | ||
'ocp', | ||
cifmw_devscripts_config['cluster_name'], | ||
'auth', | ||
'kubeadmin-password' | ||
] | ansible.builtin.path_join | ||
}} | ||
register: _kubeconfig_result | ||
|
||
- name: Verify the deployed cluster. | ||
when: | ||
- _kubeconfig_result.stat is defined | ||
- _kubeconfig_result.stat.exists | ||
block: | ||
- name: Gather the deployed cluster authentication information. | ||
ansible.builtin.import_tasks: sub_tasks/51_set_facts.yml | ||
|
||
- name: Login to the deployed OpenShift cluster. | ||
kubernetes.core.k8s_auth: | ||
host: "{{ cifmw_openshift_api }}" | ||
password: "{{ cifmw_openshift_password }}" | ||
state: present | ||
username: "{{ cifmw_openshift_user }}" | ||
validate_certs: false | ||
register: _login_result | ||
|
||
- name: Authentication successful to existing cluster. | ||
when: | ||
- _login_result is not failed | ||
- _login_result.k8s_auth.api_key is defined | ||
ansible.builtin.set_fact: | ||
cifmw_devscripts_skip_deploy: true | ||
|
||
- name: Cleanup the existing environment. | ||
when: | ||
- _login_result is defined | ||
- _login_result is failed | ||
block: | ||
- name: Cleaning up inaccessible OCP cluster. | ||
ansible.builtin.include_tasks: cleanup.yml | ||
|
||
- name: Force redeployment of the cluster. | ||
ansible.builtin.set_fact: | ||
cifmw_devscripts_skip_deploy: false |
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
50 changes: 50 additions & 0 deletions
50
ci_framework/roles/devscripts/tasks/sub_tasks/_add_node.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
# Copyright Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
- name: Verify if BaremetalHost resource exists. | ||
when: | ||
- cifmw_devscripts_skip_deploy | default(false) | ||
- _login_result is defined | ||
block: | ||
- name: Gather the baremetal host information | ||
kubernetes.core.k8s_info: | ||
api_version: "metal3.io/v1alpha1" | ||
kind: "BareMetalHost" | ||
name: "{{ node.name }}" | ||
namespace: "openshift-machine-api" | ||
register: _bmh_node_result | ||
|
||
- name: Node resource exists. | ||
when: _bmh_node_result.resources is defined | ||
ansible.builtin.set_fact: | ||
_add_node: false | ||
|
||
- name: Create baremetal host object | ||
when: _add_node | default(true) | ||
ansible.builtin.template: | ||
src: templates/bmh.yaml.j2 | ||
dest: "{{ cifmw_devscripts_artifacts_dir }}/bmh/{{ node.name }}.yaml" | ||
owner: "{{ cifmw_devscripts_user }}" | ||
group: "{{ cifmw_devscripts_user }}" | ||
mode: "0644" | ||
|
||
- name: Apply the baremetal host definitions | ||
when: _add_node | default(true) | ||
environment: | ||
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" | ||
ansible.builtin.command: | ||
cmd: "oc apply -f {{ cifmw_devscripts_artifacts_dir }}/bmh/{{ node.name }}.yaml" |