Skip to content

Commit dfcafb4

Browse files
shaxbeeZibi Mandziejewicz
authored andcommitted
initial commit
0 parents  commit dfcafb4

File tree

116 files changed

+10666
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+10666
-0
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git/
2+
3+
build/
4+
.gitlab/
5+
.vscode/
6+
docs/
7+
hack/
8+
makefiles/
9+
config/
10+
skaffold.yaml

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go.sum binary
2+
api/v1/zz_generated.*.go binary
3+
docs/design/backup/*.svg binary

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
build/
2+
go.work.sum
3+
coverage.xml
4+
5+
# editor and IDE paraphernalia
6+
.idea/
7+
.vscode/
8+
9+
# Binaries for programs and plugins
10+
*.exe
11+
*.exe~
12+
*.dll
13+
*.so
14+
*.dylib
15+
*.test
16+
__debug_bin
17+
testbin/
18+
build.json
19+
.DS_Store
20+
21+
# Test binary, build with `go test -c`
22+
*.swp
23+
*.swo
24+
*~

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# syntax=docker/dockerfile:1
2+
3+
ARG BASE_IMAGE=gcr.io/distroless/base-debian12:nonroot
4+
5+
FROM golang:1.24 AS build
6+
7+
WORKDIR /app
8+
COPY . .
9+
10+
ARG SKAFFOLD_GO_GCFLAGS
11+
ARG GOFLAGS
12+
ARG GOMODCACHE=/go/pkg/mod
13+
ARG GOCACHE=/root/.cache/go-build
14+
RUN --mount=type=cache,target=${GOMODCACHE} \
15+
--mount=type=cache,target=${GOCACHE} \
16+
mkdir -p /etc/etcd/bin && \
17+
go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /etc/etcd/bin/ ./cmd/... && \
18+
go test -o /etc/etcd/bin/etcd-e2e-test -c ./e2e
19+
20+
FROM $BASE_IMAGE
21+
COPY --from=build /etc/etcd/bin /etc/etcd/bin
22+
23+
ENV GOTRACEBACK=all
24+
ENV PATH=${PATH}:/etc/etcd/bin
25+
ENTRYPOINT [ "/etc/etcd/bin/etcd-operator" ]

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# controller-gen args
2+
CONTROLLER_GEN_VERSION = v0.17.1
3+
CONTROLLER_GEN_ARGS := \
4+
paths={./api/...,./pkg/...} \
5+
crd \
6+
object:headerFile=hack/boilerplate.go.txt \
7+
rbac:roleName=etcd-operator \
8+
output:crd:artifacts:config=config/crd
9+
10+
CRDOC_ARGS := \
11+
--resources=config/crd \
12+
--output=docs/api.md
13+
14+
# deployment namespace
15+
SKAFFOLD_NAMESPACE ?= fleet
16+
17+
# explicit package path for coverage
18+
GOCOVERPKG := github.com/agoda-com/etcd-operator/pkg/...
19+
GOTESTARGS := -test.timeout=30m
20+
GOMUTESTARGS := ./pkg
21+
GOLANGCILINT_VERSION := v1.64.8
22+
23+
include makefiles/go.mk
24+
include makefiles/controller.mk
25+
include makefiles/d2.mk
26+
27+
.PHONY: generate fetch-coverage
28+
29+
generate: config/rbac/role.yaml config/e2e/test-role.yaml config/e2e/role.yaml config/e2e/role-binding.yaml
30+
31+
fetch-coverage: $(GOCOVERDIR)
32+
GOCOVERDIR=$(GOCOVERDIR) \
33+
SKAFFOLD_NAMESPACE=$(SKAFFOLD_NAMESPACE) \
34+
SKAFFOLD_RUN_ID=$(SKAFFOLD_RUN_ID) \
35+
makefiles/scripts/skaffold/fetch-coverage app=etcd-operator
36+
37+
.PHONY: config/rbac/role.yaml config/e2e/test-role.yaml
38+
39+
config/rbac/role.yaml:
40+
$(CONTROLLER_GEN) > config/rbac/role.yaml \
41+
paths=./pkg/... \
42+
rbac:roleName=etcd-operator \
43+
output:rbac:stdout
44+
45+
config/e2e/test-role.yaml:
46+
$(CONTROLLER_GEN) > config/e2e/test-role.yaml \
47+
paths=./e2e/... \
48+
rbac:roleName=etcd-test \
49+
output:rbac:stdout
50+
51+
config/e2e/role.yaml: config/rbac/role.yaml
52+
mkdir -p config/e2e
53+
yq -r '.kind = "Role" | .rules = .rules' config/rbac/role.yaml >config/e2e/role.yaml
54+
55+
config/e2e/role-binding.yaml: config/rbac/role-binding.yaml
56+
mkdir -p config/e2e
57+
yq -r '.kind = "RoleBinding"' config/rbac/role-binding.yaml >config/e2e/role-binding.yaml

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# ETCD Operator
2+
3+
## Docs
4+
5+
* [API](/docs/api.md)
6+
* [Backup and Restore](/docs/runbook/backup-restore.md)
7+
* [Defrag](/docs/defrag.md)
8+
* [CA Rotation](/docs/ca-rotation.md)
9+
10+
## Deployment
11+
12+
## Standard
13+
* [config/base](config/base) - cluster-wide operator deployment, does not include RBAC and CRD
14+
* [config/crd](config/crd) - generated Custom Resource Definitions
15+
* [config/rbac](config/rbac) - cluster-wide RBAC
16+
17+
## Profiles
18+
* [config/sandbox](config/sandbox) - single namespace deployment with namespace-scoped RBAC
19+
* [config/e2e](config/e2e) - sandbox with coverage enabled on etcd-operator
20+
21+
## Running locally
22+
23+
### Bootstrap local environment
24+
25+
Operator requires cert-manager and CRDs to be installed in the cluster.
26+
27+
```sh
28+
kustomize build --enable-helm config/bootstrap | kubectl apply -f -
29+
```
30+
31+
### Run
32+
33+
```
34+
skaffold run
35+
```
36+
37+
### Debug
38+
39+
```
40+
skaffold debug
41+
```
42+
43+
VSCode launch configuration:
44+
```json
45+
{
46+
"name": "Skaffold Debug",
47+
"type": "go",
48+
"request": "attach",
49+
"mode": "remote",
50+
"host": "localhost",
51+
"port": 56268,
52+
"substitutePath": [
53+
{
54+
"from": "${workspaceFolder}",
55+
"to": "/workspace",
56+
},
57+
],
58+
```
59+
60+
### Testing
61+
62+
Unit tests only (marked with `t.Short()`):
63+
```sh
64+
make test
65+
```
66+
67+
Unit and integration tests:
68+
```sh
69+
make integration-test
70+
```
71+
72+
End-to-end tests:
73+
```sh
74+
make e2e-test
75+
```
76+
77+
Run end-to-end tests on dev cluster:
78+
```sh
79+
make e2e-test
80+
```
81+
82+
Coverage:
83+
```sh
84+
make test coverage
85+
make integration-test coverage
86+
make e2e-test coverage
87+
```
88+
89+
Output coverage report:
90+
```sh
91+
CODECOV_HTMLFILE=build/coverage.html make integration-test coverage
92+
open build/coverage.html
93+
```

api/go.mod

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module github.com/agoda-com/etcd-operator/api
2+
3+
go 1.24
4+
5+
toolchain go1.24.1
6+
7+
require (
8+
k8s.io/api v0.30.1
9+
k8s.io/apimachinery v0.30.1
10+
sigs.k8s.io/controller-runtime v0.18.2
11+
)
12+
13+
require (
14+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
15+
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
16+
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
17+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
18+
github.com/go-logr/logr v1.4.2 // indirect
19+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
20+
github.com/go-openapi/jsonreference v0.21.0 // indirect
21+
github.com/go-openapi/swag v0.23.0 // indirect
22+
github.com/gogo/protobuf v1.3.2 // indirect
23+
github.com/golang/protobuf v1.5.4 // indirect
24+
github.com/google/gnostic-models v0.6.8 // indirect
25+
github.com/google/gofuzz v1.2.0 // indirect
26+
github.com/google/uuid v1.6.0 // indirect
27+
github.com/imdario/mergo v0.3.16 // indirect
28+
github.com/josharian/intern v1.0.0 // indirect
29+
github.com/json-iterator/go v1.1.12 // indirect
30+
github.com/mailru/easyjson v0.7.7 // indirect
31+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
32+
github.com/modern-go/reflect2 v1.0.2 // indirect
33+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
34+
github.com/pkg/errors v0.9.1 // indirect
35+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
36+
github.com/rogpeppe/go-internal v1.12.0 // indirect
37+
go.uber.org/zap v1.27.0 // indirect
38+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
39+
golang.org/x/net v0.30.0 // indirect
40+
golang.org/x/oauth2 v0.21.0 // indirect
41+
golang.org/x/sys v0.26.0 // indirect
42+
golang.org/x/term v0.25.0 // indirect
43+
golang.org/x/text v0.19.0 // indirect
44+
golang.org/x/time v0.5.0 // indirect
45+
google.golang.org/protobuf v1.34.2 // indirect
46+
gopkg.in/inf.v0 v0.9.1 // indirect
47+
gopkg.in/yaml.v2 v2.4.0 // indirect
48+
gopkg.in/yaml.v3 v3.0.1 // indirect
49+
k8s.io/apiextensions-apiserver v0.30.1 // indirect
50+
k8s.io/client-go v0.30.1 // indirect
51+
k8s.io/klog/v2 v2.130.1 // indirect
52+
k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f // indirect
53+
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect
54+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
55+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
56+
sigs.k8s.io/yaml v1.4.0 // indirect
57+
)

0 commit comments

Comments
 (0)