Skip to content

Commit

Permalink
Using debugger with tilt is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenlj committed Jun 18, 2024
1 parent 8b1782d commit a2f839c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,24 @@ If you don't have earthly installed, you can use the wrapper at `./earthlyw`, wh
## Development

Mutilator is a mutating webhook, which means the requests can be difficult to handcraft when testing.
For that reason, there is a Tiltfile that installs the webhook into a local kind cluster and sets a service that points out of the cluster to your locally running instance.
For that reason, there is a Tiltfile that installs the webhook into a local kind cluster and configures mutilator.
Optionally, tilt can create a service that points out of the cluster to your locally running instance.
This way you can run mutilator in a debugger, and trigger mutation by applying resources in the kind cluster.

To use this, you need to have [Tilt](https://tilt.dev) installed.
It is also recommended to use [ctlptl](https://github.com/tilt-dev/ctlptl) to manage your local cluster.

1. Start the cluster: `ctlptl create cluster kind --registry=ctlptl-registry`
2. Start tilt: `tilt up --stream`
3. Run mutilator in your debugger, with these environment variables:

| Variable | Value |
|------------------------------------|----------------------------------------|
| `MUTILATOR__PROJECT_VPC_ID` | `00000000-0000-0000-0000-000000000000` |
| `MUTILATOR__WEB__CERTIFICATE_PATH` | `tls.crt` |
| `MUTILATOR__WEB__PRIVATE_KEY_PATH` | `tls.key` |
2. Start tilt:
* mutilator running in cluster: `tilt up --stream`, or
* mutilator running locally: `tilt up --stream -- --debugger`
3. Either
* Watch logs in cluster `kubectl logs -lapp.kubernetes.io/name=mutilator`, or
* Run mutilator in your debugger, with these environment variables:

| Variable | Value |
|------------------------------------|----------------------------------------|
| `MUTILATOR__PROJECT_VPC_ID` | `00000000-0000-0000-0000-000000000000` |
| `MUTILATOR__WEB__CERTIFICATE_PATH` | `tls.crt` |
| `MUTILATOR__WEB__PRIVATE_KEY_PATH` | `tls.key` |
4. Apply suitable resources to trigger mutations: `kubectl apply -f develop/`
26 changes: 14 additions & 12 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ deploy_cert_manager()
helm_repo('aiven', 'https://aiven.github.io/aiven-charts')
helm_resource('aiven-operator-crds', 'aiven/aiven-operator-crds', resource_deps=['aiven'], pod_readiness="ignore")

config.define_bool("debugger", usage="Enable directing webhook requests out of the cluster to your locally running instance")
cfg = config.parse()

ignore = str(read_file(".earthignore")).split("\n")
host_ip = local_output("/sbin/ip route show default | awk '/default/ { print $9 }'")

mutilator_objects = [
"chart-mutilator:mutatingwebhookconfiguration",
"chart-mutilator:networkpolicy",
"chart-mutilator:certificate",
"chart-mutilator:issuer",
]
if cfg.get("debugger", False):
mutilator_objects.append("chart-mutilator:endpointslice")
mutilator_objects.append("chart-mutilator:service")

custom_build(
ref=APP_NAME,
Expand All @@ -21,8 +32,6 @@ custom_build(
ignore=ignore,
)



# Deployed to the cluster
k8s_yaml(helm("charts/{}".format(APP_NAME), set=[
# Make sure the chart refers to the same image ref as the one we built
Expand All @@ -33,20 +42,13 @@ k8s_yaml(helm("charts/{}".format(APP_NAME), set=[
"autoscaling.enabled=false",
"autoscaling.minReplicas=1",
"replicaCount=1",
"debugger.enabled=true",
"debugger.enabled={}".format("true" if cfg.get("debugger", False) else "false"),
"debugger.host={}".format(host_ip),
]))
k8s_resource(
workload="chart-{}".format(APP_NAME),
resource_deps=["aiven-operator-crds"],
objects=[
"chart-mutilator:mutatingwebhookconfiguration",
"chart-mutilator:networkpolicy",
"chart-mutilator:certificate",
"chart-mutilator:issuer",
"chart-mutilator:service",
"chart-mutilator:endpointslice",
],
objects=mutilator_objects,
)

# Update locally stored certificates from cluster
Expand Down
16 changes: 1 addition & 15 deletions charts/mutilator/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{- if not .Values.debugger.enabled }}
---
apiVersion: v1
kind: Service
Expand All @@ -13,24 +12,11 @@ spec:
targetPort: https
protocol: TCP
name: https
{{- if not .Values.debugger.enabled }}
selector:
{{- include "mutilator.selectorLabels" . | nindent 4 }}
{{- else }}
---
apiVersion: v1
kind: Service
metadata:
labels:
{{- include "mutilator.labels" . | nindent 4 }}
name: {{ include "mutilator.fullname" . }}
spec:
ports:
- name: https
port: 9443
protocol: TCP
targetPort: 9443
type: ClusterIP
---
apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
Expand Down

0 comments on commit a2f839c

Please sign in to comment.