Skip to content

Commit 603f875

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

File tree

5 files changed

+125
-70
lines changed

5 files changed

+125
-70
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: 23 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,20 @@ 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+
# Set KUBECONFIG for clusterctl to use the management cluster
60+
export KUBECONFIG="${HOME}/.kube/config"
61+
62+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
6163
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}"
64+
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
65+
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
66+
export POD_CIDR="10.$((i * 10)).0.0/16"
67+
fi
68+
echo "Creating cluster ${CAPI_CLUSTER_NAME}"
6769
POD_CIDR_ESC_1=$(echo $POD_CIDR | cut -d'/' -f1)
6870
POD_CIDR_ESC_2=$(echo $POD_CIDR | cut -d'/' -f2)
6971
POD_CIDR_ESC="${POD_CIDR_ESC_1}\/${POD_CIDR_ESC_2}"
72+
7073
clusterctl generate cluster "${CAPI_CLUSTER_NAME}" \
7174
--kubernetes-version "$K8S_VERSION" \
7275
--control-plane-machine-count 1 \
@@ -75,19 +78,18 @@ do
7578
--infrastructure kubevirt | sed "s/10.243.0.0\/16/$POD_CIDR_ESC/g" | ${KUBECTL} apply -f -
7679
done
7780

78-
for i in $(seq 1 "${CLUSTER_NUMBER}");
79-
do
81+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
8082
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
8183
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
84+
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
85+
export POD_CIDR="10.$((i * 10)).0.0/16"
86+
fi
8587
echo "Waiting for cluster ${CAPI_CLUSTER_NAME} to be ready"
8688
"${KUBECTL}" wait --for condition=Ready=true -n "$TARGET_NAMESPACE" "clusters.cluster.x-k8s.io/${CAPI_CLUSTER_NAME}" --timeout=-1s
8789

8890
echo "Getting kubeconfig for cluster ${CAPI_CLUSTER_NAME}"
8991
mkdir -p "${TMPDIR}/kubeconfigs"
90-
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" > "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
92+
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" >"${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
9193

9294
CURRENT_CONTEXT=$("${KUBECTL}" config current-context --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}")
9395
"${KUBECTL}" config set contexts."${CURRENT_CONTEXT}".namespace default --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
@@ -102,8 +104,7 @@ do
102104
install_metrics_server "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
103105
done
104106

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

test/e2e/pipeline/utils.sh

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,34 @@ waitandretry() {
3636
fi
3737
}
3838

39-
function setup_arch_and_os(){
39+
function setup_arch_and_os() {
4040
ARCH=$(uname -m)
4141
case $ARCH in
42-
armv5*) ARCH="armv5";;
43-
armv6*) ARCH="armv6";;
44-
armv7*) ARCH="arm";;
45-
aarch64) ARCH="arm64";;
46-
x86) ARCH="386";;
47-
x86_64) ARCH="amd64";;
48-
i686) ARCH="386";;
49-
i386) ARCH="386";;
50-
*) echo "Error architecture '${ARCH}' unknown"; exit 1 ;;
42+
armv5*) ARCH="armv5" ;;
43+
armv6*) ARCH="armv6" ;;
44+
armv7*) ARCH="arm" ;;
45+
aarch64) ARCH="arm64" ;;
46+
x86) ARCH="386" ;;
47+
x86_64) ARCH="amd64" ;;
48+
i686) ARCH="386" ;;
49+
i386) ARCH="386" ;;
50+
*)
51+
echo "Error architecture '${ARCH}' unknown"
52+
exit 1
53+
;;
5154
esac
5255

53-
OS=$(uname |tr '[:upper:]' '[:lower:]')
56+
OS=$(uname | tr '[:upper:]' '[:lower:]')
5457
case "$OS" in
5558
# Minimalist GNU for Windows
56-
"mingw"*) OS='windows'; return ;;
59+
"mingw"*)
60+
OS='windows'
61+
return
62+
;;
5763
esac
5864
}
5965

