Skip to content

Commit 89bd8ac

Browse files
mehighlowmatthchr
andauthored
Contributing: arm64 support (Azure#3687)
* Adds anchors for improved navigation * updates dependencies * adds multi -os -arch support * updates git command * sets correct arch of the system. fixes arm64 * reverts verbosity, updates comments * updates macOS instructions * adds multi-arch support * adds multi-arch support * Make hack/crossplane/config folder actually exist * Small fix --------- Co-authored-by: Matthew Christopher <[email protected]>
1 parent 43a5635 commit 89bd8ac

File tree

8 files changed

+142
-36
lines changed

8 files changed

+142
-36
lines changed

.devcontainer/Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# This is pinned to a particular version of go:
44
FROM mcr.microsoft.com/vscode/devcontainers/go:0-1.20
55

6+
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
7+
ARG TARGETARCH
8+
69
# APT dependencies
710
ENV DEBIAN_FRONTEND=noninteractive
811
RUN apt-get update \
@@ -32,7 +35,7 @@ RUN setup-envtest use 1.27.1 --bin-dir /usr/local/envtest/bin
3235
# (entrypoint is only run on start, not on exec). Due to that, the following approaches do not work:
3336
# - ~/.bashrc - only works for one user in a shell but we must support -u $(id -u ${USER}):$(id -g ${USER}) which means the container could run as more than 1 user
3437
# - /etc/profile or /etc/profile.d - only works for one user in a login shell
35-
ENV KUBEBUILDER_ASSETS=/usr/local/envtest/bin/k8s/1.27.1-linux-amd64
38+
ENV KUBEBUILDER_ASSETS=/usr/local/envtest/bin/k8s/1.27.1-linux-${TARGETARCH}
3639
ENV PATH=$KUBEBUILDER_ASSETS:$PATH
3740

3841
# Make kubectl completions work with 'k' alias

.devcontainer/install-dependencies.sh

+36-18
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ if ! [[ $GOMINORVER -ge $GOMINORREQUIRED ]]; then
121121
exit 1
122122
fi
123123

124+
# Define os and arch
125+
os=$(go env GOOS)
126+
arch=$(go env GOARCH)
127+
124128
# Ensure we have AZ
125129

126130
#doc# | AZ | latest | https://docs.microsoft.com/en-us/cli/azure/install-azure-cli |
@@ -134,7 +138,12 @@ write-verbose "Installing tools to $TOOL_DEST"
134138
# Install Go tools
135139
TMPDIR=$(mktemp -d)
136140
clean() {
137-
chmod +w -R "$TMPDIR"
141+
# Macos wants different flag order
142+
if [[ ${os} == "darwin" ]]; then
143+
chmod -R +w "$TMPDIR"
144+
else
145+
chmod +w -R "$TMPDIR"
146+
fi
138147
rm -rf "$TMPDIR"
139148
}
140149
trap clean EXIT
@@ -144,7 +153,7 @@ export GOPATH=$TMPDIR
144153
export GOCACHE=$TMPDIR/cache
145154
export GO111MODULE=on
146155

147-
write-verbose "Installing Go tools"
156+
write-verbose "Installing Go tools..."
148157

149158
# go tools for vscode are preinstalled by base image (see first comment in Dockerfile)
150159

@@ -216,68 +225,77 @@ fi
216225
write-verbose "Checking for $TOOL_DEST/go-task"
217226
if should-install "$TOOL_DEST/task"; then
218227
write-info "Installing go-task"
219-
curl -sL "https://github.com/go-task/task/releases/download/v3.31.0/task_linux_amd64.tar.gz" | tar xz -C "$TOOL_DEST" task
228+
curl -sL "https://github.com/go-task/task/releases/download/v3.31.0/task_${os}_${arch}.tar.gz" | tar xz -C "$TOOL_DEST" task
220229
fi
221230

222231
# Install Trivy
223232
#doc# | Trivy | v0.37.3 | https://trivy.dev/ |
224233
write-verbose "Checking for $TOOL_DEST/trivy"
225234
if should-install "$TOOL_DEST/trivy"; then
226235
write-info "Installing trivy"
227-
curl -sL "https://github.com/aquasecurity/trivy/releases/download/v0.37.3/trivy_0.37.3_Linux-64bit.tar.gz" | tar xz -C "$TOOL_DEST" trivy
236+
# This guys decided to use different naming conventions for os(go env GOOS) and arch(go env GOARCH) despite trivy is 98.6% written in Go
237+
# This fixes macos arm64 architechture. Every other os/arch is named differently. Consider adding a workaround of your own ¯\_(ツ)_/¯
238+
if [[ ${os} == "darwin" ]] && [[ ${arch} == "arm64" ]]; then
239+
curl -sL "https://github.com/aquasecurity/trivy/releases/download/v0.37.3/trivy_0.37.3_macOS-ARM64.tar.gz" | tar xz -C "$TOOL_DEST" trivy
240+
else
241+
curl -sL "https://github.com/aquasecurity/trivy/releases/download/v0.37.3/trivy_0.37.3_Linux-64bit.tar.gz" | tar xz -C "$TOOL_DEST" trivy
242+
fi
228243
fi
229244

230245
# Install helm
231246
#doc# | Helm | v3.8.0 | https://helm.sh/ |
232247
write-verbose "Checking for $TOOL_DEST/helm"
233248
if should-install "$TOOL_DEST/helm"; then
234-
write-info "Installing helm"
235-
curl -sL "https://get.helm.sh/helm-v3.8.0-linux-amd64.tar.gz" | tar -C "$TOOL_DEST" --strip-components=1 -xz linux-amd64/helm
249+
write-info "Installing helm..."
250+
curl -sL "https://get.helm.sh/helm-v3.8.0-${os}-${arch}.tar.gz" | tar -C "$TOOL_DEST" --strip-components=1 -xz ${os}-${arch}/helm
236251
fi
237252

238253
# Install yq
239254
#doc# | YQ | v4.13.0 | https://github.com/mikefarah/yq/ |
240255
yq_version=v4.13.0
241-
yq_binary=yq_linux_amd64
256+
yq_binary=yq_${os}_${arch}
242257
write-verbose "Checking for $TOOL_DEST/yq"
243258
if should-install "$TOOL_DEST/yq"; then
244-
write-info "Installing yq"
259+
write-info "Installing yq..."
245260
rm -f "$TOOL_DEST/yq" # remove yq in case we're forcing the install
246261
wget "https://github.com/mikefarah/yq/releases/download/${yq_version}/${yq_binary}.tar.gz" -O - | tar -xz -C "$TOOL_DEST" && mv "$TOOL_DEST/$yq_binary" "$TOOL_DEST/yq"
247262
fi
248263

249264
# Install cmctl, used to wait for cert manager installation during some tests cases
250265
#doc# | cmctl | latest | https://cert-manager.io/docs/reference/cmctl |
251-
os=$(go env GOOS)
252-
arch=$(go env GOARCH)
253266
write-verbose "Checking for $TOOL_DEST/cmctl"
254267
if should-install "$TOOL_DEST/cmctl"; then
255-
write-info "Installing cmctl-${os}_${arch}"
268+
write-info "Installing cmctl-${os}_${arch}..."
256269
curl -L "https://github.com/jetstack/cert-manager/releases/latest/download/cmctl-${os}-${arch}.tar.gz" | tar -xz -C "$TOOL_DEST"
257270
fi
258271

259272
write-verbose "Checking for $BUILDX_DEST/docker-buildx"
260273
#doc# | BuildX | v0.11.2 | https://github.com/docker/buildx |
261274
if should-install "$BUILDX_DEST/docker-buildx"; then
262-
write-info "Installing buildx-${os}_${arch} to $BUILDX_DEST"
263-
mkdir -p "$BUILDX_DEST"
264-
curl -o "$BUILDX_DEST/docker-buildx" -L "https://github.com/docker/buildx/releases/download/v0.11.2/buildx-v0.11.2.${os}-${arch}"
265-
chmod +x "$BUILDX_DEST/docker-buildx"
275+
write-info "Installing buildx-${os}_${arch} to $BUILDX_DEST ..."
276+
if ! test -f $BUILDX_DEST; then
277+
mkdir -p "$BUILDX_DEST"
278+
fi
279+
if ! test -f $BUILDX_DEST/docker-buildx; then
280+
curl -o "$BUILDX_DEST/docker-buildx" -L "https://github.com/docker/buildx/releases/download/v0.11.2/buildx-v0.11.2.${os}-${arch}"
281+
chmod +x "$BUILDX_DEST/docker-buildx"
282+
fi
266283
fi
267284

268285
# Install azwi
269-
#doc# | AZWI | v1.0.0 | https://github.com/Azure/azure-workload-identity |
286+
#doc# | AZWI | v1.2.0 | https://github.com/Azure/azure-workload-identity |
270287
write-verbose "Checking for $TOOL_DEST/azwi"
271288
if should-install "$TOOL_DEST/azwi"; then
272-
write-info "Installing azwi"
273-
curl -sL "https://github.com/Azure/azure-workload-identity/releases/download/v1.0.0/azwi-v1.0.0-${os}-${arch}.tar.gz" | tar xz -C "$TOOL_DEST" azwi
289+
write-info "Installing azwi..."
290+
curl -sL "https://github.com/Azure/azure-workload-identity/releases/download/v1.2.0/azwi-v1.2.0-${os}-${arch}.tar.gz" | tar xz -C "$TOOL_DEST" azwi
274291
fi
275292

276293
# Ensure tooling for Hugo is available
277294
#doc# | PostCSS | latest | https://postcss.org/ |
278295
write-verbose "Checking for /usr/bin/postcss"
279296
if ! which postcss > /dev/null 2>&1; then
280297
write-info "Installing postcss"
298+
npm config set fund false --location=global
281299
npm install --global postcss postcss-cli autoprefixer
282300
fi
283301

.devcontainer/library-scripts/docker-debian.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ else
6767
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
6868
CODENAME=$(lsb_release -cs)
6969
curl -s https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT)
70-
echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-${DISTRO}-${CODENAME}-prod ${CODENAME} main" > /etc/apt/sources.list.d/microsoft.list
70+
echo "deb [arch=$(go env GOARCH)] https://packages.microsoft.com/repos/microsoft-${DISTRO}-${CODENAME}-prod ${CODENAME} main" > /etc/apt/sources.list.d/microsoft.list
7171
apt-get update
7272
apt-get -y install --no-install-recommends moby-cli moby-buildx
7373
else
7474
curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT)
75-
echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
75+
echo "deb [arch=$(go env GOARCH)] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
7676
apt-get update
7777
apt-get -y install --no-install-recommends docker-ce-cli
7878
fi

