Skip to content

Commit da3631f

Browse files
committed
Build environment agnostic changes
1 parent 839df71 commit da3631f

File tree

6 files changed

+72
-20
lines changed

6 files changed

+72
-20
lines changed

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,26 @@ export BIN_OUT ?= $(BUILD_OUT)/bin
1313
# DIST_OUT is the directory containting the distribution packages
1414
export DIST_OUT ?= $(BUILD_OUT)/dist
1515

16-
# Compile Go with boringcrypto. This is required to import crypto/tls/fipsonly package.
17-
export GOEXPERIMENT=boringcrypto
16+
# Detect architecture and conditionally enable FIPS
17+
ARCH ?= $(shell uname -m)
18+
ifeq ($(ARCH),x86_64)
19+
GOARCH := amd64
20+
# Enable FIPS for amd64/x86_64 architecture only
21+
export GOEXPERIMENT=boringcrypto
22+
else ifeq ($(ARCH),aarch64)
23+
GOARCH := arm64
24+
# FIPS not supported on ARM64, disable boringcrypto
25+
export GOEXPERIMENT=
26+
else ifeq ($(ARCH),arm64)
27+
GOARCH := arm64
28+
# FIPS not supported on ARM64, disable boringcrypto
29+
export GOEXPERIMENT=
30+
else
31+
# Default to amd64 for unknown architectures
32+
GOARCH := amd64
33+
export GOEXPERIMENT=boringcrypto
34+
endif
35+
1836

1937

2038
################################################################################

hack/release.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,24 @@ BUILD_RELEASE_TYPE="${BUILD_RELEASE_TYPE:-}"
5151
# Example: CUSTOM_REPO_FOR_GOLANG=<docker-registry>/dockerhub-proxy-cache/library/
5252
GOLANG_IMAGE=${CUSTOM_REPO_FOR_GOLANG:-}golang:1.25.5
5353

