Skip to content

Commit

Permalink
Merge branch 'main' of github.com:kubewharf/kelemetry into discovery-…
Browse files Browse the repository at this point in the history
…cache-timeout
  • Loading branch information
SOF3 committed Jan 7, 2025
2 parents 07a48df + 59823e0 commit 595dd1f
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 131 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install kind
run: wget --no-verbose -O kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/kind
- name: Install kwok
run: |
KWOK_REPO=kubernetes-sigs/kwok
KWOK_LATEST_RELEASE=$(curl "https://api.github.com/repos/${KWOK_REPO}/releases/latest" | jq -r '.tag_name')
wget -O kwokctl -c "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/kwokctl-linux-amd64" && \
sudo install kwokctl /usr/local/bin/kwokctl && \
wget -O kwok -c "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/kwok-linux-amd64" && \
sudo install kwok /usr/local/bin/kwok
- name: Start test cluster
run: make kind
run: make kwok

- name: Install kubectl
run: |
wget --no-verbose -O kubectl https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && \
chmod +x kubectl && \
sudo mv kubectl /usr/local/bin/kubectl
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
wget --no-verbose -O kubectl https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
sudo install kubectl /usr/local/bin/kubectl
- name: Download docker image
uses: actions/download-artifact@v4
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM golang:1.22.3-alpine AS build

ARG GOPROXY
ARG GOPRIVATE
ARG GONOPROXY
ARG GONOSUMDB

RUN mkdir /src
WORKDIR /src
ADD go.mod go.mod
Expand Down
57 changes: 41 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ else
TAG := $(shell git describe --always)-$(shell git diff --exit-code >/dev/null && echo clean || (echo dirty- && git ls-files | xargs cat --show-all | crc32 /dev/stdin))
endif

.PHONY: run dump-rotate test usage dot kind stack pre-commit fmt local-docker-build e2e
KWOK_VERSION ?= latest

.PHONY: run dump-rotate test usage dot kwok kwok-apiserver-host stack pre-commit fmt local-docker-build e2e
run: output/kelemetry $(DUMP_ROTATE_DEP)
GIN_MODE=debug \
$(RUN_PREFIX) ./output/kelemetry $(RUN_SUFFIX) \
Expand All @@ -93,6 +95,7 @@ run: output/kelemetry $(DUMP_ROTATE_DEP)
--diff-cache-etcd-endpoints=127.0.0.1:2379 \
--diff-cache-wrapper-enable \
--diff-controller-leader-election-enable=false \
--diff-writer-leader-election-enable=false \
--event-informer-leader-election-enable=false \
--span-cache=$(ETCD_OR_LOCAL) \
--span-cache-etcd-endpoints=127.0.0.1:2379 \
Expand Down Expand Up @@ -128,24 +131,39 @@ dot: output/kelemetry
dot -Tpng depgraph.dot >depgraph.png
dot -Tsvg depgraph.dot >depgraph.svg

FIND_PATH =
FIND_PATH =
ifeq ($(OS_NAME), Darwin)
FIND_PATH = .
endif

output/kelemetry: go.mod go.sum $(shell find $(FIND_PATH) -type f -name "*.go")
go build -v $(RACE_ARG) -gcflags=$(GCFLAGS) -ldflags=$(LDFLAGS) -o $@ $(BUILD_ARGS) .

kind:
kind delete cluster --name tracetest
docker network create kind || true # create if not exist; if fail, next step will fail anyway
kwok:
command -v kwokctl || go install sigs.k8s.io/kwok/cmd/kwokctl@$(KWOK_VERSION)
command -v kwok || go install sigs.k8s.io/kwok/cmd/kwok@$(KWOK_VERSION)

[ ! -d ~/.kwok/clusters/tracetest ] || kwokctl delete cluster --name tracetest
for file in audit-kubeconfig tracing-config; do \
cp hack/$${file}.yaml hack/$${file}.local.yaml; \
done

cd hack && kwokctl create cluster --name tracetest --config kwok-cluster.yaml

