Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile improvements #2660

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-airgap-image-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
description: The airgap image bundle's cache key.
value: ${{ jobs.build.outputs.cache-key }}

env:
MAKEFLAGS: -j

jobs:
build:
name: "${{ inputs.target-os }}-${{ inputs.target-arch }}"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
- CODE_OF_CONDUCT.md
- docs/**

env:
MAKEFLAGS: -j

jobs:
build:
name: Build docs
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-k0s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
required: true
description: The architecture to build k0s for.

env:
MAKEFLAGS: -j

jobs:
build:
name: ${{ inputs.target-os }}-${{ inputs.target-arch }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/check-network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
schedule:
- cron: "0 23 * * *"

env:
MAKEFLAGS: -j

jobs:
check-network:
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ on:
- '.github/workflows/mkdocs-set-default-version.yml'
- 'mkdocs.yml'

env:
MAKEFLAGS: -j

jobs:
prepare:
name: Prepare
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ on:
- 'mkdocs.yml'
- '*.md'

env:
MAKEFLAGS: -j

jobs:
lint:
name: Lint
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ostests-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ env:
# This is hopefully somewhat physically close to where the hosted GitHub runners live.
# https://github.com/orgs/community/discussions/24969#discussioncomment-3246032
AWS_REGION: us-east-1
MAKEFLAGS: -j

jobs:
e2e-tests:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-docs-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
required: true

env:
MAKEFLAGS: -j
PYTHON_VERSION: 3.x
TARGET_VERSION: ${{ github.event.inputs.version }}

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
types:
- published

env:
MAKEFLAGS: -j

jobs:
build:
name: Deploy docs
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- v* # Push events to matching v*, i.e. v1.0, v20.15.10

env:
MAKEFLAGS: -j

jobs:
release:
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/sbom-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
branches:
- main

env:
MAKEFLAGS: -j

jobs:
sbom-upload:
runs-on: ubuntu-latest
Expand Down
57 changes: 34 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,61 @@ $(K0S_GO_BUILD_CACHE):
go.sum: go.mod .k0sbuild.docker-image.k0s
$(GO) mod tidy && touch -c -- '$@'

codegen_targets += pkg/apis/helm/v1beta1/.controller-gen.stamp
controllergen_targets += pkg/apis/helm/v1beta1/.controller-gen.stamp
pkg/apis/helm/v1beta1/.controller-gen.stamp: $(shell find pkg/apis/helm/v1beta1/ -maxdepth 1 -type f -name \*.go)
pkg/apis/helm/v1beta1/.controller-gen.stamp: gen_output_dir = helm

codegen_targets += pkg/apis/k0s/v1beta1/.controller-gen.stamp
controllergen_targets += pkg/apis/k0s/v1beta1/.controller-gen.stamp
pkg/apis/k0s/v1beta1/.controller-gen.stamp: $(shell find pkg/apis/k0s/v1beta1/ -maxdepth 1 -type f -name \*.go)
pkg/apis/k0s/v1beta1/.controller-gen.stamp: gen_output_dir = v1beta1

codegen_targets += pkg/apis/autopilot/v1beta2/.controller-gen.stamp
controllergen_targets += pkg/apis/autopilot/v1beta2/.controller-gen.stamp
pkg/apis/autopilot/v1beta2/.controller-gen.stamp: $(shell find pkg/apis/autopilot/v1beta2/ -maxdepth 1 -type f -name \*.go)
pkg/apis/autopilot/v1beta2/.controller-gen.stamp: gen_output_dir = autopilot

codegen_targets += $(controllergen_targets)
pkg/apis/%/.controller-gen.stamp: .k0sbuild.docker-image.k0s hack/tools/boilerplate.go.txt hack/tools/Makefile.variables
rm -rf 'static/manifests/$(gen_output_dir)/CustomResourceDefinition'
rm -f -- '$(dir $@)'zz_*.go
CGO_ENABLED=0 $(GO) run sigs.k8s.io/controller-tools/cmd/controller-gen@v$(controller-gen_version) \
crd \
paths="./$(dir $@)..." \
output:crd:artifacts:config=./static/manifests/$(gen_output_dir)/CustomResourceDefinition \
object:headerFile=hack/tools/boilerplate.go.txt
mkdir -p 'static/manifests/$(gen_output_dir)'
gendir="$$(mktemp -d .controller-gen.XXXXXX.tmp)" \
&& trap "rm -rf -- $$gendir" INT EXIT \
&& CGO_ENABLED=0 $(GO) run sigs.k8s.io/controller-tools/cmd/controller-gen@v$(controller-gen_version) \
paths="./$(dir $@)..." \
object:headerFile=hack/tools/boilerplate.go.txt output:object:dir="$$gendir" \
crd output:crd:dir='static/manifests/$(gen_output_dir)/CustomResourceDefinition' \
&& mv -f -- "$$gendir"/zz_generated.deepcopy.go '$(dir $@).'
touch -- '$@'

clientset_input_dirs := pkg/apis/autopilot/v1beta2 pkg/apis/k0s/v1beta1 pkg/apis/helm/v1beta1
codegen_targets += pkg/client/clientset/.client-gen.stamp
pkg/client/clientset/.client-gen.stamp: $(shell find $(clientset_input_dirs) -type f -name \*.go -not -name \*_test.go -not -name zz_\*)
pkg/client/clientset/.client-gen.stamp: .k0sbuild.docker-image.k0s hack/tools/boilerplate.go.txt embedded-bins/Makefile.variables
rm -rf -- '$(dir $@)'
CGO_ENABLED=0 $(GO) run k8s.io/code-generator/cmd/client-gen@v$(kubernetes_version:1.%=0.%) \
--go-header-file=hack/tools/boilerplate.go.txt \
--input-base='' \
--input=$(subst $(space),$(comma),$(clientset_input_dirs:%=github.com/k0sproject/k0s/%)) \
--output-package=github.com/k0sproject/k0s/$(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $@)))) \
--clientset-name=$(notdir $(patsubst %/,%,$(dir $@))) \
--output-base=. \
--trim-path-prefix=github.com/k0sproject/k0s
gendir="$$(mktemp -d .client-gen.XXXXXX.tmp)" \
&& trap "rm -rf -- $$gendir" INT EXIT \
&& CGO_ENABLED=0 $(GO) run k8s.io/code-generator/cmd/client-gen@v$(kubernetes_version:1.%=0.%) \
--go-header-file=hack/tools/boilerplate.go.txt \
--input-base='' \
--input=$(subst $(space),$(comma),$(clientset_input_dirs:%=github.com/k0sproject/k0s/%)) \
--output-package=github.com/k0sproject/k0s/pkg/client \
--clientset-name=clientset \
--output-base="$$gendir/out" \
--trim-path-prefix=github.com/k0sproject/k0s \
&& { [ ! -e pkg/client/clientset ] || mv -- pkg/client/clientset "$$gendir/old"; } \
ncopa marked this conversation as resolved.
Show resolved Hide resolved
&& mv -f -- "$$gendir/out/github.com/k0sproject/k0s/pkg/client/clientset" pkg/client/.
touch -- '$@'

codegen_targets += static/zz_generated_assets.go
static_asset_dirs := static/manifests static/misc
static/zz_generated_assets.go: $(controllergen_targets) # to generate the CRDs into static/manifests/*/CustomResourceDefinition
static/zz_generated_assets.go: $(shell find static/manifests/calico static/manifests/windows static/misc -type f)
ncopa marked this conversation as resolved.
Show resolved Hide resolved
static/zz_generated_assets.go: .k0sbuild.docker-image.k0s hack/tools/Makefile.variables
static/zz_generated_assets.go: $(shell find $(static_asset_dirs) -type f)
-rm -f -- '$@'
CGO_ENABLED=0 $(GO) install github.com/kevinburke/go-bindata/go-bindata@v$(go-bindata_version)
$(GO_ENV) go-bindata -o '$@' -pkg static -prefix static $(patsubst %,%/...,$(static_asset_dirs))
CGO_ENABLED=0 $(GO) run github.com/kevinburke/go-bindata/go-bindata@v$(go-bindata_version) \
-o '$@' -pkg static -prefix static \
static/manifests/helm/CustomResourceDefinition/... \
static/manifests/v1beta1/CustomResourceDefinition/... \
static/manifests/autopilot/CustomResourceDefinition/... \
static/manifests/calico/... \
static/manifests/windows/... \
static/misc/...

