Skip to content

Commit

Permalink
Merge pull request #566 from psathyan/devScripts
Browse files Browse the repository at this point in the history
Add support for deploying OCP using dev-scripts.
  • Loading branch information
openshift-ci[bot] authored Oct 12, 2023
2 parents 0d5c058 + 56eee98 commit c194d42
Show file tree
Hide file tree
Showing 40 changed files with 1,715 additions and 60 deletions.
7 changes: 7 additions & 0 deletions ci_framework/playbooks/02-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
ansible.builtin.import_role:
name: rhol_crc

- name: Deploy OpenShift cluster using dev-scripts
when:
- cifmw_use_devscripts is defined
- cifmw_use_devscripts | bool
ansible.builtin.import_role:
name: devscripts

- name: Login into Openshift cluster
vars:
cifmw_openshift_login_force_refresh: true
Expand Down
23 changes: 23 additions & 0 deletions ci_framework/roles/ci_network/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# ci_network

Apply and manage connection in NetworkManager. This role is especially important for CI
and CI Job reproducer, since we have to prepare most of the network beforehand.

## Privilege escalation

It needs sudo access to edit Network Manager connections.

## Parameters

* `cifmw_network_generated_layout`: (Str) Path to the generated layout you want to apply. Defaults to `/etc/ci/env/network-layout.yml`.
* `cifmw_network_pre_cleanup`: (Bool) Clean existing ethernet connections before applying configuration. Defaults to `true`.
* `cifmw_network_layout`: (Dict) Network layout you want to apply.
* `cifmw_network_nm_config_file`: (Str) Path to NetworkManager configuration file. Defaults to `/etc/NetworkManager/NetworkManager.conf`.
* `cifmw_network_nm_config`: (List(dict)) List of editions to do in the NetworkManager.conf. Defaults to `[]`
* `cifmw_network_local_dns`: (Dict) DNS configuration to be applied on the KVM host.

## NetworkManager configuration layout

The list must be as follow:

```YAML
Expand All @@ -24,6 +29,7 @@ cifmw_network_nm_config:
```
## Network configuration layout
This dict has to represent all of the networks as follow:
```YAML
Expand All @@ -43,5 +49,22 @@ cifmw_network_layout:
```
## Bootstrap CI
It will also look for a specific parameter from the CI Bootstrap steps: `crc_ci_bootstrap_networks_out`.
If it finds it, it will consume it instead of `cifmw_network_layout`.

## DNS configuration

The configuration is represented by

```YAML
cifmw_network_local_dns:
listen_addresses: # Optional. list, IP address for the daemon to listen on. Default: 127.0.0.1
interfaces: # Optional. list, names of network interfaces to listen on.
domains: # Optional. list, local domains to be configured
addresses: # Optional. list, of dictionaries
- fqdn: # str, Fully Qualified Domain Name
address: # str, a valid IP address
forwarders:
- 8.8.8.8 # Optional. list, of DNS forwarders to be applied.
```
87 changes: 87 additions & 0 deletions ci_framework/roles/ci_network/tasks/apply-dns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
# 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: Ensure the package is installed
become: true
ansible.builtin.package:
name: "dnsmasq"
state: "present"

- name: Enable local DNS resolution.
become: true
ansible.builtin.copy:
dest: "/etc/NetworkManager/conf.d/00-use-dnsmasq.conf"
owner: root
group: root
mode: '0644'
content: |
[main]
dns = dnsmasq
- name: Ensure existing nameservers are DNS forwarders.
become: true
when: >
"'127.0.0.1' not in ansible_dns.nameservers" or
"'forwarders' in cifmw_network_local_dns"
vars:
dns_servers: >-
{{
cifmw_network_local_dns.forwarders |
default(ansible_dns.nameservers)
}}
servers: "server={{ dns_servers | join('\nserver=') }}"
ansible.builtin.copy:
dest: "/etc/NetworkManager/dnsmasq.d/99-dns-forwarders.conf"
owner: root
group: root
mode: "0644"
content: "{{ servers }}"

- name: Prepare the dns configuration
ansible.builtin.set_fact:
_dns_config: "{{ cifmw_network_local_dns }}"

- name: Ensure dnsmasq listens on default IPv4 address
when: "'listen_addresses' not in cifmw_network_local_dns"
vars:
data:
listen_addresses:
- "127.0.0.1"
- "{{ ansible_default_ipv4.address }}"
ansible.builtin.set_fact:
_dns_config: >-
{{
_dns_config |
combine(data, recursive=true)
}}
- name: Copy the local dns configuration
become: true
vars:
config: "{{ _dns_config }}"
ansible.builtin.template:
src: "templates/local_domain.conf.j2"
dest: "/etc/NetworkManager/dnsmasq.d/cifmw_local_domain.conf"
owner: root
group: root
mode: "0644"

- name: Reload the NetworkManager to pick the changes
become: true
ansible.builtin.service:
name: NetworkManager
state: "reloaded"
33 changes: 33 additions & 0 deletions ci_framework/roles/ci_network/tasks/cleanup-dns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# 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: Remove the local dns configuration
become: true
ansible.builtin.file:
path: "{{ item }}"
state: absent
force: true
loop:
- "/etc/NetworkManager/conf.d/00-use-dnsmasq.conf"
- "/etc/NetworkManager/dnsmasq.d/cifmw_local_domain.conf"
- "/etc/NetworkManager/dnsmasq.d/99-dns-forwarders.conf"

- name: Reload the NetworkManager to pick the changes
become: true
ansible.builtin.service:
name: NetworkManager
state: "reloaded"
22 changes: 22 additions & 0 deletions ci_framework/roles/ci_network/templates/local_domain.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is generated by ci-framework tool
listen-address={{ config.listen_addresses | join(',') }}

{% if 'interfaces' in config %}
{% for interface in config.interfaces %}
interface={{ interface }}
{% endfor %}
{% endif %}

addn-hosts=/etc/hosts

{% if 'domains' in config %}
{% for domain in config.domains %}
local=/{{ domain }}/
{% endfor %}
{% endif %}

{% if 'addresses' in config %}
{% for address in config.addresses %}
address=/{{ address.fqdn }}/{{ address.address }}
{% endfor %}
{% endif %}
Loading

0 comments on commit c194d42

Please sign in to comment.