Skip to content

Commit e5a5e31

Browse files
committed
fix: wireguard-go build
1 parent de96cea commit e5a5e31

File tree

5 files changed

+88
-36
lines changed

5 files changed

+88
-36
lines changed

build/liqo/Dockerfile

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,36 @@ FROM alpine:3.20
44
ARG COMPONENT
55
ARG TARGETARCH
66

7+
RUN if [ "$COMPONENT" = "geneve" ] || [ "$COMPONENT" = "wireguard" ] || [ "$COMPONENT" = "gateway" ]; then \
8+
set -x; \
9+
apk add --no-cache iproute2 nftables bash wireguard-tools tcpdump conntrack-tools curl iputils; \
10+
fi
11+
12+
RUN if [ "$COMPONENT" = "wireguard" ]; then \
13+
set -e; \
14+
apk add --no-cache git curl; \
15+
GO_VERSION=1.22.4; \
16+
# Map Docker TARGETARCH to Go architecture names \
17+
case "$TARGETARCH" in \
18+
amd64) GO_ARCH=amd64 ;; \
19+
arm64) GO_ARCH=arm64 ;; \
20+
arm) GO_ARCH=armv6l ;; \
21+
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
22+
esac; \
23+
curl -L https://go.dev/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz | tar -C /usr/local -xz; \
24+
export PATH="/usr/local/go/bin:$PATH"; \
25+
git clone https://git.zx2c4.com/wireguard-go; cd wireguard-go; git checkout f333402bd9cbe0f3eeb02507bd14e23d7d639280; \
26+
CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH /usr/local/go/bin/go build -ldflags="-s -w" -o /usr/bin/wireguard-go; \
27+
cd .. && rm -rf wireguard-go; \
28+
rm -rf /usr/local/go; \
29+
apk del git curl; \
30+
fi
31+
732
# Copy the correct binary for the architecture
833
COPY ./bin/${TARGETARCH}/${COMPONENT}_linux_${TARGETARCH} /usr/bin/${COMPONENT}
934
RUN chmod +x /usr/bin/${COMPONENT}
1035
RUN ln -s /usr/bin/${COMPONENT} /usr/bin/liqo-component
1136

12-
RUN if [ "$COMPONENT" = "geneve" ] || [ "$COMPONENT" = "wireguard" ] || [ "$COMPONENT" = "gateway" ]; then \
13-
apk add --no-cache iproute2 nftables bash wireguard-tools tcpdump conntrack-tools curl iputils; \
14-
fi
15-
1637
WORKDIR /workspace
1738

1839
ENTRYPOINT ["/usr/bin/liqo-component"]

build/liqo/build.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ set -e
44
set -o nounset
55
set -o pipefail
66

