-
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.
Adding bootstrap-in-place installation support
- Loading branch information
Showing
12 changed files
with
316 additions
and
69 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,110 @@ | ||
import os | ||
import shutil | ||
import shlex | ||
import logging | ||
import yaml | ||
|
||
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 = f"{BUILD_DIR}/ibip" | ||
RESOURCES_DIR = "discovery-infra/resources" | ||
INSTALL_CONFIG = os.path.join(IBIP_DIR, INSTALL_CONFIG_FILE_NAME) | ||
INSTALLER_BINARY = f"{BUILD_DIR}/openshift-install" | ||
EMBED_IMAGE_NAME = "installer-SNO-image.iso" | ||
|
||
|
||
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): | ||
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 | ||
with open(INSTALL_CONFIG, "w") as _file: | ||
yaml.dump(config, _file) | ||
|
||
|
||
def setup_files_and_folders(args): | ||
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) | ||
utils.set_network_asset_file() | ||
|
||
|
||
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 start_nodes(image_path): | ||
net = NetworkAssets().get() | ||
controller_kwargs = { | ||
"cluster_name": "test-infra-cluster", | ||
"num_workers": 0, | ||
"num_masters": 1, | ||
"net_asset": net, | ||
"iso_download_path": image_path, | ||
"ignore_unique_suffix": True, | ||
"bootstrap_in_place": True | ||
} | ||
|
||
controller = TerraformController(**controller_kwargs) | ||
controller.start_all_nodes() | ||
|
||
|
||
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") | ||
|
||
setup_files_and_folders(args) | ||
|
||
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) | ||
|
||
start_nodes(image_path) |
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,IyEvYmluL2Jhc2ggLXgKZXhwb3J0IEtVQkVDT05GSUc9L2V0Yy9rdWJlcm5ldGVzL2Jvb3RzdHJhcC1zZWNyZXRzL2t1YmVjb25maWcKCmZ1bmN0aW9uIHdhaXRfZm9yX2FwaSB7CiAgdW50aWwgb2MgZ2V0IGNzciAmPiAvZGV2L251bGwKICAgIGRvCiAgICAgICAgZWNobyAiV2FpdGluZyBmb3IgYXBpIC4uLiIKICAgICAgICBzbGVlcCAzMAogICAgZG9uZQp9CmZ1bmN0aW9uIHJlc3RhcnRfa3ViZWxldCB7CiAgZWNobyAiUmVzdGFydGluZyBrdWJlbGV0IgogIHdoaWxlIGNhdCAvZXRjL2t1YmVybmV0ZXMvbWFuaWZlc3RzL2t1YmUtYXBpc2VydmVyLXBvZC55YW1sICB8IGdyZXAgYm9vdHN0cmFwLWt1YmUtYXBpc2VydmVyOyBkbwogICAgZWNobyAiV2FpdGluZyBmb3Iga3ViZS1hcGlzZXJ2ZXIgdG8gYXBwbHkgdGhlIG5ldyBzdGF0aWMgcG9kIGNvbmZpZ3VyYXRpb24iCiAgICBzbGVlcCAxMAogIGRvbmUKICBzeXN0ZW1jdGwgZGFlbW9uLXJlbG9hZAogIHN5c3RlbWN0bCByZXN0YXJ0IGt1YmVsZXQKfQpmdW5jdGlvbiBhcHByb3ZlX2NzciB7CiAgZWNobyAiQXBwcm92aW5nIGNzcnMgLi4uIgogIG5lZWRlZF90b19hcHByb3ZlPWZhbHNlCiAgdW50aWwgWyAkKG9jIGdldCBub2RlcyB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cm92ZV9jc3IKd2FpdF9mb3JfY3ZvCmNsZWFu | ||
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
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
Oops, something went wrong.