Skip to content

Commit 8d99bfd

Browse files
committed
fix: properly pick talos client configuration
There was a bug in talosconfig iteration nested loop that `break` was just stopping the internal loop. Also allow building the container with race enabled. Signed-off-by: Artem Chernyshev <[email protected]>
1 parent 1bec112 commit 8d99bfd

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ FROM ghcr.io/talos-systems/fhs:${PKGS} AS pkg-fhs
1515

1616
FROM --platform=${BUILDPLATFORM} ${TOOLS} AS build
1717
SHELL ["/toolchain/bin/bash", "-c"]
18+
ARG CGO_ENABLED
1819
ENV PATH /toolchain/bin:/toolchain/go/bin:/go/bin
1920
RUN ["/toolchain/bin/mkdir", "/bin", "/tmp"]
2021
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/bin/bash", "/bin/sh"]
2122
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/etc/ssl", "/etc/ssl"]
2223
ENV GO111MODULE on
2324
ENV GOPROXY https://proxy.golang.org
24-
ENV CGO_ENABLED 0
2525
ENV GOCACHE /.cache/go-build
2626
ENV GOMODCACHE /.cache/mod
2727
RUN --mount=type=cache,target=/.cache go install sigs.k8s.io/controller-tools/cmd/[email protected]
@@ -67,8 +67,10 @@ COPY --from=release-build /control-plane-components.yaml /control-plane-componen
6767
COPY --from=release-build /metadata.yaml /metadata.yaml
6868

6969
FROM build AS binary
70+
ARG GO_BUILDFLAGS
71+
ARG GO_LDFLAGS
7072
ARG TARGETARCH
71-
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=${TARGETARCH} go build -ldflags "-s -w" -o /manager
73+
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=${TARGETARCH} go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /manager
7274
RUN chmod +x /manager
7375

7476
FROM build AS integration-test-build

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ TAG ?= $(shell git describe --tag --always --dirty)
55
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
66
REGISTRY_AND_USERNAME := $(REGISTRY)/$(USERNAME)
77
NAME := cluster-api-control-plane-talos-controller
8+
WITH_RACE ?= false
9+
CGO_ENABLED = 0
10+
11+
ifneq (, $(filter $(WITH_RACE), t true TRUE y yes 1))
12+
GO_BUILDFLAGS += -race
13+
CGO_ENABLED = 1
14+
GO_LDFLAGS += -linkmode=external -extldflags '-static'
15+
endif
16+
17+
GO_LDFLAGS += -s -w
818

919
ARTIFACTS := _out
1020

@@ -23,6 +33,9 @@ COMMON_ARGS += --build-arg=NAME=$(NAME)
2333
COMMON_ARGS += --build-arg=TAG=$(TAG)
2434
COMMON_ARGS += --build-arg=PKGS=$(PKGS)
2535
COMMON_ARGS += --build-arg=TOOLS=$(TOOLS)
36+
COMMON_ARGS += --build-arg=GO_BUILDFLAGS="$(GO_BUILDFLAGS)"
37+
COMMON_ARGS += --build-arg=GO_LDFLAGS="$(GO_LDFLAGS)"
38+
COMMON_ARGS += --build-arg=CGO_ENABLED="$(CGO_ENABLED)"
2639

2740
all: manifests container
2841

controllers/configs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ func (r *TalosControlPlaneReconciler) talosconfigForMachines(ctx context.Context
118118
return nil, err
119119
}
120120

121+
outer:
121122
for _, cfg := range cfgs.Items {
122123
for _, ref := range cfg.OwnerReferences {
123124
if ref.Kind == "Machine" && ref.Name == machine.Name {
124125
found = &cfg
125-
break
126+
break outer
126127
}
127128
}
128129
}

0 commit comments

Comments
 (0)