Skip to content

Commit

Permalink
Support for pinning the IP address of the load balancer via terraform…
Browse files Browse the repository at this point in the history
… overrides (#1235)

* Suport adding load balancer annotations and ip via terraform overrides

* add documentation for terraform overrides

* make terraform overrides being able to override any variable
  • Loading branch information
aktech authored Apr 11, 2022
1 parent 2507573 commit 927d443
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
30 changes: 30 additions & 0 deletions docs/source/installation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,36 @@ jupyterhub:
users: true
```

## Terraform Overrides

The QHub configuration file provides a huge number of configuration options for customizing your
QHub Infrastructure, while these options are sufficient for an average user, but aren't
exhaustive by any means. There are still a plenty of things you might want to achieve which
cannot be configured directly by the above mentioned options, hence we've introduced a
new option called terraform overrides (`terraform_overrides`), which lets you override
the values of terraform variables in specific modules/resource. This is a relatively
advance feature and must be used with utmost care and you should really know, what
you're doing.

Here we describe the overrides supported via QHub config file:

### Ingress

You can configure the IP of the load balancer and add annotations for the same via `ingress`'s
terraform overrides, one such example for GCP is:


```yaml
ingress:
terraform_overrides:
load-balancer-annotations:
"networking.gke.io/load-balancer-type": "Internal"
"networking.gke.io/internal-load-balancer-subnet": "pre-existing-subnet"
load-balancer-ip: "1.2.3.4"
```

This is quite useful for pinning the IP Address of the load balancer.

# Full configuration example

```yaml
Expand Down
5 changes: 5 additions & 0 deletions qhub/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ class QHubExtension(Base):
envs: typing.Optional[typing.List[QHubExtensionEnv]]


class Ingress(Base):
terraform_overrides: typing.Any


# ======== External Container Registry ========

# This allows the user to set a private AWS ECR as a replacement for
Expand Down Expand Up @@ -455,6 +459,7 @@ class Main(Base):
prevent_deploy: bool = (
False # Optional, but will be given default value if not present
)
ingress: typing.Optional[Ingress]

# If the qhub_version in the schema is old
# we must tell the user to first run qhub upgrade
Expand Down
1 change: 1 addition & 0 deletions qhub/stages/input_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def stage_04_kubernetes_ingress(stage_outputs, config):
"certificate-secret-name": config["certificate"]["secret_name"]
if config["certificate"]["type"] == "existing"
else None,
**config.get("ingress", {}).get("terraform_overrides", {}),
}


Expand Down
10 changes: 6 additions & 4 deletions qhub/template/stages/04-kubernetes-ingress/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ module "kubernetes-ingress" {

node-group = var.node_groups.general

enable-certificates = var.enable-certificates
acme-email = var.acme-email
acme-server = var.acme-server
certificate-secret-name = var.certificate-secret-name
enable-certificates = var.enable-certificates
acme-email = var.acme-email
acme-server = var.acme-server
certificate-secret-name = var.certificate-secret-name
load-balancer-annotations = var.load-balancer-annotations
load-balancer-ip = var.load-balancer-ip
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ resource "kubernetes_service" "main" {
}

spec {
selector = {
selector = merge({
"app.kubernetes.io/component" = "traefik-ingress"
}
}, var.load-balancer-annotations)

port {
name = "http"
Expand Down Expand Up @@ -111,6 +111,7 @@ resource "kubernetes_service" "main" {
}

type = "LoadBalancer"
load_balancer_ip = var.load-balancer-ip
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ variable "certificate-secret-name" {
type = string
default = null
}

variable "load-balancer-ip" {
description = "IP Address of the load balancer"
type = string
default = null
}

variable "load-balancer-annotations" {
description = "Annotations for the load balancer"
type = map(object({
key = string
value = string
}))
default = null
}
17 changes: 17 additions & 0 deletions qhub/template/stages/04-kubernetes-ingress/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ variable "certificate-secret-name" {
description = "Kubernetes secret used for certificate"
default = ""
}


variable "load-balancer-ip" {
description = "IP Address of the load balancer"
type = string
default = null
}


variable "load-balancer-annotations" {
description = "Annotations for the load balancer"
type = map(object({
key = string
value = string
}))
default = null
}

0 comments on commit 927d443

Please sign in to comment.