Skip to content

Commit

Permalink
Rebulding in Go with the Operator SDK (#21)
Browse files Browse the repository at this point in the history
After seeing that the Python `kopf` operator framework is considered not ready
for production use, I decided to go with the more stable and widely used
[Operator SDK](https://sdk.operatorframework.io/) for Go.  This is a reboot and
re-scaffolding the project with the SDK's tools.
  • Loading branch information
chrisguidry authored Aug 12, 2024
1 parent 9f7dab8 commit 2c42f45
Show file tree
Hide file tree
Showing 86 changed files with 4,424 additions and 2,561 deletions.
16 changes: 3 additions & 13 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
.bookkeeping
.coverage
.envrc*
.github
.mypy_cache
.pre-commit-config.yaml
.pytest_cache
.python-version
.vscode
Dockerfile
Makefile
tests
**/*.pyc
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
4 changes: 0 additions & 4 deletions .github/codeql-config.yml

This file was deleted.

59 changes: 0 additions & 59 deletions .github/workflows/docker-images.yaml

This file was deleted.

73 changes: 0 additions & 73 deletions .github/workflows/static-analysis.yaml

This file was deleted.

50 changes: 0 additions & 50 deletions .github/workflows/unit-tests.yaml

This file was deleted.

34 changes: 26 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
.bookkeeping
.coverage
*.egg-info
.mypy_cache
__pycache__
.pytest_cache
.python-version
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*
Dockerfile.cross

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
.vscode
.ruff_cache
*.swp
*.swo
*~
40 changes: 40 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
run:
timeout: 5m
allow-parallel-runners: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
- lll
linters:
disable-all: true
enable:
- dupl
- errcheck
- exportloopref
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- staticcheck
- typecheck
- unconvert
- unparam
- unused
31 changes: 0 additions & 31 deletions .pre-commit-config.yaml

This file was deleted.

53 changes: 33 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
FROM python:3.12.4-slim-bookworm

RUN apt-get update && apt-get install -y git && apt-get clean

WORKDIR /app
ENTRYPOINT [ "prefect-operator" ]
CMD [ "run" ]

RUN pip install -U pip uv

COPY requirements.txt .

RUN uv pip install --system -r requirements.txt

COPY pyproject.toml .
COPY src src

RUN --mount=source=.git,target=.git,type=bind pip install --no-cache-dir -e .

RUN prefect-operator --version
# Build the manager binary
FROM golang:1.21 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
Loading

0 comments on commit 2c42f45

Please sign in to comment.