This port is based on my slack thread in Keptn community here. I am writing it here so that it gets public visibility.

PSA: Using Telepresence V2 with remote Keptn cluster does not work when writing an integration.

Problem/Context

How do you do local development for a Keptn Integration if your laptop/PC cannot handle running a Keptn cluster locally with an IDE like VSCode and a web browser? I recently wrote a blogpost on it here. At the time of writing this post, I was doing this by running a remote cluster on GKE (free trial) and trying to route the requests coming to my Keptn integration (Kubernetes Deployment running in the cluster) to the integration running on my local machine (how? you basically run your binary locally and Telepresence V2 makes your cluster think it is part of Kubernetes networking) but I haven’t been able to do it because the tool that does this (Telepresence V2) does not play well with the distributor sidecar.

Why?

  1. I think this is because the distributor intercepts the events from the NATS queue and passes it on to the Deployment running in the cluster instead of routing it to the go server (i.e., the integration) running on my local machine. When I execute telepresence intercept datadog-service -nkeptn , Telepresence V2 injects a sidecar called traffic agent that intercepts the request and routes it to my local machine but it doesn’t do that if I have distributor running as a sidecar.
    Current
    distributor ➡️ Kubernetes Deployment
    Expected
    distributor ➡️ Telepresence traffic agent ➡️ local machine

How to fix it?

This is a really roundabout solution to the problem (please let me know if you have a better solution) but here it is (TL;DR: you have to use Telepresence V2 with Telepresence V1)

  1. Use Telepresence V2 to make the cluster believe your local machine is part of the cluster using telepresence connect (this does not inject traffic agent sidecar).

Note: You need to rename Telepresence V2 binary to something else to use it with Telepresence V1.

  1. Use Telepresence V1 to swap deployment like this:
1
telepresence --swap-deployment <K8s-Deployment-name> --docker-run --rm -it -v $(pwd):/<dir-you-want-to-use-docker-container> golang:1.16 <- development image for running our code

e.g.,

1
telepresence --swap-deployment datadog-service --docker-run --rm -it -v $(pwd):/dds golang:1.16 

There is no traffic agent which handles routing like in V2 and hence distributor sends the events to the datadog-service Kubernetes Deployment which then routes the requests to my local machine (Telepresence makes your Kubernetes Deployment think the local go server is a part of the Deployment).

Note: I think we can use the default Docker image present in the integration repo and build only the first stage of the image (builder part) but I haven’t tried it yet (I think this is a better approach than using a stock golang image)

  1. You should get a working docker container which copies and syncs all your local code in to the docker container i.e., any code change you make in your IDE is reflected in the docker container because we are using docker volumes. Every time you need to make a code change, you have to re-run go run main.go eventhandlers.go (<- command to run your integration; I think we might be able to do live reload here but I haven’t tried it out yet). So you can do,
1
2
3
4
/<dir-you-want-to-use-docker-container># go run main.go eventhandlers.go
2021/12/24 16:49:37 env=local: Running with local filesystem to fetch resources
2021/12/24 16:49:37 Starting datadog-service...
2021/12/24 16:49:37     on Port = 8080; Path=/

Caveats

This method however has a big caveat which I discovered recently. If your keptn integration tries to send back an event, Keptn doesn’t receive it at all (more details here).