Skip to content

Commit

Permalink
For optional virtual cluster ingress, expose a default subdomain, and…
Browse files Browse the repository at this point in the history
… allow adding of extra subdomains.
  • Loading branch information
GrahamDumpleton committed Jul 6, 2022
1 parent b82382e commit 80aa56f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,16 @@ spec:
x-kubernetes-preserve-unknown-fields: true
ingress:
type: object
required:
- enabled
properties:
enabled:
type: boolean
default: false
subdomains:
type: array
items:
type: string
dashboards:
type: array
items:
Expand Down
78 changes: 53 additions & 25 deletions session-manager/handlers/application_vcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def vcluster_session_objects_list(workshop_spec, application_properties):

ingress_enabled = xget(application_properties, "ingress.enabled", False)

ingress_subdomains = xget(application_properties, "ingress.subdomains", [])
ingress_subdomains = sorted(ingress_subdomains + ["default"])

sync_resources = ""

if ingress_enabled:
Expand Down Expand Up @@ -495,37 +498,62 @@ def vcluster_session_objects_list(workshop_spec, application_properties):
"syncPeriod": "24h",
},
},
]
)

ingress_body = {
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"name": "contour-$(session_namespace)",
"namespace": "$(session_namespace)",
},
"spec": {
"rules": [
{
"host": "*.$(session_namespace).$(ingress_domain)",
"http": {
"paths": [
{
"path": "/",
"pathType": "Prefix",
"backend": {
"service": {
"name": "envoy-x-projectcontour-x-my-vcluster",
"port": {"number": 80},
}
},
}
]
},
}
]
},
}

for subdomain in filter(len, ingress_subdomains):
ingress_body["spec"]["rules"].append(
{
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"name": "contour-$(session_namespace)",
"namespace": "$(session_namespace)",
},
"spec": {
"rules": [
"host": f"*.{subdomain}.$(session_namespace).$(ingress_domain)",
"http": {
"paths": [
{
"host": "*.$(session_namespace).$(ingress_domain)",
"http": {
"paths": [
{
"path": "/",
"pathType": "Prefix",
"backend": {
"service": {
"name": "envoy-x-projectcontour-x-my-vcluster",
"port": {"number": 80},
}
},
}
]
"path": "/",
"pathType": "Prefix",
"backend": {
"service": {
"name": "envoy-x-projectcontour-x-my-vcluster",
"port": {"number": 80},
}
},
}
]
},
},
]
)
}
)

objects.append(ingress_body)

return objects


Expand Down

0 comments on commit 80aa56f

Please sign in to comment.