forked from k3s-io/cluster-api-k3s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to latest capi; minor clean up; fix docker build (k3s-io#12)
- Loading branch information
Showing
29 changed files
with
869 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,55 @@ | ||
FROM gcr.io/distroless/static:nonroot | ||
# Build the manager binary | ||
# Run this with docker build --build-arg builder_image=<golang:x.y.z> | ||
ARG builder_image | ||
|
||
# Build architecture | ||
ARG ARCH | ||
|
||
# Ignore Hadolint rule "Always tag the version of an image explicitly." | ||
# It's an invalid finding since the image is explicitly set in the Makefile. | ||
# https://github.com/hadolint/hadolint/wiki/DL3006 | ||
# hadolint ignore=DL3006 | ||
FROM ${builder_image} as builder | ||
WORKDIR /workspace | ||
|
||
# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy | ||
ARG goproxy=https://proxy.golang.org | ||
# Run this with docker build --build-arg package=./controlplane/kubeadm or --build-arg package=./bootstrap/kubeadm | ||
ENV GOPROXY=$goproxy | ||
|
||
# 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 --mount=type=cache,target=/go/pkg/mod \ | ||
go mod download | ||
|
||
# Copy the sources | ||
COPY ./ ./ | ||
|
||
# Cache the go build into the Go’s compiler cache folder so we take benefits of compiler caching across docker build calls | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
go build ./bootstrap/main.go | ||
|
||
# Build | ||
ARG package=. | ||
ARG ARCH | ||
ARG ldflags | ||
|
||
# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ | ||
go build -trimpath -ldflags "${ldflags} -extldflags '-static'" \ | ||
-o manager ${package} | ||
|
||
# Production image | ||
FROM gcr.io/distroless/static:nonroot-${ARCH} | ||
WORKDIR / | ||
COPY bin/manager ./ | ||
USER nonroot:nonroot | ||
COPY --from=builder /workspace/manager . | ||
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies | ||
USER 65532 | ||
ENTRYPOINT ["/manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
GO_VERSION ?= 1.19.0 | ||
GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION) | ||
|
||
ARCH ?= $(shell go env GOARCH) | ||
|
||
# Use GOPROXY environment variable if set | ||
GOPROXY := $(shell go env GOPROXY) | ||
ifeq ($(GOPROXY),) | ||
GOPROXY := https://proxy.golang.org | ||
endif | ||
export GOPROXY | ||
|
||
# Active module mode, as we use go modules to manage dependencies | ||
export GO111MODULE=on | ||
|
||
GO_INSTALL := ./hack/go_install.sh | ||
|
||
BIN_DIR := bin | ||
TOOLS_BIN_DIR := $(abspath $(BIN_DIR)) | ||
|
||
|
||
# Image URL to use all building/pushing image targets | ||
BOOTSTRAP_IMG ?= ghcr.io/zawachte/cluster-api-k3s/bootstrap-controller:v0.1.3 | ||
BOOTSTRAP_IMG ?= ghcr.io/zawachte/cluster-api-k3s/bootstrap-controller:v0.1.4 | ||
|
||
# Image URL to use all building/pushing image targets | ||
CONTROLPLANE_IMG ?= ghcr.io/zawachte/cluster-api-k3s/controlplane-controller:v0.1.3 | ||
CONTROLPLANE_IMG ?= ghcr.io/zawachte/cluster-api-k3s/controlplane-controller:v0.1.4 | ||
|
||
|
||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
|
@@ -16,10 +36,14 @@ else | |
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen | ||
CONTROLLER_GEN_BIN = controller-gen | ||
CONTROLLER_GEN_PKG = "sigs.k8s.io/controller-tools/cmd/controller-gen" | ||
CONTROLLER_GEN_VER = "v0.8.0" | ||
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)) | ||
|
||
.PHONY: controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER) | ||
|
||
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
.PHONY: kustomize | ||
|
@@ -82,7 +106,7 @@ generate-bootstrap: controller-gen | |
|
||
# Build the docker image | ||
docker-build-bootstrap: manager-bootstrap | ||
docker build . -t ${BOOTSTRAP_IMG} | ||
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./bootstrap/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${BOOTSTRAP_IMG} | ||
|
||
# Push the docker image | ||
docker-push-bootstrap: | ||
|
@@ -130,22 +154,8 @@ generate-controlplane: controller-gen | |
|
||
# Build the docker image | ||
docker-build-controlplane: manager-controlplane | ||
docker build . -t ${CONTROLPLANE_IMG} | ||
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./controlplane/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${CONTROLPLANE_IMG} | ||
|
||
# Push the docker image | ||
docker-push-controlplane: | ||
docker push ${CONTROLPLANE_IMG} | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef |
3 changes: 1 addition & 2 deletions
3
bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_kthreesconfigs.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_kthreesconfigtemplates.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
controlplane/config/crd/bases/bootstrap.cluster.x-k8s.io_kthreesconfigs.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
controlplane/config/crd/bases/bootstrap.cluster.x-k8s.io_kthreesconfigtemplates.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.