Skip to content

Commit 23d69de

Browse files
syscod3claude
andcommitted
feat: initial scaffold — PivotIP CRD, OCI client, reconciler
- PivotIP CRD (pivot.oci.io/v1alpha1): serviceRef, nodeSelector, compartmentId - OCI client using instance principal auth (no API key) - Reconciler: balance-elects node with fewest assignments, creates secondary private IP + reserved public IP, patches Service.spec.externalIPs - Node watcher triggers re-election on readiness change - Finalizer-based cleanup deletes OCI resources on PivotIP deletion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0 parents  commit 23d69de

56 files changed

Lines changed: 4369 additions & 0 deletions

Some content is hidden

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

.custom-gcl.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file configures golangci-lint with module plugins.
2+
# When you run 'make lint', it will automatically build a custom golangci-lint binary
3+
# with all the plugins listed below.
4+
#
5+
# See: https://golangci-lint.run/plugins/module-plugins/
6+
version: v2.8.0
7+
plugins:
8+
# logcheck validates structured logging calls and parameters (e.g., balanced key-value pairs)
9+
- module: "sigs.k8s.io/logtools"
10+
import: "sigs.k8s.io/logtools/logcheck/gclplugin"
11+
version: latest

.devcontainer/devcontainer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "golang:1.25",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
6+
"moby": false,
7+
"dockerDefaultAddressPool": "base=172.30.0.0/16,size=24"
8+
},
9+
"ghcr.io/devcontainers/features/git:1": {},
10+
"ghcr.io/devcontainers/features/common-utils:2": {
11+
"upgradePackages": true
12+
}
13+
},
14+
15+
"runArgs": ["--privileged", "--init"],
16+
17+
"customizations": {
18+
"vscode": {
19+
"settings": {
20+
"terminal.integrated.shell.linux": "/bin/bash"
21+
},
22+
"extensions": [
23+
"ms-kubernetes-tools.vscode-kubernetes-tools",
24+
"ms-azuretools.vscode-docker"
25+
]
26+
}
27+
},
28+
29+
"remoteEnv": {
30+
"GO111MODULE": "on"
31+
},
32+
33+
"onCreateCommand": "bash .devcontainer/post-install.sh"
34+
}
35+

