Skip to content

Commit

Permalink
Merge branch 'main' into fix-tag
Browse files Browse the repository at this point in the history
Signed-off-by: Endre Karlson <[email protected]>
  • Loading branch information
ekarlso authored Aug 21, 2023
2 parents 68bf121 + 80058e0 commit 734304d
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GO_VERSION: "1.20"

jobs:
validate:
Expand All @@ -25,6 +26,8 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: "./go.mod"
go-version: "${{ env.GO_VERSION }}"
cache: true

- name: ${{ matrix.target }}
run: make ${{ matrix.target }}
43 changes: 24 additions & 19 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GO_VERSION: '1.20'
GO_VERSION: "1.20"

permissions:
packages: write
contents: write

jobs:
image:
name: Build and push ${{ matrix.target }} image
runs-on: ubuntu-latest
strategy:
matrix:
target: [bootsrap, controlplane]
target: [bootstrap, controlplane]

steps:
- name: Checkout code
Expand Down Expand Up @@ -46,7 +50,7 @@ jobs:
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ env.REGISTRY }}/${{ matrix.target }}-${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.target }}
flavor: latest=false
tags: type=ref,event=tag

Expand All @@ -71,6 +75,7 @@ jobs:
push: true
build-args: |
LDFLAGS=${{ env.DOCKER_BUILD_LDFLAGS }}
package=./${{ matrix.target }}/main.go
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
Expand All @@ -93,7 +98,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-go
- name: Set release
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV

- uses: actions/setup-go@v4
with:
go-version: "${{ env.GO_VERSION }}"
cache: true

- uses: actions/cache@v3
with:
Expand All @@ -108,7 +119,9 @@ jobs:
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-controlplane
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-bootstrap
flavor: latest=false
tags: type=ref,event=tag