54-
ARCH=amd64
54+
# Detect architecture automatically, default to amd64 if not detected
55+
ARCH=${ARCH:-$(uname -m)}
56+
case "$ARCH" in
57+
x86_64)
58+
ARCH=amd64
59+
;;
60+
aarch64|arm64)
61+
ARCH=arm64
62+
;;
63+
armv7l)
64+
ARCH=arm
65+
;;
66+
*)
67+
echo "Warning: Unknown architecture $ARCH, defaulting to amd64"
68+
ARCH=amd64
69+
;;
70+
esac
71+
5572
OSVERSION=1809
5673
# OS Version for the Windows images: 1809, 20H2, ltsc2022
5774
OSVERSION_WIN=(1809 20H2 ltsc2022)
@@ -136,7 +153,7 @@ function build_driver_images_linux() {
136153
--output "${LINUX_IMAGE_OUTPUT}" \
137154
--file images/driver/Dockerfile \
138155
--tag "${tag}" \
139-
--build-arg ARCH=amd64 \
156+
--build-arg ARCH=${ARCH} \
140157
--build-arg "VERSION=${VERSION}" \
141158
--build-arg "GOPROXY=${GOPROXY}" \
142159
--build-arg "GIT_COMMIT=${GIT_COMMIT}" \
@@ -148,6 +165,7 @@ function build_driver_images_linux() {
148165
function build_syncer_image_linux() {
149166
echo "building ${SYNCER_IMAGE_NAME}:${VERSION} for linux"
150167
docker buildx build --platform "linux/$ARCH"\
168+
--output "${LINUX_IMAGE_OUTPUT}" \
151169
-f images/syncer/Dockerfile \
152170
-t "${SYNCER_IMAGE_NAME}":"${VERSION}" \
153171
--build-arg "VERSION=${VERSION}" \

images/driver/Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@ ARG VERSION=unknown
3434
# This build arg controls the GOPROXY setting
3535
ARG GOPROXY
3636

37+
# Architecture detection for conditional FIPS support
38+
ARG TARGETARCH
39+
3740
WORKDIR /build
3841
COPY go.mod go.sum ./
3942
COPY pkg/ pkg/
4043
COPY cmd/ cmd/
4144
ENV CGO_ENABLED=0
42-
ENV GOFIPS=1
43-
ENV GOEXPERIMENT="boringcrypto"
4445
ENV GOPROXY=${GOPROXY:-https://proxy.golang.org}
45-
RUN go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service.Version=${VERSION}" -o vsphere-csi ./cmd/vsphere-csi
46+
47+
# Conditionally set FIPS environment variables based on architecture
48+
# FIPS/boringcrypto is only supported on amd64 architecture
49+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
50+
export GOFIPS=1 && \
51+
export GOEXPERIMENT="boringcrypto"; \
52+
fi && \
53+
go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service.Version=${VERSION}" -o vsphere-csi ./cmd/vsphere-csi
4654

4755
################################################################################
4856
## MAIN STAGE ##

images/syncer/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ARG VERSION=unknown
2929

3030
ARG GOPROXY
3131

32+
# Architecture detection for conditional FIPS support
33+
ARG TARGETARCH
34+
3235
WORKDIR /build
3336

3437
COPY go.mod go.sum ./
@@ -41,11 +44,13 @@ ENV CGO_ENABLED=0
4144

4245
ENV GOPROXY=${GOPROXY:-https://proxy.golang.org}
4346

44-
ENV GOFIPS=1
45-
46-
ENV GOEXPERIMENT="boringcrypto"
47-
48-
RUN go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer.Version=${VERSION}" -o vsphere-syncer ./cmd/syncer
47+
# Conditionally set FIPS environment variables based on architecture
48+
# FIPS/boringcrypto is only supported on amd64 architecture
49+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
50+
export GOFIPS=1 && \
51+
export GOEXPERIMENT="boringcrypto"; \
52+
fi && \
53+
go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer.Version=${VERSION}" -o vsphere-syncer ./cmd/syncer
4954

5055
################################################################################
5156
## MAIN STAGE ##

images/windows/driver/Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
ARG GOLANG_IMAGE=golang:1.25.5
2020
ARG OSVERSION
2121
ARG ARCH=amd64
22+
ARG TARGETARCH
2223

2324
################################################################################
2425
## BUILD STAGE ##
2526
################################################################################
2627
# Build the manager as a statically compiled binary so it has no dependencies
2728
# libc, muscl, etc.
28-
FROM --platform=linux/amd64 ${GOLANG_IMAGE} as builder
29+
FROM --platform=linux/${TARGETARCH:-amd64} ${GOLANG_IMAGE} as builder
2930

3031
# This build arg is the version to embed in the CSI binary
3132
ARG VERSION=unknown
@@ -38,22 +39,26 @@ COPY go.mod go.sum ./
3839
COPY pkg/ pkg/
3940
COPY cmd/ cmd/
4041
ENV CGO_ENABLED=0
41-
ENV GOFIPS=1
42-
ENV GOEXPERIMENT="boringcrypto"
4342
ENV GOPROXY ${GOPROXY:-https://proxy.golang.org}
44-
RUN GOOS=windows GOARCH=amd64 go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service.Version=${VERSION}" -o ./bin/vsphere-csi.windows_amd64 cmd/vsphere-csi/main.go
43+
44+
# Conditionally set FIPS environment variables and build for target architecture
45+
RUN if [ "${TARGETARCH:-amd64}" = "amd64" ]; then \
46+
export GOFIPS=1 && \
47+
export GOEXPERIMENT="boringcrypto"; \
48+
fi && \
49+
GOOS=windows GOARCH=${TARGETARCH:-amd64} go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service.Version=${VERSION}" -o ./bin/vsphere-csi.windows_${TARGETARCH:-amd64} cmd/vsphere-csi/main.go
4550

4651

4752
################################################################################
4853
## MAIN STAGE ##
4954
################################################################################
50-
FROM --platform=linux/amd64 gcr.io/k8s-staging-e2e-test-images/windows-servercore-cache:1.0-linux-${ARCH}-${OSVERSION} as core
55+
FROM --platform=linux/${TARGETARCH:-amd64} gcr.io/k8s-staging-e2e-test-images/windows-servercore-cache:1.0-linux-${TARGETARCH:-amd64}-${OSVERSION} as core
5156

5257
FROM mcr.microsoft.com/windows/nanoserver:${OSVERSION}
5358
COPY --from=core /Windows/System32/netapi32.dll /Windows/System32/netapi32.dll
5459

5560
USER ContainerAdministrator
5661
LABEL description="vSphere CSI Driver Windows Plugin"
5762

58-
COPY --from=builder /build/bin/vsphere-csi.windows_amd64 ./csi.exe
63+
COPY --from=builder /build/bin/vsphere-csi.windows_${TARGETARCH:-amd64} ./csi.exe
5964
ENTRYPOINT ["/csi.exe"]

pkg/syncer/admissionhandler/cnscsi_admissionhandler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package admissionhandler
33
import (
44
"context"
55
"crypto/tls"
6-
7-
_ "crypto/tls/fipsonly"
86
"crypto/x509"
97
"encoding/json"
108
"fmt"

0 commit comments

Comments
 (0)