[[ $(OS_NAME) == Darwin ]] || make kwok-apiserver-host

kubectl --context=kwok-tracetest create -f hack/kwok-node.yaml

kwok-apiserver-host:
sed "s/host.docker.internal/$$( \
docker network inspect kind -f '{{(index .IPAM.Config 0).Gateway}}' \
docker network inspect kwok-tracetest -f '{{(index .IPAM.Config 0).Gateway}}' \
)/g" hack/audit-kubeconfig.yaml >hack/audit-kubeconfig.local.yaml
sed "s/host.docker.internal/$$( \
docker network inspect kind -f '{{(index .IPAM.Config 0).Gateway}}' \
docker network inspect kwok-tracetest -f '{{(index .IPAM.Config 0).Gateway}}' \
)/g" hack/tracing-config.yaml >hack/tracing-config.local.yaml
cd hack && kind create cluster --config kind-cluster.yaml

# Restart apiserver to reload config changes
docker restart kwok-tracetest-kube-apiserver

COMPOSE_COMMAND ?= up --build -d --remove-orphans

Expand All @@ -160,25 +178,32 @@ stack:
$(COMPOSE_COMMAND)

define QUICKSTART_JQ_PATCH
.version = "2.2" |
if $$KELEMETRY_IMAGE == "" then .services.kelemetry.build = "." else . end |
if $$KELEMETRY_IMAGE != "" then .services.kelemetry.image = $$KELEMETRY_IMAGE else . end
if $$KELEMETRY_IMAGE == "" then .services.kelemetry.build |= (.dockerfile = "./Dockerfile" | .context = ".") else . end |
if $$KELEMETRY_IMAGE != "" then .services.kelemetry.image = $$KELEMETRY_IMAGE else . end
endef

SED_I_FLAG =
SED_I_FLAG =
ifeq ($(OS_NAME), Darwin)
SED_I_FLAG = ''
endif

ifneq (, $(shell command -v go))
export GOPROXY=$(shell go env GOPROXY)
export GOPRIVATE=$(shell go env GOPRIVATE)
export GONOPROXY=$(shell go env GONOPROXY)
export GONOSUMDB=$(shell go env GONOSUMDB)
endif

export QUICKSTART_JQ_PATCH
quickstart:
echo $(COMPOSE_COMMAND)
docker compose -f quickstart.docker-compose.yaml \
-f <(jq -n --arg KELEMETRY_IMAGE "$(KELEMETRY_IMAGE)" "$$QUICKSTART_JQ_PATCH") \
up --no-recreate --no-start
kubectl config view --raw --minify --flatten --merge >hack/client-kubeconfig.local.yaml
up --no-recreate --no-start $(BUILD_ARGS)
docker inspect kwok-tracetest-kube-apiserver -f '{{.NetworkSettings.Networks.kelemetry_default}}' | grep kwok-tracetest-kube-apiserver >/dev/null || \
docker network connect kelemetry_default kwok-tracetest-kube-apiserver || true
kubectl --context=kwok-tracetest config view --raw --minify --flatten --merge >hack/client-kubeconfig.local.yaml

sed -i $(SED_I_FLAG) "s/0\.0\.0\.0/$$(docker network inspect kelemetry_default -f '{{(index .IPAM.Config 0).Gateway}}')/g" hack/client-kubeconfig.local.yaml
sed -i $(SED_I_FLAG) "s/127\.0\.0\.1:[0-9]*/kwok-tracetest-kube-apiserver:6443/g" hack/client-kubeconfig.local.yaml
sed -i $(SED_I_FLAG) 's/certificate-authority-data: .*$$/insecure-skip-tls-verify: true/' hack/client-kubeconfig.local.yaml

docker compose -f quickstart.docker-compose.yaml \
Expand Down
1 change: 0 additions & 1 deletion dev.docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# docker-compose setup for development setup.
# Use quickstart.docker-compose.yaml if you just want to try out Kelemetry.
# Use the helm chart if you want to deploy in production.
version: "3"
services:
# ETCD cache storage, only required if etcd cache is used
etcd:
Expand Down
8 changes: 4 additions & 4 deletions docs/DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
The development setup is streamlined into three steps:

