Skip to content

Commit

Permalink
fix: properly pick talos client configuration
Browse files Browse the repository at this point in the history
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 <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Nov 9, 2021
1 parent 61fb582 commit b8db449
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ FROM ghcr.io/talos-systems/fhs:${PKGS} AS pkg-fhs

FROM --platform=${BUILDPLATFORM} ${TOOLS} AS build
SHELL ["/toolchain/bin/bash", "-c"]
ARG CGO_ENABLED
ENV PATH /toolchain/bin:/toolchain/go/bin:/go/bin
RUN ["/toolchain/bin/mkdir", "/bin", "/tmp"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/bin/bash", "/bin/sh"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/etc/ssl", "/etc/ssl"]
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org
ENV CGO_ENABLED 0
ENV GOCACHE /.cache/go-build
ENV GOMODCACHE /.cache/mod
RUN --mount=type=cache,target=/.cache go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0
Expand Down Expand Up @@ -67,8 +67,10 @@ COPY --from=release-build /control-plane-components.yaml /control-plane-componen
COPY --from=release-build /metadata.yaml /metadata.yaml

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

FROM build AS integration-test-build
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ TAG ?= $(shell git describe --tag --always --dirty)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
REGISTRY_AND_USERNAME := $(REGISTRY)/$(USERNAME)
NAME := cluster-api-control-plane-talos-controller
WITH_RACE ?= false
CGO_ENABLED = 0

ifneq (, $(filter $(WITH_RACE), t true TRUE y yes 1))
GO_BUILDFLAGS += -race
CGO_ENABLED = 1
GO_LDFLAGS += -linkmode=external -extldflags '-static'
endif

GO_LDFLAGS += -s -w

ARTIFACTS := _out

Expand All @@ -23,6 +33,9 @@ COMMON_ARGS += --build-arg=NAME=$(NAME)
COMMON_ARGS += --build-arg=TAG=$(TAG)
COMMON_ARGS += --build-arg=PKGS=$(PKGS)
COMMON_ARGS += --build-arg=TOOLS=$(TOOLS)
COMMON_ARGS += --build-arg=GO_BUILDFLAGS="$(GO_BUILDFLAGS)"
COMMON_ARGS += --build-arg=GO_LDFLAGS="$(GO_LDFLAGS)"
COMMON_ARGS += --build-arg=CGO_ENABLED="$(CGO_ENABLED)"

all: manifests container

Expand Down
3 changes: 2 additions & 1 deletion controllers/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ func (r *TalosControlPlaneReconciler) talosconfigForMachines(ctx context.Context
return nil, err
}

outer:
for _, cfg := range cfgs.Items {
for _, ref := range cfg.OwnerReferences {
if ref.Kind == "Machine" && ref.Name == machine.Name {
found = &cfg
break
break outer
}
}
}
Expand Down

0 comments on commit b8db449

Please sign in to comment.