Skip to content

Commit

Permalink
Tilt sharded dev env
Browse files Browse the repository at this point in the history
Signed-off-by: Mangirdas Judeikis <[email protected]>
  • Loading branch information
mjudeikis committed Mar 31, 2024
1 parent 58b4ac5 commit 88c36a2
Show file tree
Hide file tree
Showing 19 changed files with 1,103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tools
build
vendor
goio.yaml
*.kubeconfig

# JetBrains IDE files
.idea/
Expand All @@ -28,3 +29,6 @@ tmp

go.work
go.work.*
go.work.sum

/contrib/tilt/bin/*
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ clean-workdir: ## Clean workdir
download-e2e-logs: ## Download e2e logs from a given URL
OUT=$(OUT) URL=$(URL) hack/download-e2e-logs.sh

tilt-kind-up:
./contrib/tilt/kind.sh

.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
16 changes: 16 additions & 0 deletions contrib/tilt/Dockerfile.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG SHELL=""

FROM alpine

RUN apk --no-cache add ca-certificates \
&& update-ca-certificates ca-certificates-bundle

RUN apk --no-cache add curl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin

WORKDIR /
COPY bin/cache-server .

ENTRYPOINT ["./cache-server"]
20 changes: 20 additions & 0 deletions contrib/tilt/Dockerfile.kcp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG SHELL=""

FROM alpine

RUN apk --no-cache add ca-certificates \
&& update-ca-certificates ca-certificates-bundle
RUN apk --no-cache add curl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin

RUN apk --no-cache add curl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin

WORKDIR /
COPY bin/kcp .

ENTRYPOINT ["./kcp"]
16 changes: 16 additions & 0 deletions contrib/tilt/Dockerfile.proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG SHELL=""

FROM alpine

RUN apk --no-cache add ca-certificates \
&& update-ca-certificates ca-certificates-bundle

RUN apk --no-cache add curl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin

WORKDIR /
COPY bin/kcp-front-proxy .

ENTRYPOINT ["./kcp-front-proxy"]
80 changes: 80 additions & 0 deletions contrib/tilt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# TILT

Tilt setup for KCP development.
The benefit of using Tilt here is that it can be used to build and deploy the KCP
automatically when code changes are detected. It also provides tools like
Prometheus, Grafana, Loki and port forwarding into local machines for debugging.
It uses a helm chart as a base and injects locally built images into kind cluster

## Prerequisites

- [Docker](https://docs.docker.com/get-docker/)
- [Tilt](https://docs.tilt.dev/install.html)
- [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
- [Helm](https://helm.sh/docs/intro/install/)
- [kubectl oidc-login](https://github.com/int128/kubelogin)

## Usage

To start tilt run:

```bash
./contrib/tilt/kind.sh
```
or
```bash
make tilt-kind-up
```

# Output example:
....
Install KCP
Tooling:
Grafana: http://localhost:3333/
Prometheus: http://localhost:9091
KCP API Server: https://localhost:9443
KCP FrontProxy Server: https://localhost:9444
Tilt started on http://localhost:10350/
v0.33.6, built 2023-09-29

(space) to open the browser
(s) to stream logs (--stream=true)
(t) to open legacy terminal mode (--legacy=true)
(ctrl-c) to exit
```
Once the tilt starts, press `space` and track the progress. The first boot might take
a while as it needs to build all the images, run Prometheus, Grafana, loki, etc.
# Login using IDP:
```bash
./contrib/tilt/generate-admin-kubeconfig.sh
export KUBECONFIG=kcp.kubeconfig
# create ws using kcp-admin
kubectl ws create test
# login using oidc
# user: [email protected]
# password: password
kubectl ws use ~ --user oidc
kubectl ws create test --user oidc
```

Check token manually if failed:
```bash
kubectl oidc-login get-token \
--oidc-issuer-url=https://idp.dev.local:6443 \
--oidc-client-id=kcp-dev \
--oidc-client-secret=Z2Fyc2lha2FsYmlzdmFuZGVuekWplCg== \
--insecure-skip-tls-verify=true \
--oidc-extra-scope=email
```

If you get `Unauthorized` error, check if you have cache contamination from previous runs:
```bash
rm -rf ~/.kube/cache/oidc-login
```
Loading

0 comments on commit 88c36a2

Please sign in to comment.