60-
61-
function check_supported_arch_and_os(){
66+
function check_supported_arch_and_os() {
6267
local supported=$1
6368
local os=$2
6469
local arch=$3
@@ -89,8 +94,7 @@ function install_kubectl() {
8994
version=$(curl -L -s https://dl.k8s.io/release/stable.txt)
9095
fi
9196

92-
if ! command -v "${KUBECTL}" &> /dev/null
93-
then
97+
if ! command -v "${KUBECTL}" &>/dev/null; then
9498
echo "WARNING: kubectl could not be found. Downloading and installing it locally..."
9599
echo "Downloading https://dl.k8s.io/release/${version}/bin/${os}/${arch}/kubectl"
96100
if ! curl --fail -Lo "${KUBECTL}" "https://dl.k8s.io/release/${version}/bin/${os}/${arch}/kubectl"; then
@@ -114,8 +118,7 @@ function install_helm() {
114118

115119
HELM_VERSION="v3.15.3"
116120

117-
if ! command -v "${HELM}" &> /dev/null
118-
then
121+
if ! command -v "${HELM}" &>/dev/null; then
119122
echo "WARNING: helm could not be found. Downloading and installing it locally..."
120123
if ! curl --fail -Lo "./helm-${HELM_VERSION}-${os}-${arch}.tar.gz" "https://get.helm.sh/helm-${HELM_VERSION}-${os}-${arch}.tar.gz"; then
121124
echo "Error: Unable to download helm for '${os}-${arch}'"
@@ -159,27 +162,24 @@ function install_gcloud() {
159162
cd -
160163

161164
#Login to gcloud
162-
echo "${GCLOUD_KEY}" | base64 -d > "${BINDIR}/gke_key_file.json"
165+
echo "${GCLOUD_KEY}" | base64 -d >"${BINDIR}/gke_key_file.json"
163166
"${GCLOUD}" auth activate-service-account --key-file="${BINDIR}/gke_key_file.json"
164167
"${GCLOUD}" components install gke-gcloud-auth-plugin
165168
}
166169

167170
function install_az() {
168171
local os=$1
169172

170-
if ! command -v az &> /dev/null
171-
then
172-
echo "Azure CLI could not be found. Downloading and installing..."
173-
if [[ "${os}" == "linux" ]]
174-
then
175-
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
176-
elif [[ "${os}" == "darwin" ]]
177-
then
178-
brew update && brew install azure-cli
179-
else
180-
echo "Error: Azure CLI is not supported on ${os}"
181-
exit 1
182-
fi
173+
if ! command -v az &>/dev/null; then
174+
echo "Azure CLI could not be found. Downloading and installing..."
175+
if [[ "${os}" == "linux" ]]; then
176+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
177+
elif [[ "${os}" == "darwin" ]]; then
178+
brew update && brew install azure-cli
179+
else
180+
echo "Error: Azure CLI is not supported on ${os}"
181+
exit 1
182+
fi
183183
fi
184184

185185
echo "Azure CLI version:"
@@ -206,8 +206,7 @@ function wait_kyverno() {
206206
local kubeconfig=$1
207207

208208
# Wait for the kyverno deployments to be ready
209-
if ! waitandretry 5s 2 "${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig}"
210-
then
209+
if ! waitandretry 5s 2 "${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig}"; then
211210
echo "Failed to wait for kyverno deployments to be ready"
212211
exit 1
213212
fi
@@ -221,3 +220,41 @@ function install_clusterctl() {
221220
sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
222221
clusterctl version
223222
}
223+
224+
function generate_kubeconfig() {
225+
# Ensure .kube directory exists
226+
mkdir -p "${HOME}/.kube"
227+
228+
# Get service account details
229+
SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
230+
SA_CA_CERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
231+
NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
232+
233+
echo "SA_TOKEN: ${SA_TOKEN}"
234+
echo "SA_CA_CERT: ${SA_CA_CERT}"
235+
echo "NAMESPACE: ${NAMESPACE}"
236+
237+
# Get the Kubernetes API server address
238+
KUBERNETES_SERVICE_HOST=${KUBERNETES_SERVICE_HOST:-kubernetes.default.svc}
239+
KUBERNETES_SERVICE_PORT=${KUBERNETES_SERVICE_PORT:-443}
240+
241+
# Create kubeconfig
242+
"${KUBECTL}" config set-cluster default-cluster \
243+
--server=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} \
244+
--certificate-authority=${SA_CA_CERT} \
245+
--embed-certs=true \
246+
--kubeconfig="${HOME}/.kube/config"
247+
248+
"${KUBECTL}" config set-credentials default-user \
249+
--token=${SA_TOKEN} \
250+
--kubeconfig="${HOME}/.kube/config"
251+
252+
"${KUBECTL}" config set-context default-context \
253+
--cluster=default-cluster \
254+
--user=default-user \
255+
--namespace=${NAMESPACE} \
256+
--kubeconfig="${HOME}/.kube/config"
257+
258+
"${KUBECTL}" config use-context default-context \
259+
--kubeconfig="${HOME}/.kube/config"
260+
}

0 commit comments

Comments
 (0)