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

🌱 make Cluster API dev tooling to work on arm64 #5547

Merged
merged 1 commit into from
Nov 2, 2021
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ KUBEADM_CONTROL_PLANE_CONTROLLER_IMG ?= $(REGISTRY)/$(KUBEADM_CONTROL_PLANE_IMAG

# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971
TAG ?= dev
ARCH ?= amd64
ARCH ?= $(shell go env GOARCH)
ALL_ARCH = amd64 arm arm64 ppc64le s390x

# Allow overriding the imagePullPolicy
Expand Down
9 changes: 5 additions & 4 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ providers = {
"exp",
"third_party",
],
"additional_docker_helper_commands": """
RUN wget -qO- https://dl.k8s.io/v1.21.2/kubernetes-client-linux-amd64.tar.gz | tar xvz
""",
"additional_docker_helper_commands": "RUN wget -qO- https://dl.k8s.io/v1.21.2/kubernetes-client-linux-{arch}.tar.gz | tar xvz".format(
arch = os_arch,
),
"additional_docker_build_commands": """
COPY --from=tilt-helper /go/kubernetes/client/bin/kubectl /usr/bin/kubectl
""",
Expand Down Expand Up @@ -197,8 +197,9 @@ def enable_provider(name, debug):
else:
gcflags = ""

build_env = "CGO_ENABLED={cgo_enabled} GOOS=linux GOARCH=amd64".format(
build_env = "CGO_ENABLED={cgo_enabled} GOOS=linux GOARCH={arch}".format(
cgo_enabled = cgo_enabled,
arch = os_arch,
)
build_cmd = "{build_env} go build {build_options} -gcflags '{gcflags}' -ldflags '{ldflags}' -o .tiltbuild/manager {go_main}".format(
build_env = build_env,
Expand Down
6 changes: 4 additions & 2 deletions hack/ensure-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ set -x

GOPATH_BIN="$(go env GOPATH)/bin/"
MINIMUM_KIND_VERSION=v0.11.0
goarch="$(go env GOARCH)"
goos="$(go env GOOS)"

# Ensure the kind tool exists and is a viable version, or installs it
verify_kind_version() {

# If kind is not available on the path, get it
if ! [ -x "$(command -v kind)" ]; then
if [[ "${OSTYPE}" == "linux-gnu" ]]; then
if [ "$goos" == "linux" ] || [ "$goos" == "darwin" ]; then
echo 'kind not found, installing'
if ! [ -d "${GOPATH_BIN}" ]; then
mkdir -p "${GOPATH_BIN}"
fi
curl -sLo "${GOPATH_BIN}/kind" https://github.com/kubernetes-sigs/kind/releases/download/${MINIMUM_KIND_VERSION}/kind-linux-amd64
curl -sLo "${GOPATH_BIN}/kind" "https://github.com/kubernetes-sigs/kind/releases/download/${MINIMUM_KIND_VERSION}/kind-${goos}-${goarch}"
chmod +x "${GOPATH_BIN}/kind"
else
echo "Missing required binary in path: kind"
Expand Down
6 changes: 4 additions & 2 deletions hack/ensure-kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ set -o pipefail

GOPATH_BIN="$(go env GOPATH)/bin/"
MINIMUM_KUBECTL_VERSION=v1.19.0
goarch="$(go env GOARCH)"
goos="$(go env GOOS)"

# Ensure the kubectl tool exists and is a viable version, or installs it
verify_kubectl_version() {

# If kubectl is not available on the path, get it
if ! [ -x "$(command -v kubectl)" ]; then
if [[ "${OSTYPE}" == "linux-gnu" ]]; then
if [ "$goos" == "linux" ] || [ "$goos" == "darwin" ]; then
if ! [ -d "${GOPATH_BIN}" ]; then
mkdir -p "${GOPATH_BIN}"
fi
echo 'kubectl not found, installing'
curl -sLo "${GOPATH_BIN}/kubectl" https://dl.k8s.io/release/${MINIMUM_KUBECTL_VERSION}/bin/linux/amd64/kubectl
curl -sLo "${GOPATH_BIN}/kubectl" "https://dl.k8s.io/release/${MINIMUM_KUBECTL_VERSION}/bin/${goos}/${goarch}/kubectl"
chmod +x "${GOPATH_BIN}/kubectl"
else
echo "Missing required binary in path: kubectl"
Expand Down
14 changes: 4 additions & 10 deletions hack/ensure-kustomize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ BIN_ROOT="${KUBE_ROOT}/hack/tools/bin"

kustomize_version=3.9.1

goarch=amd64
goos="unknown"
if [[ "${OSTYPE}" == "linux"* ]]; then
goos="linux"
elif [[ "${OSTYPE}" == "darwin"* ]]; then
goos="darwin"
fi

if [[ "$goos" == "unknown" ]]; then
goarch="$(go env GOARCH)"
goos="$(go env GOOS)"
if [ "$goos" != "linux" ] && [ "$goos" != "darwin" ]; then
echo "OS '$OSTYPE' not supported. Aborting." >&2
exit 1
fi
Expand All @@ -44,7 +38,7 @@ verify_kustomize_version() {
mkdir -p "${BIN_ROOT}"
fi
archive_name="kustomize-v${kustomize_version}.tar.gz"
curl -sLo "${BIN_ROOT}/${archive_name}" https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${kustomize_version}/kustomize_v${kustomize_version}_${goos}_${goarch}.tar.gz
curl -sLo "${BIN_ROOT}/${archive_name}" "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${kustomize_version}/kustomize_v${kustomize_version}_${goos}_${goarch}.tar.gz"
tar -zvxf "${BIN_ROOT}/${archive_name}" -C "${BIN_ROOT}/"
chmod +x "${BIN_ROOT}/kustomize"
rm "${BIN_ROOT}/${archive_name}"
Expand Down
7 changes: 4 additions & 3 deletions scripts/ci-e2e-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
capi:buildDockerImages () {
# Configure provider images generation;
# please ensure the generated image name matches image names used in the E2E_CONF_FILE
ARCH="$(go env GOARCH)"
export REGISTRY=gcr.io/k8s-staging-cluster-api
export TAG=dev
export ARCH=amd64
export ARCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export ARCH
export ARCH="$(go env GOARCH)"

Nit

Copy link
Member Author

@fabriziopandini fabriziopandini Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shell checker was complying when I originally inlined export and $(), this is the suggested solution

Copy link
Member

@sbueringer sbueringer Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that a potential error of go env GOARCH is masked if you have it in one line

export PULL_POLICY=IfNotPresent

## Build all Cluster API provider images, if missing
if [[ "$(docker images -q $REGISTRY/cluster-api-controller-amd64:$TAG 2> /dev/null)" == "" ]]; then
if [[ "$(docker images -q "$REGISTRY/cluster-api-controller-$ARCH:$TAG" 2> /dev/null)" == "" ]]; then
echo "+ Building CAPI images"
make docker-build
else
echo "+ CAPI images already present in the system, skipping make"
fi

## Build CAPD provider images, if missing
if [[ "$(docker images -q $REGISTRY/capd-manager-amd64:$TAG 2> /dev/null)" == "" ]]; then
if [[ "$(docker images -q "$REGISTRY/capd-manager-$ARCH:$TAG" 2> /dev/null)" == "" ]]; then
echo "+ Building CAPD images"
make -C test/infrastructure/docker docker-build
else
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/config/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

images:
# Use local dev images built source tree;
- name: gcr.io/k8s-staging-cluster-api/cluster-api-controller-amd64:dev
- name: gcr.io/k8s-staging-cluster-api/cluster-api-controller-{ARCH}:dev
loadBehavior: tryLoad
- name: gcr.io/k8s-staging-cluster-api/kubeadm-bootstrap-controller-amd64:dev
- name: gcr.io/k8s-staging-cluster-api/kubeadm-bootstrap-controller-{ARCH}:dev
loadBehavior: tryLoad
- name: gcr.io/k8s-staging-cluster-api/kubeadm-control-plane-controller-amd64:dev
- name: gcr.io/k8s-staging-cluster-api/kubeadm-control-plane-controller-{ARCH}:dev
loadBehavior: tryLoad
- name: gcr.io/k8s-staging-cluster-api/capd-manager-amd64:dev
- name: gcr.io/k8s-staging-cluster-api/capd-manager-{ARCH}:dev
loadBehavior: tryLoad
- name: quay.io/jetstack/cert-manager-cainjector:v1.5.3
loadBehavior: tryLoad
Expand Down
3 changes: 3 additions & 0 deletions test/framework/clusterctl/e2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -274,8 +275,10 @@ func (c *E2EConfig) Defaults() {
}
}
}
imageReplacer := strings.NewReplacer("{OS}", runtime.GOOS, "{ARCH}", runtime.GOARCH)
for i := range c.Images {
containerImage := &c.Images[i]
containerImage.Name = imageReplacer.Replace(containerImage.Name)
if containerImage.LoadBehavior == "" {
containerImage.LoadBehavior = MustLoadImage
}
Expand Down
4 changes: 2 additions & 2 deletions test/infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ENV GOPROXY=$goproxy
# Gets additional CAPD dependencies
WORKDIR /tmp

RUN curl -LO https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl && \
RUN curl -LO https://dl.k8s.io/release/v1.22.0/bin/linux/${ARCH}/kubectl && \
chmod +x ./kubectl && \
mv ./kubectl /usr/bin/kubectl

Expand Down Expand Up @@ -55,7 +55,7 @@ WORKDIR /workspace/test/infrastructure/docker
# Build the CAPD manager using 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=amd64 go build -a -o /workspace/manager main.go
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -o /workspace/manager main.go

# NOTE: CAPD can't use non-root because docker requires access to the docker socket
FROM gcr.io/distroless/static:latest
Expand Down
4 changes: 2 additions & 2 deletions test/infrastructure/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ $(KUSTOMIZE): # Build kustomize from tools folder.
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
IMAGE_NAME ?= capd-manager
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64
ARCH ?= $(shell go env GOARCH)
ALL_ARCH = amd64 arm arm64 ppc64le s390x

STAGING_REGISTRY ?= gcr.io/k8s-staging-cluster-api
STAGING_BUCKET ?= artifacts.k8s-staging-cluster-api.appspot.com
Expand Down