Skip to content

Commit ad454ad

Browse files
authored
Merge pull request #1 from cloudscale-ch/scaffolding
Basic Scaffolding
2 parents 736e2c3 + c07fba2 commit ad454ad

92 files changed

Lines changed: 7354 additions & 0 deletions

File tree

Some content is hidden

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

.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/auto_update.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Auto Update
2+
3+
# The 'kubebuilder alpha update' command requires write access to the repository to create a branch
4+
# with the update files and allow you to open a pull request using the link provided in the issue.
5+
# The branch created will be named in the format kubebuilder-update-from-<from-version>-to-<to-version> by default.
6+
# To protect your codebase, please ensure that you have branch protection rules configured for your
7+
# main branches. This will guarantee that no one can bypass a review and push directly to a branch like 'main'.
8+
permissions:
9+
contents: write # Create and push the update branch
10+
issues: write # Create GitHub Issue with PR link
11+
12+
on:
13+
workflow_dispatch:
14+
schedule:
15+
- cron: "0 0 * * 2" # Every Tuesday at 00:00 UTC
16+
17+
jobs:
18+
auto-update:
19+
runs-on: ubuntu-latest
20+
env:
21+
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
22+
23+
# Checkout the repository.
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
27+
with:
28+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
29+
fetch-depth: 0
30+
persist-credentials: false
31+
32+
# Configure Git to create commits with the GitHub Actions bot.
33+
- name: Configure Git
34+
run: |
35+
git config --global user.name "github-actions[bot]"
36+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
37+
38+
# Set up Go environment.
39+
- name: Set up Go
40+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
41+
with:
42+
go-version: stable
43+
44+
# Install Kubebuilder.
45+
- name: Install Kubebuilder
46+
run: |
47+
curl -L -o kubebuilder "https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)"
48+
chmod +x kubebuilder
49+
sudo mv kubebuilder /usr/local/bin/
50+
kubebuilder version
51+
52+
# Run the Kubebuilder alpha update command.
53+
# More info: https://kubebuilder.io/reference/commands/alpha_update
54+
- name: Run kubebuilder alpha update
55+
# Executes the update command with specified flags.
56+
# --force: Completes the merge even if conflicts occur, leaving conflict markers.
57+
# --push: Automatically pushes the resulting output branch to the 'origin' remote.
58+
# --restore-path: Preserves specified paths (e.g., CI workflow files) when squashing.
59+
# --open-gh-issue: Creates a GitHub Issue with a link for opening a PR for review.
60+
#
61+
# WARNING: This workflow does not use GitHub Models AI summary by default.
62+
# To enable AI-generated summaries in GitHub issues, you need permissions to use GitHub Models.
63+
# If you have the required permissions, re-run:
64+
# kubebuilder edit --plugins="autoupdate/v1-alpha" --use-gh-models
65+
run: |
66+
kubebuilder alpha update \
67+
--force \
68+
--push \
69+
--restore-path .github/workflows \
70+
--open-gh-issue

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Lint
2+
3+
permissions: {}
4+
5+
on:
6+
push:
7+
branches: [main]
8+
pull_request:
9+
10+
jobs:
11+
lint:
12+
name: Run on Ubuntu
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Clone the code
16+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
17+
with:
18+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
19+
fetch-depth: 0
20+
persist-credentials: false
21+
22+
- name: Setup Go
23+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
24+
with:
25+
go-version-file: go.mod
26+
27+
- name: Run linter
28+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
29+
with:
30+
version: v2.8.0

.github/workflows/test-e2e.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: E2E Tests
2+
3+
permissions: {}
4+
5+
on:
6+
workflow_dispatch:
7+
8+
# TODO: Re-enable automatic triggers once e2e tests are working
9+
# push:
10+
# branches: [main]
11+
12+
concurrency:
13+
group: e2e-tests-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
test-e2e:
18+
name: Run on Ubuntu
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Clone the code
22+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
23+
with:
24+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
25+
fetch-depth: 0
26+
persist-credentials: false
27+
28+
- name: Setup Go
29+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
30+
with:
31+
go-version-file: go.mod
32+
33+
- name: Install the latest version of kind
34+
run: |
35+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
36+
chmod +x ./kind
37+
sudo mv ./kind /usr/local/bin/kind
38+
39+
- name: Verify kind installation
40+
run: kind version
41+
42+
- name: Running Test e2e
43+
run: |
44+
go mod tidy
45+
make test-e2e

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tests
2+
3+
permissions: {}
4+
5+
on:
6+
push:
7+
branches: [main]
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
name: Run on Ubuntu
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Clone the code
16+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
17+
with:
18+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
19+
fetch-depth: 0
20+
persist-credentials: false
21+
22+
- name: Setup Go
23+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
24+
with:
25+
go-version-file: go.mod
26+
27+
- name: Running Tests
28+
run: |
29+
go mod tidy
30+
make test

0 commit comments

Comments
 (0)