From 20da6e1979b23c443cea014f0e858e9429def03f Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Mon, 14 Oct 2024 18:59:11 +0900 Subject: [PATCH] chore:Updated Dockerfile to include k8s crd manpulation scripts --- Dockerfile | 10 +++++---- tools/k8s/mkllb-url | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100755 tools/k8s/mkllb-url diff --git a/Dockerfile b/Dockerfile index 1482bb3d0..78b81df5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,11 @@ ARG TAG=main ENV PATH="${PATH}:/usr/local/go/bin" ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib64/" +RUN mkdir -p /root/loxilb-io/loxilb +COPY . /root/loxilb-io/loxilb/ + # Install loxilb related packages RUN mkdir -p /opt/loxilb && \ - mkdir -p /root/loxilb-io/loxilb/ && \ mkdir -p /usr/lib64/ && \ mkdir -p /opt/loxilb/cert/ && \ mkdir -p /etc/loxilb/certs/ && \ @@ -45,11 +47,12 @@ RUN mkdir -p /opt/loxilb && \ make && cp ./loxicmd /usr/local/sbin/loxicmd && cd - && rm -fr loxicmd && \ /usr/local/sbin/loxicmd completion bash > /etc/bash_completion.d/loxi_completion && \ # Install loxilb - git clone --recurse-submodules https://github.com/loxilb-io/loxilb /root/loxilb-io/loxilb/ && \ + # git clone --recurse-submodules https://github.com/loxilb-io/loxilb /root/loxilb-io/loxilb/ && \ cd /root/loxilb-io/loxilb/ && git fetch --all --tags && git checkout $TAG && \ cd loxilb-ebpf && git fetch --all --tags && git checkout $TAG && cd .. \ go get . && if [ "$arch" = "arm64" ] ; then DOCKER_BUILDX_ARM64=true make; \ else make ;fi && cp loxilb-ebpf/utils/mkllb_bpffs.sh /usr/local/sbin/mkllb_bpffs && \ + cp tools/k8s/mkllb-url /usr/local/sbin/mkllb-url && \ cp loxilb-ebpf/utils/mkllb_cgroup.sh /usr/local/sbin/mkllb_cgroup && \ cp /root/loxilb-io/loxilb/loxilb-ebpf/kernel/loxilb_dp_debug /usr/local/sbin/loxilb_dp_debug && \ cp /root/loxilb-io/loxilb/loxilb /usr/local/sbin/loxilb && \ @@ -89,14 +92,13 @@ ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib64/" RUN apt-get update && apt-get install -y --no-install-recommends sudo wget \ libbsd-dev iproute2 tcpdump bridge-utils net-tools libllvm10 ca-certificates && \ - wget https://raw.githubusercontent.com/loxilb-io/tools/refs/heads/main/k8s/mkllb-url.sh && \ - chmod +x mkllb-url.sh && mv mkllb-url.sh /usr/local/sbin/mkllb-url && \ rm -rf /var/lib/apt/lists/* && apt clean COPY --from=build /usr/lib64/libbpf* /usr/lib64/ COPY --from=build /usr/local/build/lib/* /usr/lib64 COPY --from=build /usr/local/go/bin /usr/local/go/bin COPY --from=build /usr/local/sbin/mkllb_bpffs /usr/local/sbin/mkllb_bpffs +COPY --from=build /usr/local/sbin/mkllb-url /usr/local/sbin/mkllb-url COPY --from=build /usr/local/sbin/mkllb_cgroup /usr/local/sbin/mkllb_cgroup COPY --from=build /usr/local/sbin/loxilb_dp_debug /usr/local/sbin/loxilb_dp_debug COPY --from=build /usr/local/sbin/loxicmd /usr/local/sbin/loxicmd diff --git a/tools/k8s/mkllb-url b/tools/k8s/mkllb-url new file mode 100755 index 000000000..6e0c0a279 --- /dev/null +++ b/tools/k8s/mkllb-url @@ -0,0 +1,54 @@ +#!/bin/bash + +usage() { + echo "Usage: $0 -a -z -t " + echo " $0 -a -z -t -d" +} + +if [[ $# -gt 7 ]] || [[ $# -lt 6 ]]; then + usage + exit +fi + +if [[ ! -f /usr/local/sbin/kubectl ]]; then + apt-get update && apt-get install -y curl + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/sbin/kubectl +fi + +addr="" +zone="llb" +utype="default" +cmd="apply" + +while getopts a:z:t:x opt +do + case "${opt}" in + a) addr=${OPTARG};; + z) zone=${OPTARG};; + t) utype=${OPTARG};; + x) cmd="delete";; + ?) usage;exit;; + esac +done + +echo "============" +echo "Applying CRD" +echo "============" +echo addr $addr +echo zone $zone +echo utype $utype +echo cmd $cmd +echo "============" + +cat <