Skip to content

Commit

Permalink
openshift kubevirt: extra routes
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Jan 13, 2025
1 parent 1855ab5 commit e5168b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
7 changes: 2 additions & 5 deletions kvirt/cluster/hypershift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions kvirt/cluster/openshift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions kvirt/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion kvirt/providers/kubevirt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit e5168b9

Please sign in to comment.