Taskfile.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ tasks:
10221022
OBJECT_OPTIONS: object:headerFile={{.HEADER_FILE}}
10231023
CRD_OPTIONS: crd:crdVersions=v1,allowDangerousTypes=true output:crd:artifacts:config={{.CROSSPLANE_OUTPUT}}/crd/bases
10241024
WEBHOOK_OPTIONS: webhook output:webhook:artifacts:config={{.CROSSPLANE_OUTPUT}}/webhook
1025-
RBAC_OPTIONS: rbac:roleName=manager-role # output:rbac:artifacts:config={{.CROSSPLANE_OUTPUT}}/rbac # not output currently?
1025+
RBAC_OPTIONS: rbac:roleName=manager-role output:rbac:artifacts:config={{.CROSSPLANE_OUTPUT}}/rbac
10261026

10271027
crossplane:generate-types:
10281028
desc: Run {{.GENERATOR_APP}} to generate input files for controller-gen for {{.CROSSPLANE_APP}}.

docs/hugo/content/contributing/dependencies.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Developer Dependencies
33
linktitle: Dependencies
44
---
5-
Development of Azure Service Operator depends on a number of development tools and libraries that need to be installed.
5+
Development of Azure Service Operator depends on a number of development tools and libraries that need to be installed.
66

7-
If you prefer to install those dependencies manually (instead of using the `.devcontainer/install-dependencies.sh` script), here is a list of what's required.
7+
If you prefer to install those dependencies manually (instead of using the `.devcontainer/install-dependencies.sh` script), here is a list of what's required.
88

