diff --git a/Makefile b/Makefile index 6b3539076..f0ec49891 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ bin/protoc: unzip protoc-$(PROTOC_VERSION)-linux-x86_64.zip 'bin/*' 'include/*' rm -f protoc-$(PROTOC_VERSION)-linux-x86_64.zip -bin/%/submariner-gateway: main.go $(shell find pkg -not \( -path 'pkg/globalnet*' -o -path 'pkg/routeagent*' \)) pkg/natdiscovery/proto/natdiscovery.pb.go +bin/%/submariner-gateway: main.go $(shell find pkg -not \( -path 'pkg/globalnet*' -o -path 'pkg/routeagent*' -o -path 'pkg/await_node_ready*' \)) pkg/natdiscovery/proto/natdiscovery.pb.go GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ . bin/%/submariner-route-agent: $(shell find pkg/routeagent_driver) @@ -75,6 +75,8 @@ bin/%/submariner-route-agent: $(shell find pkg/routeagent_driver) bin/%/submariner-globalnet: $(shell find pkg/globalnet) GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/globalnet +bin/%/await-node-ready: $(shell find pkg/await_node_ready) + GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/await_node_ready nullstring := space := $(nullstring) # end of the line @@ -84,7 +86,7 @@ comma := , # This can be overridden to build for other supported architectures; the reference is the Go architecture, # so "make images ARCHES=arm" will build a linux/arm/v7 image ARCHES ?= amd64 -BINARIES = submariner-gateway submariner-route-agent submariner-globalnet +BINARIES = submariner-gateway submariner-route-agent submariner-globalnet await-node-ready ARCH_BINARIES := $(foreach arch,$(subst $(comma),$(space),$(ARCHES)),$(foreach binary,$(BINARIES),bin/linux/$(call gotodockerarch,$(arch))/$(binary))) build: $(ARCH_BINARIES) diff --git a/package/Dockerfile.submariner-gateway b/package/Dockerfile.submariner-gateway index aeed28079..e03a493b9 100644 --- a/package/Dockerfile.submariner-gateway +++ b/package/Dockerfile.submariner-gateway @@ -10,6 +10,7 @@ ARG TARGETPLATFORM COPY . ${SOURCE} RUN make -C ${SOURCE} LOCAL_BUILD=1 bin/${TARGETPLATFORM}/submariner-gateway +RUN make -C ${SOURCE} LOCAL_BUILD=1 bin/${TARGETPLATFORM}/await-node-ready FROM --platform=${BUILDPLATFORM} fedora:${FEDORA_VERSION} AS base ARG FEDORA_VERSION @@ -32,7 +33,7 @@ ARG TARGETPLATFORM WORKDIR /var/submariner COPY --from=base /output/gateway / - -COPY --from=builder ${SOURCE}/package/submariner.sh ${SOURCE}/package/pluto ${SOURCE}/bin/${TARGETPLATFORM}/submariner-gateway /usr/local/bin/ +COPY --from=builder ${SOURCE}/package/submariner.sh ${SOURCE}/package/pluto ${SOURCE}/bin/${TARGETPLATFORM}/submariner-gateway \ + ${SOURCE}/package/await-node-ready.sh ${SOURCE}/bin/${TARGETPLATFORM}/await-node-ready /usr/local/bin/ ENTRYPOINT submariner.sh diff --git a/package/Dockerfile.submariner-route-agent b/package/Dockerfile.submariner-route-agent index fd0adda0a..898e2d334 100644 --- a/package/Dockerfile.submariner-route-agent +++ b/package/Dockerfile.submariner-route-agent @@ -10,6 +10,7 @@ ARG TARGETPLATFORM COPY . ${SOURCE} RUN make -C ${SOURCE} LOCAL_BUILD=1 bin/${TARGETPLATFORM}/submariner-route-agent +RUN make -C ${SOURCE} LOCAL_BUILD=1 bin/${TARGETPLATFORM}/await-node-ready FROM --platform=${BUILDPLATFORM} fedora:${FEDORA_VERSION} AS base ARG FEDORA_VERSION @@ -29,8 +30,8 @@ ARG TARGETPLATFORM WORKDIR /var/submariner COPY --from=base /output/route-agent / - -COPY --from=builder ${SOURCE}/package/submariner-route-agent.sh ${SOURCE}/bin/${TARGETPLATFORM}/submariner-route-agent /usr/local/bin/ +COPY --from=builder ${SOURCE}/package/submariner-route-agent.sh ${SOURCE}/bin/${TARGETPLATFORM}/submariner-route-agent \ + ${SOURCE}/package/await-node-ready.sh ${SOURCE}/bin/${TARGETPLATFORM}/await-node-ready /usr/local/bin/ # Wrapper scripts to choose the appropriate iptables # https://github.com/kubernetes-sigs/iptables-wrappers diff --git a/package/await-node-ready.sh b/package/await-node-ready.sh new file mode 100755 index 000000000..383e8734d --- /dev/null +++ b/package/await-node-ready.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e -x + +trap "exit 1" SIGTERM SIGINT + +SUBMARINER_VERBOSITY=${SUBMARINER_VERBOSITY:-2} + +if [ "${SUBMARINER_DEBUG}" == "true" ]; then + DEBUG="-v=3" +else + DEBUG="-v=${SUBMARINER_VERBOSITY}" +fi + +exec await-node-ready ${DEBUG} -alsologtostderr diff --git a/pkg/await_node_ready/main.go b/pkg/await_node_ready/main.go new file mode 100644 index 000000000..95d929b3a --- /dev/null +++ b/pkg/await_node_ready/main.go @@ -0,0 +1,69 @@ +/* +SPDX-License-Identifier: Apache-2.0 + +Copyright Contributors to the Submariner project. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + + "github.com/submariner-io/admiral/pkg/log" + "github.com/submariner-io/admiral/pkg/log/kzerolog" + admversion "github.com/submariner-io/admiral/pkg/version" + "github.com/submariner-io/submariner/pkg/node" + "github.com/submariner-io/submariner/pkg/versions" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/clientcmd" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/manager/signals" +) + +var ( + masterURL string + kubeconfig string + logger = log.Logger{Logger: logf.Log.WithName("main")} + showVersion = false +) + +func main() { + kzerolog.AddFlags(nil) + flag.Parse() + + admversion.Print("await-node-ready", versions.Submariner()) + + if showVersion { + return + } + + kzerolog.InitK8sLogging() + + versions.Log(&logger) + + logger.Info("Initializing K8s client...") + + ctx := signals.SetupSignalHandler() + + cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig) + logger.FatalOnError(err, "Error building kubeconfig") + + k8sClientSet, err := kubernetes.NewForConfig(cfg) + logger.FatalOnError(err, "Error building clientset") + + logger.Info("Awaiting local node ready...") + + node.WaitForLocalNodeReady(ctx, k8sClientSet) +}