1. Ensure the prerequisites are available:
- [kind](https://kind.sigs.k8s.io)
- [kwok](https://kwok.sigs.k8s.io)
- [docker-compose](https://docs.docker.com/compose/install/)

2. Create the kind cluster and dependency services:
2. Create the kwok cluster and dependency services:

```console
$ make kind stack
$ make kwok stack
```

3. Compile and run the kelemetry all-in-one executable:
Expand Down Expand Up @@ -336,7 +336,7 @@ with the following structure:
End-to-end tests can be executed locally with the commands:

```console
$ make kind
$ make kwok
$ make e2e
```

Expand Down
12 changes: 6 additions & 6 deletions docs/QUICK_START.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

Kelemetry requires setting up the audit webhook for kube-apiserver.
To try out Kelemetry, the easiest way is to create a new test cluster
using the pre-made kind config we prepared for Kelemetry setup.
using the pre-made kwok config we prepared for Kelemetry setup.

1. Ensure the prerequisites are available:
- [kind](https://kind.sigs.k8s.io)
- [kwok](https://kwok.sigs.k8s.io)
- [docker-compose](https://docs.docker.com/compose/install/)

2. Run the quickstart scripts:

```console
$ make kind quickstart
$ make kwok quickstart
```

3. Open <http://localhost:16686> in your browser to view the trace output with Jaeger UI.

4. Check out what happens when you deploy!

```console
$ kubectl --context kind-tracetest create deployment hello --image=alpine:latest -- sleep infinity
$ kubectl --context kwok-tracetest create deployment hello --image=alpine:latest -- sleep infinity
deployment.apps/hello created

$ kubectl --context kind-tracetest scale deployment hello --replicas=5
$ kubectl --context kwok-tracetest scale deployment hello --replicas=5
deployment.apps/hello scaled

$ kubectl --context kind-tracetest set image deployments hello alpine=alpine:edge
$ kubectl --context kwok-tracetest set image deployments hello alpine=alpine:edge
deployment.apps/hello image updated
```

Expand Down
2 changes: 1 addition & 1 deletion e2e/deployment/validate.jq
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include "graph";
)
| assert(
"status update was logged";
any(.fields.audit == "system:serviceaccount:kube-system:deployment-controller update status")
any(.fields.audit == "kwok-admin update status")
)
| assert(
"status update contains diff (" + (map(.fields.audit) | @json) + ")";
Expand Down
43 changes: 22 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ toolchain go1.22.3

require (
github.com/coocood/freecache v1.2.4
github.com/daixiang0/gci v0.13.4
github.com/daixiang0/gci v0.13.5
github.com/dlclark/regexp2 v1.11.4
github.com/gin-gonic/gin v1.10.0
github.com/go-logr/logr v1.4.2
github.com/itchyny/gojq v0.12.16
github.com/itchyny/gojq v0.12.17
github.com/jaegertracing/jaeger v1.57.0
github.com/pelletier/go-toml/v2 v2.2.3
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/client_golang v1.20.5
github.com/segmentio/golines v0.12.2
github.com/sirupsen/logrus v1.9.3
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
go.etcd.io/etcd/client/v3 v3.5.16
go.opentelemetry.io/otel v1.30.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0
github.com/stretchr/testify v1.10.0
go.etcd.io/etcd/client/v3 v3.5.17
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/sdk v1.30.0
go.opentelemetry.io/otel/trace v1.30.0
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/trace v1.33.0
go.uber.org/zap v1.27.0
golang.org/x/tools v0.25.0
golang.org/x/tools v0.28.0
google.golang.org/grpc v1.65.0
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
Expand Down Expand Up @@ -149,27 +149,28 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
go.etcd.io/etcd/api/v3 v3.5.16 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.16 // indirect
go.etcd.io/etcd/api/v3 v3.5.17 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
Loading

0 comments on commit 595dd1f

Please sign in to comment.