Skip to content

Commit 8a89641

Browse files
authored
Merge pull request #2 from lllamnyp/feat/helm-packaging
Package as Helm, publish images to ghcr.io
2 parents ac62790 + 61dd1d0 commit 8a89641

54 files changed

Lines changed: 286 additions & 1769 deletions

Some content is hidden

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

‎.github/workflows/release.yml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ['v*']
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
env:
13+
IMAGE: ghcr.io/${{ github.repository }}
14+
15+
jobs:
16+
image:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: docker/setup-qemu-action@v3
22+
- uses: docker/setup-buildx-action@v3
23+
24+
- uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- id: meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ${{ env.IMAGE }}
34+
tags: |
35+
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
36+
type=sha,prefix=main-,enable=${{ github.ref == 'refs/heads/main' }}
37+
type=semver,pattern={{version}}
38+
type=semver,pattern={{major}}.{{minor}}
39+
40+
- id: build
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
platforms: linux/amd64,linux/arm64
45+
tags: ${{ steps.meta.outputs.tags }}
46+
push: true
47+
cache-from: type=gha
48+
cache-to: type=gha,mode=max
49+
50+
- name: report digest
51+
run: |
52+
{
53+
echo "## address-controller image"
54+
echo ""
55+
echo "\`\`\`"
56+
echo "${{ env.IMAGE }}@${{ steps.build.outputs.digest }}"
57+
echo "\`\`\`"
58+
} >> "$GITHUB_STEP_SUMMARY"

‎.github/workflows/test-e2e.yml‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎Dockerfile‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
# Build the manager binary
2-
FROM docker.io/golang:1.23 AS builder
3-
ARG TARGETOS
4-
ARG TARGETARCH
1+
# syntax=docker/dockerfile:1
52

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
3+
# Pin the builder to the native build platform and cross-compile via GOARCH;
4+
# otherwise buildx runs the toolchain under QEMU for the arm64 leg (glacial).
5+
FROM --platform=$BUILDPLATFORM docker.io/golang:1.26 AS build
6+
WORKDIR /src
7+
COPY go.mod go.sum ./
128
RUN go mod download
13-
14-
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
9+
COPY cmd/ cmd/
1610
COPY api/ api/
1711
COPY internal/ internal/
12+
ARG TARGETARCH
13+
RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} go build -trimpath -o /out/manager ./cmd
1814

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
2815
FROM gcr.io/distroless/static:nonroot
29-
WORKDIR /
30-
COPY --from=builder /workspace/manager .
16+
COPY --from=build /out/manager /manager
3117
USER 65532:65532
32-
3318
ENTRYPOINT ["/manager"]

‎Makefile‎

Lines changed: 39 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
# Image URL to use all building/pushing image targets
2-
IMG ?= controller:latest
1+
# address-controller — core controllers for IP addresses as a first-class
2+
# resource (IPAddressClass / IPAddress / IPAddressClaim).
3+
4+
# Image coordinates. TAG defaults to something unique per commit; override for
5+
# releases (e.g. make docker-push TAG=v0.1.0) or floating tags (TAG=main).
6+
IMG_REPO ?= ghcr.io/lllamnyp/address-controller
7+
TAG ?= $(shell git describe --tags --always --dirty)
8+
IMG ?= $(IMG_REPO):$(TAG)
9+
PLATFORMS ?= linux/amd64,linux/arm64
10+
11+
CHART := chart/address-controller
12+
# Chart.yaml carries a 0.0.0 placeholder; the real version is stamped here.
13+
CHART_VERSION ?= 0.1.0
314

415
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
516
ifeq (,$(shell go env GOBIN))
@@ -9,9 +20,6 @@ GOBIN=$(shell go env GOBIN)
920
endif
1021

1122
# CONTAINER_TOOL defines the container tool to be used for building images.
12-
# Be aware that the target commands are only tested with Docker which is
13-
# scaffolded by default. However, you might want to replace it to use other
14-
# tools. (i.e. podman)
1523
CONTAINER_TOOL ?= docker
1624

1725
# Setting SHELL to bash allows bash commands to be executed by recipes.
@@ -24,26 +32,17 @@ all: build
2432

2533
##@ General
2634