.devcontainer/post-install.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
echo "===================================="
5+
echo "Kubebuilder DevContainer Setup"
6+
echo "===================================="
7+
8+
# Verify running as root (required for installing to /usr/local/bin and /etc)
9+
if [ "$(id -u)" -ne 0 ]; then
10+
echo "ERROR: This script must be run as root"
11+
exit 1
12+
fi
13+
14+
echo ""
15+
echo "Detecting system architecture..."
16+
# Detect architecture using uname
17+
MACHINE=$(uname -m)
18+
case "${MACHINE}" in
19+
x86_64)
20+
ARCH="amd64"
21+
;;
22+
aarch64|arm64)
23+
ARCH="arm64"
24+
;;
25+
*)
26+
echo "WARNING: Unsupported architecture ${MACHINE}, defaulting to amd64"
27+
ARCH="amd64"
28+
;;
29+
esac
30+
echo "Architecture: ${ARCH}"
31+
32+
echo ""
33+
echo "------------------------------------"
34+
echo "Setting up bash completion..."
35+
echo "------------------------------------"
36+
37+
BASH_COMPLETIONS_DIR="/usr/share/bash-completion/completions"
38+
39+
# Enable bash-completion in root's .bashrc (devcontainer runs as root)
40+
if ! grep -q "source /usr/share/bash-completion/bash_completion" ~/.bashrc 2>/dev/null; then
41+
echo 'source /usr/share/bash-completion/bash_completion' >> ~/.bashrc
42+
echo "Added bash-completion to .bashrc"
43+
fi
44+
45+
echo ""
46+
echo "------------------------------------"
47+
echo "Installing development tools..."
48+
echo "------------------------------------"
49+
50+
# Install kind
51+
if ! command -v kind &> /dev/null; then
52+
echo "Installing kind..."
53+
curl -Lo /usr/local/bin/kind "https://kind.sigs.k8s.io/dl/latest/kind-linux-${ARCH}"
54+
chmod +x /usr/local/bin/kind
55+
echo "kind installed successfully"
56+
fi
57+
58+
# Generate kind bash completion
59+
if command -v kind &> /dev/null; then
60+
if kind completion bash > "${BASH_COMPLETIONS_DIR}/kind" 2>/dev/null; then
61+
echo "kind completion installed"
62+
else
63+
echo "WARNING: Failed to generate kind completion"
64+
fi
65+
fi
66+
67+
# Install kubebuilder
68+
if ! command -v kubebuilder &> /dev/null; then
69+
echo "Installing kubebuilder..."
70+
curl -Lo /usr/local/bin/kubebuilder "https://go.kubebuilder.io/dl/latest/linux/${ARCH}"
71+
chmod +x /usr/local/bin/kubebuilder
72+
echo "kubebuilder installed successfully"
73+
fi
74+
75+
# Generate kubebuilder bash completion
76+
if command -v kubebuilder &> /dev/null; then
77+
if kubebuilder completion bash > "${BASH_COMPLETIONS_DIR}/kubebuilder" 2>/dev/null; then
78+
echo "kubebuilder completion installed"
79+
else
80+
echo "WARNING: Failed to generate kubebuilder completion"
81+
fi
82+
fi
83+
84+
# Install kubectl
85+
if ! command -v kubectl &> /dev/null; then
86+
echo "Installing kubectl..."
87+
KUBECTL_VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt)
88+
curl -Lo /usr/local/bin/kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl"
89+
chmod +x /usr/local/bin/kubectl
90+
echo "kubectl installed successfully"
91+
fi
92+
93+
# Generate kubectl bash completion
94+
if command -v kubectl &> /dev/null; then
95+
if kubectl completion bash > "${BASH_COMPLETIONS_DIR}/kubectl" 2>/dev/null; then
96+
echo "kubectl completion installed"
97+
else
98+
echo "WARNING: Failed to generate kubectl completion"
99+
fi
100+
fi
101+
102+
# Generate Docker bash completion
103+
if command -v docker &> /dev/null; then
104+
if docker completion bash > "${BASH_COMPLETIONS_DIR}/docker" 2>/dev/null; then
105+
echo "docker completion installed"
106+
else
107+
echo "WARNING: Failed to generate docker completion"
108+
fi
109+
fi
110+
111+
echo ""
112+
echo "------------------------------------"
113+
echo "Configuring Docker environment..."
114+
echo "------------------------------------"
115+
116+
# Wait for Docker to be ready
117+
echo "Waiting for Docker to be ready..."
118+
for i in {1..30}; do
119+
if docker info >/dev/null 2>&1; then
120+
echo "Docker is ready"
121+
break
122+
fi
123+
if [ "$i" -eq 30 ]; then
124+
echo "WARNING: Docker not ready after 30s"
125+
fi
126+
sleep 1
127+
done
128+
129+
# Create kind network (ignore if already exists)
130+
if ! docker network inspect kind >/dev/null 2>&1; then
131+
if docker network create kind >/dev/null 2>&1; then
132+
echo "Created kind network"
133+
else
134+
echo "WARNING: Failed to create kind network (may already exist)"
135+
fi
136+
fi
137+
138+
echo ""
139+
echo "------------------------------------"
140+
echo "Verifying installations..."
141+
echo "------------------------------------"
142+
kind version
143+
kubebuilder version
144+
kubectl version --client
145+
docker --version
146+
go version
147+
148+
echo ""
149+
echo "===================================="
150+
echo "DevContainer ready!"
151+
echo "===================================="
152+
echo "All development tools installed successfully."
153+
echo "You can now start building Kubernetes operators."

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Check linter configuration
21+
run: make lint-config
22+
- name: Run linter
23+
run: make lint

.github/workflows/test-e2e.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-e2e:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Install the latest version of kind
21+
run: |
22+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
23+
chmod +x ./kind
24+
sudo mv ./kind /usr/local/bin/kind
25+
26+
- name: Verify kind installation
27+
run: kind version
28+
29+
- name: Running Test e2e
30+
run: |
31+
go mod tidy
32+
make test-e2e

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Running Tests
21+
run: |
22+
go mod tidy
23+
make test

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/*
8+
Dockerfile.cross
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Go workspace file
17+
go.work
18+
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
!vendor/**/zz_generated.*
21+
22+
# editor and IDE paraphernalia
23+
.idea
24+
.vscode
25+
*.swp
26+
*.swo
27+
*~
28+
29+
# Kubeconfig might contain secrets
30+
*.kubeconfig

.golangci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: "2"
2+
run:
3+
allow-parallel-runners: true
4+
linters:
5+
default: none
6+
enable:
7+
- copyloopvar
8+
- dupl
9+
- errcheck
10+
- ginkgolinter
11+
- goconst
12+
- gocyclo
13+
- govet
14+
- ineffassign
15+
- lll
16+
- modernize
17+
- misspell
18+
- nakedret
19+
- prealloc
20+
- revive
21+
- staticcheck
22+
- unconvert
23+
- unparam
24+
- unused
25+
- logcheck
26+
settings:
27+
custom:
28+
logcheck:
29+
type: "module"
30+
description: Checks Go logging calls for Kubernetes logging conventions.
31+
revive:
32+
rules:
33+
- name: comment-spacings
34+
- name: import-shadowing
35+
modernize:
36+
disable:
37+
- omitzero
38+
exclusions:
39+
generated: lax
40+
rules:
41+
- linters:
42+
- lll
43+
path: api/*
44+
- linters:
45+
- dupl
46+
- lll
47+
path: internal/*
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$
52+
formatters:
53+
enable:
54+
- gofmt
55+
- goimports
56+
exclusions:
57+
generated: lax
58+
paths:
59+
- third_party$
60+
- builtin$
61+
- examples$

0 commit comments

Comments
 (0)