-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MGMT-3108: Adding bootstrap-in-place installation support
- Loading branch information
Showing
13 changed files
with
374 additions
and
71 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
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,145 @@ | ||
import os | ||
import shutil | ||
import shlex | ||
import logging | ||
import yaml | ||
|
||
import waiting | ||
|
||
from oc_utils import get_operators_status | ||
from test_infra import utils, consts | ||
from test_infra.tools.assets import NetworkAssets | ||
from test_infra.controllers.node_controllers.terraform_controller import TerraformController | ||
|
||
BUILD_DIR = "build" | ||
INSTALL_CONFIG_FILE_NAME = "install-config.yaml" | ||
IBIP_DIR = os.path.join(BUILD_DIR, "ibip") | ||
RESOURCES_DIR = os.path.join("discovery-infra", "resources") | ||
INSTALL_CONFIG = os.path.join(IBIP_DIR, INSTALL_CONFIG_FILE_NAME) | ||
INSTALLER_BINARY = os.path.join(BUILD_DIR, "openshift-install") | ||
EMBED_IMAGE_NAME = "installer-SNO-image.iso" | ||
KUBE_CONFIG = os.path.join(IBIP_DIR, "auth", "kubeconfig") | ||
|
||
|
||
def installer_generate(): | ||
logging.info("Installer generate manifests") | ||
utils.run_command(f"{INSTALLER_BINARY} create manifests --dir={IBIP_DIR}") | ||
logging.info("Installer generate ignitions") | ||
# TODO delete | ||
shutil.copy(f"{RESOURCES_DIR}/sno_manifest.yaml", os.path.join(IBIP_DIR, "openshift")) | ||
utils.run_command(f"{INSTALLER_BINARY} create ignition-configs --dir={IBIP_DIR}") | ||
|
||
|
||
def download_live_image(download_path, rhcos_version=None): | ||
if os.path.exists(download_path): | ||
logging.info("Image %s already exists, skipping download", download_path) | ||
return | ||
|
||
logging.info("Downloading iso to %s", download_path) | ||
rhcos_version = rhcos_version or os.getenv('RHCOS_VERSION', "46.82.202009222340-0") | ||
utils.run_command(f"curl https://releases-art-rhcos.svc.ci.openshift.org/art/storage/releases/rhcos-4.6/" | ||
f"{rhcos_version}/x86_64/rhcos-{rhcos_version}-live.x86_64.iso --retry 5 -o {download_path}") | ||
|
||
|
||
def embed(image_name, ignition_file, embed_image_name): | ||
logging.info("Embed ignition %s to iso %s", ignition_file, image_name) | ||
embedded_image = os.path.join(BUILD_DIR, embed_image_name) | ||
os.remove(embedded_image) if os.path.exists(embedded_image) else None | ||
|
||
flags = shlex.split(f"--privileged --rm -v /dev:/dev -v /run/udev:/run/udev -v .:/data -w /data") | ||
utils.run_container("coreos-installer", "quay.io/coreos/coreos-installer:release", flags, | ||
f"iso ignition embed {BUILD_DIR}/{image_name} " | ||
f"-f --ignition-file /data/{IBIP_DIR}/{ignition_file} -o /data/{embedded_image}") | ||
|
||
image_path = os.path.join(consts.BASE_IMAGE_FOLDER, embed_image_name) | ||
shutil.move(embedded_image, image_path) | ||
return image_path | ||
|
||
|
||
def fill_install_config(pull_secret, ssh_pub_key, net_asset, cluster_name): | ||
yaml.add_representer(str, str_presenter) | ||
with open(INSTALL_CONFIG, "r") as _file: | ||
config = yaml.safe_load(_file) | ||
|
||
config["pullSecret"] = pull_secret | ||
config["sshKey"] = ssh_pub_key | ||
config["metadata"]["name"] = cluster_name | ||
config["networking"]["machineNetwork"][0]["cidr"] = net_asset["machine_cidr"] | ||
|
||
with open(INSTALL_CONFIG, "w") as _file: | ||
yaml.dump(config, _file) | ||
|
||
|
||
def setup_files_and_folders(args, net_asset, cluster_name): | ||
logging.info("Creating needed files and folders") | ||
utils.recreate_folder(consts.BASE_IMAGE_FOLDER, force_recreate=False) | ||
utils.recreate_folder(IBIP_DIR, with_chmod=False, force_recreate=True) | ||
shutil.copy(os.path.join(RESOURCES_DIR, INSTALL_CONFIG_FILE_NAME), IBIP_DIR) | ||
fill_install_config(args.pull_secret, args.ssh_key, net_asset, cluster_name) | ||
|
||
|
||
def str_presenter(dumper, data): | ||
if "ssh-rsa" in data: # check for multiline string | ||
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|') | ||
return dumper.represent_scalar('tag:yaml.org,2002:str', data) | ||
|
||
|
||
def create_controller(net_asset): | ||
return TerraformController( | ||
cluster_name="test-infra-cluster", | ||
num_masters=1, | ||
num_workers=0, | ||
master_memory=32 * 1024, # 32GB of RAM | ||
net_asset=net_asset, | ||
iso_download_path="<TBD>", # will be set later on | ||
bootstrap_in_place=True, | ||
) | ||
|
||
|
||
def all_operators_up(): | ||
statuses = get_operators_status(KUBE_CONFIG) | ||
if not statuses: | ||
logging.debug("No operator has been found currently...") | ||
return False | ||
|
||
invalid_operators = [operator for operator, up in statuses.items() if not up] | ||
|
||
all_operators_are_valid = len(invalid_operators) == 0 | ||
|
||
if not all_operators_are_valid: | ||
logging.debug("Following operators are still down: %s", ", ".join(invalid_operators)) | ||
|
||
return all_operators_are_valid | ||
|
||
|
||
def execute_ibip_flow(args): | ||
openshift_release_image = os.getenv('OPENSHIFT_INSTALL_RELEASE_IMAGE') | ||
if not openshift_release_image: | ||
raise ValueError("os env OPENSHIFT_INSTALL_RELEASE_IMAGE must be provided") | ||
|
||
net_asset = NetworkAssets().get() | ||
controller = create_controller(net_asset) | ||
setup_files_and_folders(args, net_asset, controller.cluster_name) | ||
|
||
utils.extract_installer(openshift_release_image, BUILD_DIR) | ||
installer_generate() | ||
|
||
download_live_image(f"{BUILD_DIR}/installer-image.iso") | ||
image_path = embed("installer-image.iso", "bootstrap.ign", EMBED_IMAGE_NAME) | ||
|
||
logging.info("Starting nodes...") | ||
controller.image_path = image_path | ||
controller.start_all_nodes() | ||
logging.info("Nodes started!") | ||
|
||
logging.info("Configuring /etc/hosts...") | ||
utils.config_etc_hosts(cluster_name=controller.cluster_name, | ||
base_dns_domain=controller.cluster_domain, | ||
api_vip=controller.master_ips[0][0]) | ||
|
||
logging.info("Waiting for installation to complete...") | ||
waiting.wait(all_operators_up, | ||
sleep_seconds=20, | ||
timeout_seconds=60 * 60, | ||
waiting_for="all operators to get up") | ||
logging.info("Installation completed successfully!") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apiVersion: v1 | ||
baseDomain: redhat.com | ||
compute: | ||
- architecture: amd64 | ||
hyperthreading: Enabled | ||
name: worker | ||
platform: {} | ||
replicas: 0 | ||
controlPlane: | ||
architecture: amd64 | ||
hyperthreading: Enabled | ||
name: master | ||
platform: {} | ||
replicas: 1 | ||
metadata: | ||
creationTimestamp: null | ||
name: test-infra-cluster | ||
networking: | ||
clusterNetwork: | ||
- cidr: 10.128.0.0/14 | ||
hostPrefix: 23 | ||
machineNetwork: | ||
- cidr: 192.168.126.0/24 | ||
networkType: OpenShiftSDN | ||
serviceNetwork: | ||
- 172.30.0.0/16 | ||
platform: | ||
none: {} | ||
publish: External | ||
pullSecret: '{}' | ||
sshKey: "" |
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,22 @@ | ||
apiVersion: machineconfiguration.openshift.io/v1 | ||
kind: MachineConfig | ||
metadata: | ||
labels: | ||
machineconfiguration.openshift.io/role: master | ||
name: after-reboot | ||
spec: | ||
config: | ||
ignition: | ||
version: 3.1.0 | ||
storage: | ||
files: | ||
- contents: | ||
source: data:text/plain;charset=utf-8;base64,IyEvYmluL2Jhc2ggLXgKZXhwb3J0IEtVQkVDT05GSUc9L2V0Yy9rdWJlc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R9fXt7ZW5kfX0nIHwgeGFyZ3Mgb2MgYWRtIGNlcnRpZmljYXRlIGFwcHJvdmUgJj4gL2Rldi9udWxsIHx8IHRydWUKICAgICBzbGVlcCAzMAogICAgZG9uZQogICMgUmVzdGFydCBrdWJlbGV0IG9ubHkgaWYgbm9kZSB3YXMgYWRkZWQKICBpZiAkbmVlZGVkX3RvX2FwcHJvdmUgOyB0aGVuCiAgICBzbGVlcCA2MAogICAgcmVzdGFydF9rdWJlbGV0CiAgZmkKfQpmdW5jdGlvbiB3YWl0X2Zvcl9jdm8gewogIGVjaG8gIldhaXRpbmcgZm9yIGN2byIKICB1bnRpbCBbICIkKG9jIGdldCBjbHVzdGVydmVyc2lvbiAtbyBqc29ucGF0aD0ney5pdGVtc1swXS5zdGF0dXMuY29uZGl0aW9uc1s/KEAudHlwZT09IkF2YWlsYWJsZSIpXS5zdGF0dXN9JykiID09ICJUcnVlIiBdOyBkbwogICAgICBlY2hvICJTdGlsbCB3YWl0aW5nIGZvciBjdm8gLi4uIgogICAgIHNsZWVwIDMwCiAgICBkb25lCn0KZnVuY3Rpb24gY2xlYW4gewogIGlmIFsgLWQgIi9ldGMva3ViZXJuZXRlcy9ib290c3RyYXAtc2VjcmV0cyIgXTsgdGhlbgogICAgIHJtIC1yZiAvZXRjL2t1YmVybmV0ZXMvYm9vdHN0cmFwLSoKICBmaQp9Cgp3YWl0X2Zvcl9hcGkKYXBwcm92ZV9jc3IKd2FpdF9mb3JfY3ZvCmNsZWFu | ||
mode: 365 | ||
overwrite: true | ||
path: /usr/local/bin/after_reboot.sh | ||
systemd: | ||
units: | ||
- name: after_reboot.service | ||
contents: "[Unit]\nDescription=Master Install\nWants=kubelet.service\nAfter=kubelet.service\n[Service]\nType=oneshot\nExecStart=/usr/local/bin/after_reboot.sh\n\nRestartSec=5s\n\n[Install]\nWantedBy=multi-user.target\n" | ||
enabled: true |
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.