Skip to content

Commit 5effd3e

Browse files
authored
Add Go operator (#7)
This is the 1st version of the operator written in Go. Using these operator, users can interact with the cluster. The operator consists of CustomResource, represented by CustomResourceDefinition and controller loop, also called reconciliation loop. Coordinators and data instances are created as StatefulSets. Each coordinator and data instance have two services attached to it, ClusterIP and NodePort. ClusterIP is used for internal communication between instances and NodePort for external access to the Bolt server. Controller tests are deleted since they weren't used. Setup job runs as Deployment. License and organization name should be user-provided in the form of Kubernetes Secret.
1 parent 5046a2b commit 5effd3e

37 files changed

+2875
-155
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
as51340

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ bin
1212
*.swp
1313
*.swo
1414
*~
15+
16+
./manager

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "helm-charts"]
22
path = helm-charts
3-
url = https://github.com/memgraph/helm-charts.git
3+
url = https://github.com/memgraph/helm-charts.git
44
branch = main

.golangci.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
run:
2+
deadline: 5m
3+
allow-parallel-runners: true
4+
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
# restore some of the defaults
10+
# (fill in the rest as needed)
11+
exclude-rules:
12+
- path: "api/*"
13+
linters:
14+
- lll
15+
- path: "internal/*"
16+
linters:
17+
- dupl
18+
- lll
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- exportloopref
25+
- goconst
26+
- gocyclo
27+
- gofmt
28+
- goimports
29+
- gosimple
30+
- govet
31+
- ineffassign
32+
- lll
33+
- misspell
34+
- nakedret
35+
- prealloc
36+
- staticcheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused

.pre-commit-config.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -10,3 +10,9 @@ repos:
1010
- id: mixed-line-ending
1111
- id: check-merge-conflict
1212
- id: detect-private-key
13+
14+
- repo: https://github.com/tekwizely/pre-commit-golang
15+
rev: v1.0.0-rc.1
16+
hooks:
17+
- id: go-mod-tidy
18+
- id: go-fmt

Dockerfile

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
# Build the manager binary
2-
FROM quay.io/operator-framework/helm-operator:v1.35.0
2+
FROM golang:1.22 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
35

4-
ENV HOME=/opt/helm
5-
COPY watches.yaml ${HOME}/watches.yaml
6-
COPY helm-charts ${HOME}/helm-charts
7-
WORKDIR ${HOME}
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY cmd/main.go cmd/main.go
16+
COPY api/ api/
17+
COPY internal/controller/ internal/controller/
18+
19+
# Build
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
25+
26+
# Use distroless as minimal base image to package the manager binary
27+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28+
FROM gcr.io/distroless/static:nonroot
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
32+
33+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)