27-
# The help target prints out all targets with their descriptions organized
28-
# beneath their categories. The categories are represented by '##@' and the
29-
# target descriptions by '##'. The awk command is responsible for reading the
30-
# entire set of makefiles included in this invocation, looking for lines of the
31-
# file as xyz: ## something, and then pretty-format the target and help. Then,
32-
# if there's a line with ##@ something, that gets pretty-printed as a category.
33-
# More info on the usage of ANSI control characters for terminal formatting:
34-
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
35-
# More info on the awk command:
36-
# http://linuxcommand.org/lc3_adv_awk.php
37-
3835
.PHONY: help
3936
help: ## Display this help.
4037
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
4138

4239
##@ Development
4340

4441
.PHONY: manifests
45-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
46-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
42+
manifests: controller-gen ## Generate the CRDs and the ClusterRole straight into the Helm chart.
43+
$(CONTROLLER_GEN) rbac:roleName=address-controller crd paths="./..." \
44+
output:crd:artifacts:config=$(CHART)/crds \
45+
output:rbac:artifacts:config=$(CHART)/templates
4746

4847
.PHONY: generate
4948
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -61,23 +60,6 @@ vet: ## Run go vet against code.
6160
test: manifests generate fmt vet setup-envtest ## Run tests.
6261
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
6362

64-
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
65-
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
66-
# Prometheus and CertManager are installed by default; skip with:
67-
# - PROMETHEUS_INSTALL_SKIP=true
68-
# - CERT_MANAGER_INSTALL_SKIP=true
69-
.PHONY: test-e2e
70-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
71-
@command -v kind >/dev/null 2>&1 || { \
72-
echo "Kind is not installed. Please install Kind manually."; \
73-
exit 1; \
74-
}
75-
@kind get clusters | grep -q 'kind' || { \
76-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
77-
exit 1; \
78-
}
79-
go test ./test/e2e/ -v -ginkgo.v
80-
8163
.PHONY: lint
8264
lint: golangci-lint ## Run golangci-lint linter
8365
$(GOLANGCI_LINT) run
@@ -86,10 +68,6 @@ lint: golangci-lint ## Run golangci-lint linter
8668
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
8769
$(GOLANGCI_LINT) run --fix
8870

89-
.PHONY: lint-config
90-
lint-config: golangci-lint ## Verify golangci-lint linter configuration
91-
$(GOLANGCI_LINT) config verify
92-
9371
##@ Build
9472

9573
.PHONY: build
@@ -100,62 +78,40 @@ build: manifests generate fmt vet ## Build manager binary.
10078
run: manifests generate fmt vet ## Run a controller from your host.
10179
go run ./cmd/main.go
10280

103-
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
104-
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
105-
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
10681
.PHONY: docker-build
107-
docker-build: ## Build docker image with the manager.
108-
$(CONTAINER_TOOL) build -t ${IMG} .
82+
docker-build: ## Build the controller image for the host platform.
83+
$(CONTAINER_TOOL) build -t $(IMG) .
10984

11085
.PHONY: docker-push
111-
docker-push: ## Push docker image with the manager.
112-
$(CONTAINER_TOOL) push ${IMG}
113-
114-
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
115-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
116-
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
117-
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
118-
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
119-
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
120-
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
86+
docker-push: ## Push the controller image.
87+
$(CONTAINER_TOOL) push $(IMG)
88+
12189
.PHONY: docker-buildx
122-
docker-buildx: ## Build and push docker image for the manager for cross-platform support
123-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
124-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
125-
- $(CONTAINER_TOOL) buildx create --name address-controller-builder
126-
$(CONTAINER_TOOL) buildx use address-controller-builder
127-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
128-
- $(CONTAINER_TOOL) buildx rm address-controller-builder
129-
rm Dockerfile.cross
130-
131-
.PHONY: build-installer
132-
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
133-
mkdir -p dist
134-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
135-
$(KUSTOMIZE) build config/default > dist/install.yaml
90+
docker-buildx: ## Build and push a multi-platform controller image (requires buildx).
91+
$(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) -t $(IMG) .
13692

137-
##@ Deployment
93+
##@ Helm
13894

139-
ifndef ignore-not-found
140-
ignore-not-found = false
141-
endif
95+
.PHONY: helm-lint
96+
helm-lint: ## Lint the chart.
97+
helm lint $(CHART)
14298