7-
usage() {
8-
echo "Usage: $0 [-m] [-p] <component-folder>"
9-
echo " -p Push the built image to the registry"
10-
echo " -h Show this help message"
11-
}
12-
137
if [ $# -ne 1 ]; then
14-
usage
8+
echo "Usage: $0 <component-folder>"
159
exit 1
1610
fi
1711

test/e2e/pipeline/infra/kubeadm/pre-requirements.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
# POD_CIDR_OVERLAPPING -> the pod CIDR of the clusters is overlapping
1919
# CLUSTER_TEMPLATE_FILE -> the file where the cluster template is stored
2020

21-
set -e # Fail in case of error
22-
set -o nounset # Fail if undefined variables are used
23-
set -o pipefail # Fail if one of the piped commands fails
21+
set -e # Fail in case of error
22+
set -o nounset # Fail if undefined variables are used
23+
set -o pipefail # Fail if one of the piped commands fails
2424

2525
error() {
2626
local sourcefile=$1
@@ -43,3 +43,5 @@ install_kubectl "${OS}" "${ARCH}" "${K8S_VERSION}"
4343
install_helm "${OS}" "${ARCH}"
4444

4545
install_clusterctl "${OS}" "${ARCH}"
46+
47+
generate_kubeconfig

test/e2e/pipeline/infra/kubeadm/setup.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
# CLUSTER_TEMPLATE_FILE -> the file where the cluster template is stored
2020
# CNI -> the CNI plugin used
2121

22-
set -e # Fail in case of error
23-
set -o nounset # Fail if undefined variables are used
24-
set -o pipefail # Fail if one of the piped commands fails
22+
set -e # Fail in case of error
23+
set -o nounset # Fail if undefined variables are used
24+
set -o pipefail # Fail if one of the piped commands fails
2525

2626
error() {
27-
local sourcefile=$1
28-
local lineno=$2
29-
echo "An error occurred at $sourcefile:$lineno."
27+
local sourcefile=$1
28+
local lineno=$2
29+
echo "An error occurred at $sourcefile:$lineno."
3030
}
3131
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
3232

@@ -38,7 +38,7 @@ WORKDIR=$(dirname "$FILEPATH")
3838
source "$WORKDIR/../../utils.sh"
3939

4040
# shellcheck disable=SC1091
41-
# shellcheck source=../cni.sh
41+
# shellcheck source=../cni.sh
4242
source "$WORKDIR/../cni.sh"
4343

4444
export K8S_VERSION=${K8S_VERSION:-"1.29.7"}
@@ -56,17 +56,19 @@ export POD_CIDR_OVERLAPPING=${POD_CIDR_OVERLAPPING:-"false"}
5656

5757
TARGET_NAMESPACE="liqo-ci"
5858

59-
for i in $(seq 1 "${CLUSTER_NUMBER}");
60-
do
59+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
6160
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
62-
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
63-
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
64-
export POD_CIDR="10.$((i * 10)).0.0/16"
65-
fi
66-
echo "Creating cluster ${CAPI_CLUSTER_NAME}"
61+
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
62+
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
63+
export POD_CIDR="10.$((i * 10)).0.0/16"
64+
fi
65+
echo "Creating cluster ${CAPI_CLUSTER_NAME}"
6766
POD_CIDR_ESC_1=$(echo $POD_CIDR | cut -d'/' -f1)
6867
POD_CIDR_ESC_2=$(echo $POD_CIDR | cut -d'/' -f2)
6968
POD_CIDR_ESC="${POD_CIDR_ESC_1}\/${POD_CIDR_ESC_2}"
69+
70+
export KUBECONFIG="$HOME/.kube/config"
71+
7072
clusterctl generate cluster "${CAPI_CLUSTER_NAME}" \
7173
--kubernetes-version "$K8S_VERSION" \
7274
--control-plane-machine-count 1 \
@@ -75,19 +77,18 @@ do
7577
--infrastructure kubevirt | sed "s/10.243.0.0\/16/$POD_CIDR_ESC/g" | ${KUBECTL} apply -f -
7678
done
7779

78-
for i in $(seq 1 "${CLUSTER_NUMBER}");
79-
do
80+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
8081
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
8182
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
82-
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
83-
export POD_CIDR="10.$((i * 10)).0.0/16"
84-
fi
83+
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
84+
export POD_CIDR="10.$((i * 10)).0.0/16"
85+
fi
8586
echo "Waiting for cluster ${CAPI_CLUSTER_NAME} to be ready"
8687
"${KUBECTL}" wait --for condition=Ready=true -n "$TARGET_NAMESPACE" "clusters.cluster.x-k8s.io/${CAPI_CLUSTER_NAME}" --timeout=-1s
8788

8889
echo "Getting kubeconfig for cluster ${CAPI_CLUSTER_NAME}"
8990
mkdir -p "${TMPDIR}/kubeconfigs"
90-
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" > "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
91+
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" >"${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
9192

9293
CURRENT_CONTEXT=$("${KUBECTL}" config current-context --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}")
9394
"${KUBECTL}" config set contexts."${CURRENT_CONTEXT}".namespace default --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
@@ -102,8 +103,7 @@ do
102103
install_metrics_server "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
103104
done
104105

105-
for i in $(seq 1 "${CLUSTER_NUMBER}");
106-
do
106+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
107107
echo "Waiting for cluster ${CAPI_CLUSTER_NAME} CNI to be ready"
108108
"wait_${CNI}" "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
109109
done

test/e2e/pipeline/utils.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,38 @@ function install_clusterctl() {
221221
sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
222222
clusterctl version
223223
}
224+
225+
function generate_kubeconfig() {
226+
# Get service account details
227+
SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
228+
SA_CA_CERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
229+
NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
230+
231+
echo "SA_TOKEN: ${SA_TOKEN}"
232+
echo "SA_CA_CERT: ${SA_CA_CERT}"
233+
echo "NAMESPACE: ${NAMESPACE}"
234+
235+
# Get the Kubernetes API server address
236+
KUBERNETES_SERVICE_HOST=${KUBERNETES_SERVICE_HOST:-kubernetes.default.svc}
237+
KUBERNETES_SERVICE_PORT=${KUBERNETES_SERVICE_PORT:-443}
238+
239+
# Create kubeconfig
240+
"${KUBECTL}" config set-cluster default-cluster \
241+
--server=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} \
242+
--certificate-authority=${SA_CA_CERT} \
243+
--embed-certs=true \
244+
--kubeconfig=~/.kube/config
245+
246+
"${KUBECTL}" config set-credentials default-user \
247+
--token=${SA_TOKEN} \
248+
--kubeconfig=~/.kube/config
249+
250+
"${KUBECTL}" config set-context default-context \
251+
--cluster=default-cluster \
252+
--user=default-user \
253+
--namespace=${NAMESPACE} \
254+
--kubeconfig=~/.kube/config
255+
256+
"${KUBECTL}" config use-context default-context \
257+
--kubeconfig=~/.kube/config
258+
}

0 commit comments

Comments
 (0)