99
| Dependency | Version | Reference |
1010
|:---------- |:-------:|:--------- |
11-
| AZWI | v1.0.0 | https://github.com/Azure/azure-workload-identity |
11+
| AZWI | v1.2.0 | https://github.com/Azure/azure-workload-identity |
1212
| BuildX | v0.11.2 | https://github.com/docker/buildx |
1313
| cmctl | latest | https://cert-manager.io/docs/reference/cmctl |
1414
| controller-gen | v0.13.0 | https://book.kubebuilder.io/reference/controller-gen |

docs/hugo/content/contributing/developer-setup.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ description: "How to set up your developer environment for Azure Service Operato
1010

1111
We support a number of different approaches to ASO development.
1212

13-
- Dev Container with VS Code on Linux
14-
- Dev Container with VS Code on Windows
15-
- Docker on Linux
16-
- CLI on Linux
17-
- CLI on MacOS
13+
- [Dev Container with VS Code on Linux](#dev-container-with-vs-code-on-linux)
14+
- [Dev Container with VS Code on Windows](#dev-container-with-vs-code-on-windows)
15+
- [Docker on Linux](#docker-on-linux)
16+
- [CLI on Linux](#cli-on-linux)
17+
- [CLI on MacOS](#cli-on-macos)
1818

1919
Each of these is described in a different section below. See also the [troubleshooting](#troubleshooting-repo-health) sections below for help with common problems.
2020

@@ -73,19 +73,19 @@ $ docker run --env-file ~/work/envs.env --env HOSTROOT=$(git rev-parse --show-to
7373

7474
Note: If you mount the source like this from a Windows folder, performance will be poor as file operations between the container and Windows are very slow.
7575

76-
7776
## CLI on Linux
7877

7978
If you are using Linux, instead of using VS Code you can run the `dev.sh` script in the root of the repository. This will install all required tooling into the `hack/tools` directory and then start a new shell with the `PATH` updated to use it.
8079

8180
## CLI on MacOS
8281

83-
Development of ASO on MacOS is possible (one of our team does so), but things are less automated.
82+
Development of ASO on MacOS is also possible.
8483

85-
You'll need to manually install the tools as listed by `.devcontainer/install-dependencies.sh`.
84+
You can either use the VS Code devcontainer approach (recommended) which installs all the tools into a container, or you can install the tools directly on your Mac. In case of the latter, you'll need to install the following tools manually running: `.devcontainer/install-dependencies.sh`.
8685

87-
If you have an ARM based Mac, you'll also need to install [Rosetta](https://support.apple.com/en-nz/HT211861).
86+
This creates `hack/tools` and downloads all the required tools into it based on the architecture(arm64 or amd64) of your machine.
8887

88+
If you have an ARM based Mac, you'll also need to install [Rosetta](https://support.apple.com/en-nz/HT211861).
8989

9090
## Troubleshooting: Repo health
9191

@@ -115,7 +115,7 @@ If you see a list of tags (as shown above), then you're good to go.
115115
Otherwise, pull tags from your upstream repo and check again:
116116

117117
``` bash
118-
$ git-fetch --all --tags
118+
$ git fetch --all --tags
119119
Fetching origin
120120
$ git tag --list 'v2*'
121121
v2.0.0

hack/crossplane/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
config/
1+
config/crd
2+
config/rbac/role.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Adds namespace to all resources.
2+
namespace: crossplane-system
3+
4+
# Value of this field is prepended to the
5+
# names of all resources, e.g. a deployment named
6+
# "wordpress" becomes "alices-wordpress".
7+
# Note that it should also match with the prefix (text before '-') of the namespace
8+
# field above.
9+
10+
# Labels to add to all resources and selectors.
11+
#commonLabels:
12+
# someName: someValue
13+
14+
resources: []
15+
16+
bases:
17+
- ../crd
18+
- ../rbac
19+
- ../manager
20+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
21+
# - ../webhook
22+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
23+
- ../certmanager
24+
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
25+
#- ../prometheus
26+
27+
patchesStrategicMerge:
28+
# If you want your controller-manager to expose the /metrics
29+
# endpoint w/o any authn/z, uncomment the following line and
30+
# comment manager_auth_proxy_patch.yaml.
31+
# Only one of manager_auth_proxy_patch.yaml and
32+
# manager_prometheus_metrics_patch.yaml should be enabled.
33+
#- manager_prometheus_metrics_patch.yaml
34+
35+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
36+
# - manager_webhook_patch.yaml
37+
38+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
39+
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
40+
# 'CERTMANAGER' needs to be enabled to use ca injection
41+
# - webhookcainjection_patch.yaml
42+
43+
# - manager_credentials_patch.yaml
44+
45+
patches:
46+
- patch: |-
47+
- op: add
48+
path: /spec/template/spec/containers/0/args/-
49+
value: --webhook-port=9443
50+
- op: add
51+
path: /spec/template/spec/containers/0/args/-
52+
value: --webhook-cert-dir=/tmp/k8s-webhook-server/serving-certs
53+
target:
54+
kind: Deployment
55+
56+
# the following config is for teaching kustomize how to do var substitution
57+
vars:
58+
## [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
59+
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
60+
objref:
61+
kind: Certificate
62+
group: cert-manager.io
63+
version: v1
64+
name: serving-cert # this name should match the one in certificate.yaml
65+
fieldref:
66+
fieldpath: metadata.namespace
67+
- name: CERTIFICATE_NAME
68+
objref:
69+
kind: Certificate
70+
group: cert-manager.io
71+
version: v1
72+
name: serving-cert # this name should match the one in certificate.yaml
73+
- name: SERVICE_NAMESPACE # namespace of the service
74+
objref:
75+
kind: Service
76+
version: v1
77+
name: webhook-service
78+
fieldref:
79+
fieldpath: metadata.namespace
80+
- name: SERVICE_NAME
81+
objref:
82+
kind: Service
83+
version: v1
84+
name: webhook-service

0 commit comments

Comments
 (0)