143-
.PHONY: install
144-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
145-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
99+
.PHONY: helm-package
100+
helm-package: manifests helm-lint ## Package the chart into dist/ with the version stamped.
101+
mkdir -p dist
102+
helm package $(CHART) --version $(CHART_VERSION) --app-version $(TAG) -d dist
146103

147-
.PHONY: uninstall
148-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
149-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
104+
.PHONY: install-crds
105+
install-crds: manifests ## Apply the CRDs to the cluster in ~/.kube/config (Helm only installs, never upgrades, crds/).
106+
kubectl apply -f $(CHART)/crds
150107

151108
.PHONY: deploy
152-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
153-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
154-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
109+
deploy: manifests ## Install/upgrade the chart into the cluster in ~/.kube/config.
110+
helm upgrade --install address-controller $(CHART) --namespace address-controller-system --create-namespace
155111

156112
.PHONY: undeploy
157-
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
158-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
113+
undeploy: ## Uninstall the chart (CRDs and their objects are left behind by design).
114+
helm uninstall address-controller --namespace address-controller-system
159115

160116
##@ Dependencies
161117

@@ -165,26 +121,18 @@ $(LOCALBIN):
165121
mkdir -p $(LOCALBIN)
166122

167123
## Tool Binaries
168-
KUBECTL ?= kubectl
169-
KUSTOMIZE ?= $(LOCALBIN)/kustomize
170124
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
171125
ENVTEST ?= $(LOCALBIN)/setup-envtest
172126
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
173127

174128
## Tool Versions
175-
KUSTOMIZE_VERSION ?= v5.5.0
176129
CONTROLLER_TOOLS_VERSION ?= v0.17.1
177130
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
178131
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
179132
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
180133
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
181134
GOLANGCI_LINT_VERSION ?= v1.63.4
182135

183-
.PHONY: kustomize
184-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
185-
$(KUSTOMIZE): $(LOCALBIN)
186-
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
187-
188136
.PHONY: controller-gen
189137
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
190138
$(CONTROLLER_GEN): $(LOCALBIN)

‎README.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,34 @@ core controller as follows:
7878
The core controller never touches Services, never parses class parameters,
7979
and never puts a packet on a wire.
8080

81-
## Development
81+
## Installing
82+
83+
Packaged as a Helm chart at [`chart/address-controller`](chart/address-controller)
84+
(no kustomize). The CRDs and the ClusterRole are generated by `make manifests`
85+
straight into the chart — `chart/address-controller/crds/` and
86+
`templates/role.yaml` are controller-gen output, never edited by hand.
87+
88+
```sh
89+
helm upgrade --install address-controller chart/address-controller \
90+
--namespace address-controller-system --create-namespace
91+
```
92+
93+
Helm installs the `crds/` directory on first install but never upgrades it;
94+
after an API change, `make install-crds` applies the current CRDs to the
95+
cluster. `helm uninstall` leaves the CRDs (and every `IPAddress` ledger
96+
entry) behind by design.
8297

83-
Standard kubebuilder project:
98+
The controller image is published as
99+
`ghcr.io/lllamnyp/address-controller:main` (plus `main-<sha>` and semver tags)
100+
by the release workflow on every push to main.
101+
102+
## Development
84103

85104
```sh
86-
make manifests generate # regenerate CRDs and deepcopy after API changes
105+
make manifests generate # regenerate CRDs, ClusterRole, and deepcopy after API changes
87106
make build # build the manager
88107
go test ./internal/controller/
89-
make install # install CRDs into the current kube-context
90108
make run # run the controller locally
109+
make docker-build docker-push # publish ghcr.io/lllamnyp/address-controller:<git-sha>
110+
make helm-package # lint and package the chart into dist/
91111
```

‎api/v1alpha1/ipaddress_types.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ type IPAddressStatus struct {
164164
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
165165
// +kubebuilder:printcolumn:name="ClaimNamespace",type=string,JSONPath=`.spec.claimRef.namespace`
166166
// +kubebuilder:printcolumn:name="Claim",type=string,JSONPath=`.spec.claimRef.name`
167+
// +kubebuilder:printcolumn:name="AttachedTo",type=string,JSONPath=`.status.associatedTo.name`
167168
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
168169

169170
// IPAddress is a concrete address the cluster owns — the inventory object,

0 commit comments

Comments
 (0)