Skip to content

Commit

Permalink
Support reusing of deployed OCP cluster.
Browse files Browse the repository at this point in the history
Reuse an existing deployed OCP cluster by dev-scripts or
ci-framework.

Signed-off-by: Pragadeeswaran Sathyanarayanan <[email protected]>
  • Loading branch information
psathyan authored and openshift-merge-bot[bot] committed Dec 15, 2023
1 parent 450e8d5 commit 1c78a48
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 24 deletions.
85 changes: 85 additions & 0 deletions ci_framework/roles/devscripts/tasks/00_pre_check.yml
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
23 changes: 17 additions & 6 deletions ci_framework/roles/devscripts/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,37 @@
- "{{ cifmw_devscripts_logs_dir }}"
- "{{ cifmw_devscripts_output_dir }}"

- name: Prepare the host for execution of dev-scripts.
- name: Perform pre-checks
tags:
- devscripts_prepare
- devscripts_deploy
ansible.builtin.import_tasks: 01_prepare_host.yml
- always
ansible.builtin.import_tasks: 00_pre_check.yml

- name: Gather the host and dev-scripts required information.
- name: Prepare for OCP deployment.
tags:
- devscripts_prepare
- devscripts_deploy
ansible.builtin.import_tasks: 02_gather_env_details.yml
when:
- not cifmw_devscripts_skip_deploy | default(false)
- not cifmw_devscripts_use_base_layer | default(false)
block:
- name: Prepare the host for execution of dev-scripts.
ansible.builtin.import_tasks: 01_prepare_host.yml

- name: Gather the host and dev-scripts required information.
ansible.builtin.import_tasks: 02_gather_env_details.yml

- name: Running dev-scripts.
tags:
- devscripts_deploy
when:
- not cifmw_devscripts_skip_deploy | default(false)
- not cifmw_devscripts_use_base_layer | default(false)
ansible.builtin.import_tasks: 03_install.yml

- name: Prepare for image overlay
when:
- cifmw_devscripts_use_layers | bool
- not cifmw_devscripts_skip_deploy | default(false)
ansible.builtin.import_tasks: 04_overlays.yml

- name: Executing dev-scripts post-install tasks.
Expand Down
22 changes: 4 additions & 18 deletions ci_framework/roles/devscripts/tasks/sub_tasks/53_add_bmh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,8 @@
group: "{{ cifmw_devscripts_user }}"
mode: "0755"

- name: Create baremetal host object
vars:
node: "{{ item }}"
ansible.builtin.template:
src: templates/bmh.yaml.j2
dest: "{{ cifmw_devscripts_artifacts_dir }}/bmh/{{ item.name }}.yaml"
owner: "{{ cifmw_devscripts_user }}"
group: "{{ cifmw_devscripts_user }}"
mode: "0644"
- name: Add OpenStack compute nodes
ansible.builtin.include_tasks: _add_node.yml
loop: "{{ cifmw_devscripts_osp_compute_nodes }}"

- name: Apply the baremetal host definitions
when:
- cifmw_devscripts_osp_compute_nodes is defined
- cifmw_devscripts_osp_compute_nodes | length > 0
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
ansible.builtin.command:
cmd: "oc apply -f {{ cifmw_devscripts_artifacts_dir }}/bmh/"
loop_control:
loop_var: node
50 changes: 50 additions & 0 deletions ci_framework/roles/devscripts/tasks/sub_tasks/_add_node.yml
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"

0 comments on commit 1c78a48

Please sign in to comment.