Expand All @@ -118,24 +131,16 @@ jobs:
CONTROLPLANE_IMG_TAG=$RELEASE_TAG
make release
- name: Generate Release Notes
run: |
release_notes=$(gh api repos/{owner}/{repo}/releases/generate-notes -F tag_name=${{ github.ref }} --jq .body)
echo 'RELEASE_NOTES<<EOF' >> $GITHUB_ENV
echo "${release_notes}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
- name: manifest
run: make release-notes

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: out/release/*
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false
files: out/*
body_path: _releasenotes/${{ env.RELEASE_TAG }}.md
draft: true
prerelease: false
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/


bin/
out/
out/
_releasenotes
48 changes: 24 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# Build the manager binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build architecture
ARG ARCH
# Build the manager binary
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.20.7 as build
ARG TARGETOS TARGETARCH
ARG package

# 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
Expand All @@ -34,22 +41,15 @@ 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'" \
RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 \
go build -ldflags "${LDFLAGS} -extldflags '-static'" \
-o manager ${package}

# Production image
FROM gcr.io/distroless/static:nonroot-${ARCH}
FROM --platform=${BUILDPLATFORM} gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=build /workspace/manager .
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
USER 65532
ENTRYPOINT ["/manager"]
ENTRYPOINT ["/manager"]
51 changes: 42 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SHELL:=/usr/bin/env bash

.DEFAULT_GOAL:=help

GO_VERSION ?= 1.20.6
GO_VERSION ?= 1.20.7
GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION)

ARCH ?= $(shell go env GOARCH)
Expand Down Expand Up @@ -92,6 +92,32 @@ KUSTOMIZE_VER := v4.0.4
KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER)

## --------------------------------------
## Release
## --------------------------------------

##@ release:

## latest git tag for the commit, e.g., v0.3.10
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
ifneq (,$(findstring -,$(RELEASE_TAG)))
PRE_RELEASE=true
endif
# the previous release tag, e.g., v0.3.9, excluding pre-release tags
PREVIOUS_TAG ?= $(shell git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | sort -V | grep -B1 $(RELEASE_TAG) | head -n 1 2>/dev/null)
## set by Prow, ref name of the base branch, e.g., main
RELEASE_ALIAS_TAG := $(PULL_BASE_REF)
RELEASE_DIR := out
RELEASE_NOTES_DIR := _releasenotes

.PHONY: $(RELEASE_DIR)
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/

.PHONY: $(RELEASE_NOTES_DIR)
$(RELEASE_NOTES_DIR):
mkdir -p $(RELEASE_NOTES_DIR)/


all-bootstrap: manager-bootstrap

Expand Down Expand Up @@ -124,18 +150,17 @@ deploy-bootstrap: manifests-bootstrap
manifests-bootstrap: $(KUSTOMIZE) $(CONTROLLER_GEN)
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=bootstrap/config/crd/bases output:rbac:dir=bootstrap/config/rbac

release-bootstrap: manifests-bootstrap ## Release bootstrap
mkdir -p out
release-bootstrap:$(RELEASE_DIR) manifests-bootstrap ## Release bootstrap
cd bootstrap/config/manager && $(KUSTOMIZE) edit set image controller=${BOOTSTRAP_IMG}
$(KUSTOMIZE) build bootstrap/config/default > out/bootstrap-components.yaml
$(KUSTOMIZE) build bootstrap/config/default > $(RELEASE_DIR)/bootstrap-components.yaml

# Generate code
generate-bootstrap: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="$(shell pwd)/bootstrap/..."

# Build the docker image
docker-build-bootstrap: manager-bootstrap ## Build bootstrap
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}
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./bootstrap/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${BOOTSTRAP_IMG}

# Push the docker image
docker-push-bootstrap: ## Push bootstrap
Expand Down Expand Up @@ -172,21 +197,29 @@ deploy-controlplane: manifests-controlplane
manifests-controlplane: $(KUSTOMIZE) $(CONTROLLER_GEN)
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook crd paths="./..." output:crd:artifacts:config=controlplane/config/crd/bases output:rbac:dir=controlplane/config/rbac

release-controlplane: manifests-controlplane ## Release control-plane
mkdir -p out
release-controlplane: $(RELEASE_DIR) manifests-controlplane ## Release control-plane
cd controlplane/config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLPLANE_IMG}
$(KUSTOMIZE) build controlplane/config/default > out/control-plane-components.yaml
$(KUSTOMIZE) build controlplane/config/default > $(RELEASE_DIR)/control-plane-components.yaml

generate-controlplane: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="$(shell pwd)/controlplane/..."

docker-build-controlplane: manager-controlplane ## Build control-plane
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}
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./controlplane/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${CONTROLPLANE_IMG}

docker-push-controlplane: ## Push control-plane
docker push ${CONTROLPLANE_IMG}

release: release-bootstrap release-controlplane

.PHONY: release-notes
release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES)
if [ -n "${PRE_RELEASE}" ]; then \
echo ":rotating_light: This is a RELEASE CANDIDATE. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/kubernetes-sigs/cluster-api/issues/new)." > $(RELEASE_NOTES_DIR)/$(RELEASE_TAG).md; \
else \
go run ./hack/tools/release/notes.go --from=$(PREVIOUS_TAG) > $(RELEASE_NOTES_DIR)/$(RELEASE_TAG).md; \
fi

## --------------------------------------
## Help
## --------------------------------------
Expand Down
65 changes: 65 additions & 0 deletions bootstrap/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ rules:
- patch
- update
- watch
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- list
- watch
- apiGroups:
- bootstrap.cluster.x-k8s.io
resources:
Expand All @@ -42,16 +50,73 @@ rules:
- patch
- update
- watch
- apiGroups:
- bootstrap.cluster.x-k8s.io
- controlplane.cluster.x-k8s.io
- infrastructure.cluster.x-k8s.io
resources:
- '*'
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- cluster.x-k8s.io
resources:
- clusters
- clusters/status
verbs:
- get
- list
- watch
- apiGroups:
- cluster.x-k8s.io
resources:
- clusters
- clusters/status
- machines
- machines/status
verbs:
- get
- list
- watch
- apiGroups:
- cluster.x-k8s.io
resources:
- machines
- machines/status
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- get
- list
- patch
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- get
- list
- patch
- update
- watch
- apiGroups:
- exp.cluster.x-k8s.io
Expand Down
Loading

0 comments on commit 734304d

Please sign in to comment.