diff --git a/kvirt/cluster/hypershift/__init__.py b/kvirt/cluster/hypershift/__init__.py index 9e57941e7..ac3858724 100644 --- a/kvirt/cluster/hypershift/__init__.py +++ b/kvirt/cluster/hypershift/__init__.py @@ -3,7 +3,7 @@ from ipaddress import ip_network from kvirt.common import success, error, pprint, info2, container_mode, warning, fix_typos, olm_app from kvirt.common import get_oc, pwd_path, get_installer_rhcos, get_ssh_pub_key, start_baremetal_hosts_with_iso -from kvirt.common import deploy_cloud_storage +from kvirt.common import deploy_cloud_storage, patch_ingress_controller_wildcard from kvirt.cluster.openshift import get_ci_installer, get_downstream_installer, get_installer_version from kvirt.cluster.openshift import same_release_images, process_apps, offline_image import json @@ -558,10 +558,7 @@ def create(config, plandir, cluster, overrides): data['domain'] = domain pprint(f"Setting domain to {domain}") try: - cmcmd = "oc patch ingresscontroller -n openshift-ingress-operator default --type=json -p " - cmcmd += "'[{ \"op\": \"add\", \"path\": \"/spec/routeAdmission\", " - cmcmd += "\"value\": {wildcardPolicy: \"WildcardsAllowed\"}}]'" - call(cmcmd, shell=True) + patch_ingress_controller_wildcard() except: warning("Couldnt patch ingresscontroller to support wildcards. Assuming it's configured properly") if not kubevirt: diff --git a/kvirt/cluster/openshift/__init__.py b/kvirt/cluster/openshift/__init__.py index f0144c2c2..28a02c8b4 100644 --- a/kvirt/cluster/openshift/__init__.py +++ b/kvirt/cluster/openshift/__init__.py @@ -4,7 +4,7 @@ from ipaddress import ip_address, ip_network import json from kvirt.common import error, pprint, success, warning, info2, fix_typos -from kvirt.common import get_oc, pwd_path, get_oc_mirror +from kvirt.common import get_oc, pwd_path, get_oc_mirror, patch_ingress_controller_wildcard from kvirt.common import get_latest_fcos, generate_rhcos_iso, olm_app from kvirt.common import get_installer_rhcos, wait_cloud_dns, delete_lastvm, detect_openshift_version from kvirt.common import ssh, scp, _ssh_credentials, get_ssh_pub_key @@ -797,10 +797,11 @@ def create(config, plandir, cluster, overrides, dnsconfig=None): elif provider == 'kubevirt': selector = {'kcli/plan': plan, 'kcli/role': 'ctlplane'} service_type = "LoadBalancer" if k.access_mode == 'LoadBalancer' else 'NodePort' + namespace = k.namespace if service_type == 'NodePort': kubevirt_api_service_node_port = True - api_ip = k.create_service(f"{cluster}-api", k.namespace, selector, _type=service_type, - ports=[6443, 22623, 22624, 80, 443], openshift_hack=True) + api_ip = k.create_service(f"{cluster}-api", namespace, selector, _type=service_type, + ports=[6443, 22623, 22624], openshift_hack=True) if api_ip is None: return {'result': 'failure', 'reason': "Couldnt gather an api_ip from your specified network"} else: @@ -809,6 +810,15 @@ def create(config, plandir, cluster, overrides, dnsconfig=None): overrides['kubevirt_api_service'] = True kubevirt_api_service = True overrides['mdns'] = False + try: + patch_ingress_controller_wildcard() + selector = {'kcli/plan': plan, 'kcli/role': 'worker' if workers > 0 else 'ctlplane'} + k.create_service(f"{cluster}-ingress", namespace, selector, ports=[80, 443]) + routecmd = f'oc -n {namespace} create route passthrough --service={cluster}-ingress ' + routecmd += f'--hostname=http.apps.{cluster}.{domain} --wildcard-policy=Subdomain --port=443' + call(routecmd, shell=True) + except: + pass else: return {'result': 'failure', 'reason': "You need to define api_ip in your parameters file"} if api_ip is not None: diff --git a/kvirt/common/__init__.py b/kvirt/common/__init__.py index ae6db0f43..6a4c8b141 100644 --- a/kvirt/common/__init__.py +++ b/kvirt/common/__init__.py @@ -2596,3 +2596,10 @@ def detect_openshift_version(tag, OPENSHIFT_TAG): else: version = 'stable' return version + + +def patch_ingress_controller_wildcard(): + cmd = "oc patch ingresscontroller -n openshift-ingress-operator default --type=json -p " + cmd += "'[{ \"op\": \"add\", \"path\": \"/spec/routeAdmission\", " + cmd += "\"value\": {wildcardPolicy: \"WildcardsAllowed\"}}]'" + call(cmd, shell=True) diff --git a/kvirt/providers/kubevirt/__init__.py b/kvirt/providers/kubevirt/__init__.py index 6339bc822..89e898a99 100644 --- a/kvirt/providers/kubevirt/__init__.py +++ b/kvirt/providers/kubevirt/__init__.py @@ -195,7 +195,7 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu vm['metadata']['annotations'][f'kcli/{entry}'] = metadata[entry] if entry == 'kube': kube = True - role = 'ctlplane' if name.endswith('bootstrap') else name.split('-')[-2] + role = 'ctlplane' if name.endswith('bootstrap') or name.endswith('sno') else name.split('-')[-2] vm['spec']['template']['metadata']['labels']['kcli/role'] = role if entry == 'plan' and kube: vm['spec']['template']['metadata']['labels']['kcli/plan'] = metadata[entry]