ifeq ($(EMBEDDED_BINS_BUILDMODE),none)
BUILD_GO_TAGS += noembedbins
Expand Down
8 changes: 6 additions & 2 deletions embedded-bins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct || date -u +%s)
bindir = staging/${TARGET_OS}/bin
posix_bins = runc kubelet containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 kube-apiserver kube-scheduler kube-controller-manager etcd kine konnectivity-server xtables-legacy-multi xtables-nft-multi
windows_bins = kubelet.exe kube-proxy.exe containerd.exe containerd-shim-runhcs-v1.exe
buildmode = docker

ifeq ($(TARGET_OS),windows)
bins = ${windows_bins}
Expand Down Expand Up @@ -65,7 +64,12 @@ $(bindir)/kubelet.exe $(bindir)/kube-proxy.exe: .container.kubernetes.windows
$(bindir)/containerd.exe $(bindir)/containerd-shim-runhcs-v1.exe: .container.containerd.windows

$(addprefix $(bindir)/, $(bins)): | $(bindir)
docker export $$(cat $<) | tar -C $(dir $(bindir)) -xv bin/$(notdir $@) && touch $@
tardir=$$(mktemp -d -- '$(notdir $@).XXXXXX.tmp') \
&& trap "rm -rf -- $$tardir" INT EXIT \
&& docker export "$$(cat $<)" \
| tar -C "$$tardir" -x bin/$(notdir $@) \
&& touch -c -- "$$tardir"/bin/$(notdir $@) \
&& mv "$$tardir"/bin/$(notdir $@) $@

build_docker_container = \
rm -f -- '$@'; \
Expand Down
3 changes: 3 additions & 0 deletions vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

set -eu

# Don't deal with recursive make stuff here!
unset -v MAKEFLAGS MAKELEVEL

from=
var=

Expand Down
Loading