Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create await-node-ready binary and add to gateway and route-agent images #3237

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also uses pkg/node and pkg/versions.

Suggested change
bin/%/await-node-ready: $(shell find pkg/await_node_ready)
bin/%/await-node-ready: $(shell find pkg/await_node_ready pkg/node pkg/versions)

Copy link
Contributor Author

@tpantelis tpantelis Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok but is that needed? Route agent only specifies $(shell find pkg/routeagent_driver) but it uses other packages as well. Same with globalnet - $(shell find pkg/globalnet). The executable binary runs fine locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t affect the binary that gets built, it only determines when it gets rebuilt. But this approach is inherently brittle, I’ve got a better one — let’s merge this and I’ll fix all the binaries properly.

GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/await_node_ready

nullstring :=
space := $(nullstring) # end of the line
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions package/Dockerfile.submariner-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions package/Dockerfile.submariner-route-agent
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions package/await-node-ready.sh
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions pkg/await_node_ready/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading