Skip to content

Commit e9f8db7

Browse files
authored
Merge pull request #2 from ma-hill/HYPERFLEET-1405
HYPERFLEET-1045: Use operator-sdk for scaffolding
2 parents ca018a9 + fb4f958 commit e9f8db7

40 files changed

Lines changed: 1544 additions & 1058 deletions

.devcontainer/devcontainer.json

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
22
"name": "Kubebuilder DevContainer",
3-
"image": "golang:1.26",
3+
"image": "golang:1.24",
44
"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-
}
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
137
},
148

15-
"runArgs": ["--privileged", "--init"],
9+
"runArgs": ["--network=host"],
1610

1711
"customizations": {
1812
"vscode": {
@@ -26,10 +20,6 @@
2620
}
2721
},
2822

29-
"remoteEnv": {
30-
"GO111MODULE": "on"
31-
},
32-
3323
"onCreateCommand": "bash .devcontainer/post-install.sh"
3424
}
3525

.devcontainer/post-install.sh

Lines changed: 13 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,23 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
set -x
33

4-
echo "===================================="
5-
echo "Kubebuilder DevContainer Setup"
6-
echo "===================================="
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
77

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
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
1311

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}"
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
3116

32-
echo ""
33-
echo "------------------------------------"
34-
echo "Setting up bash completion..."
35-
echo "------------------------------------"
17+
docker network create -d=bridge --subnet=172.19.0.0/24 kind
3618

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 "------------------------------------"
14219
kind version
14320
kubebuilder version
144-
kubectl version --client
14521
docker --version
14622
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."
23+
kubectl version --client

.dockerignore

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
11
# 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-
7-
# Re-include source directories
8-
!cmd/
9-
!pkg/
10-
11-
!**/*.go
12-
**/*_test.go
13-
14-
# Re-include Go module files
15-
!go.mod
16-
!go.sum
2+
# Ignore build and test binaries.
3+
bin/

.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: Run linter
21+
uses: golangci/golangci-lint-action@v8
22+
with:
23+
version: v2.1.0

.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-amd64
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

.golangci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ linters:
55
default: none
66
enable:
77
- copyloopvar
8-
- depguard
98
- dupl
109
- errcheck
1110
- ginkgolinter
@@ -14,7 +13,6 @@ linters:
1413
- govet
1514
- ineffassign
1615
- lll
17-
- modernize
1816
- misspell
1917
- nakedret
2018
- prealloc
@@ -24,20 +22,10 @@ linters:
2422
- unparam
2523
- unused
2624
settings:
27-
depguard:
28-
rules:
29-
forbid-sort-pkg:
30-
deny:
31-
- pkg: sort
32-
desc: Should be replaced with slices package
3325
revive:
3426
rules:
3527
- name: comment-spacings
3628
- name: import-shadowing
37-
modernize:
38-
disable:
39-
- omitzero
40-
- newexpr
4129
exclusions:
4230
generated: lax
4331
rules:

0 commit comments

Comments
 (0)