-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sergio Gonzalez <[email protected]>
- Loading branch information
1 parent
716d9ab
commit f08aabd
Showing
3 changed files
with
102 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
name: multus-cni | ||
|
||
image: cgr.dev/chainguard/multus-cni | ||
|
||
logo: https://storage.googleapis.com/chainguard-academy/logos/multus-cni.svg | ||
|
||
endoflife: "" | ||
|
||
console_summary: "" | ||
|
||
short_description: A CNI meta-plugin for multi-homed pods in Kubernetes | ||
|
||
compatibility_notes: "" | ||
|
||
readme_file: README.md | ||
upstream_url: | ||
|
||
upstream_url: | ||
|
||
keywords: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,98 @@ | ||
#!/usr/bin/env bash | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset -o errtrace -o pipefail -x | ||
# Function to check pod status | ||
check_pod_status() { | ||
local pod_name="$1" | ||
local namespace="$2" | ||
kubectl get pod "$pod_name" -n "$namespace" &>/dev/null | ||
} | ||
|
||
# Replace "multus-cni" with the name of your Helm release | ||
HELM_RELEASE="multus-cni" | ||
# Function to delete the pod if it exists | ||
delete_pod_if_exists() { | ||
local pod_name="$1" | ||
local namespace="$2" | ||
if check_pod_status "$pod_name" "$namespace"; then | ||
kubectl delete pod "$pod_name" -n "$namespace" &>/dev/null | ||
fi | ||
} | ||
|
||
POD_SPEC='apiVersion: v1 | ||
# Apply the Multus CNI DaemonSet manifest | ||
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml &>/dev/null | ||
|
||
NAMESPACE="multus" | ||
kubectl create namespace "$NAMESPACE" &>/dev/null | ||
kubectl create serviceaccount multus -n "$NAMESPACE" &>/dev/null | ||
|
||
cat <<EOF > multus-pod.yaml | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: test-pod | ||
name: multus-test-pod | ||
namespace: $NAMESPACE | ||
annotations: | ||
k8s.v1.cni.cncf.io/networks: '[{"name":"flannel-network"},{"name":"default-network"}]' | ||
spec: | ||
serviceAccountName: multus | ||
containers: | ||
- name: test-container | ||
- name: multus-test-container | ||
image: busybox | ||
command: | ||
- /bin/sh | ||
- -c | ||
- "trap : TERM INT; (while true; do sleep 1; done) & wait" | ||
- sleep | ||
- "3600" | ||
stdin: true | ||
tty: true | ||
' | ||
|
||
# Create the test pod | ||
kubectl apply -f - <<< "$POD_SPEC" | ||
|
||
# Wait until the pod is in "Running" state | ||
echo "Waiting for pod to be in 'Running' state..." | ||
while true; do | ||
POD_STATUS=$(kubectl get pod test-pod -o jsonpath='{.status.phase}') | ||
if [ "$POD_STATUS" = "Running" ]; then | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
echo "Pod is now in 'Running' state." | ||
resources: | ||
requests: | ||
memory: "64Mi" | ||
cpu: "250m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
EOF | ||
|
||
kubectl apply -f multus-pod.yaml &>/dev/null | ||
|
||
# Total time to wait in seconds (3 minutes) | ||
TOTAL_WAIT_TIME=$((3 * 60)) | ||
|
||
# Waiting time between checks in seconds (5 seconds) | ||
WAIT_INTERVAL=5 | ||
|
||
# Get the IP address of the pod | ||
POD_IP=$(kubectl get pod test-pod -o jsonpath='{.status.podIPs[0].ip}') | ||
# Total expected time | ||
TOTAL_WAITED=0 | ||
|
||
# Test network connectivity | ||
echo "Testing connectivity to Google..." | ||
ping -c 3 google.com | ||
# pod name | ||
POD_NAME="multus-test-pod" | ||
|
||
# Delete the test pod | ||
kubectl delete pod test-pod | ||
while [ $TOTAL_WAITED -lt $TOTAL_WAIT_TIME ]; do | ||
# Get pod status | ||
POD_STATUS=$(kubectl get pod "$POD_NAME" -n "$NAMESPACE" -o jsonpath='{.status.phase}') | ||
|
||
# Check if the status is 'Running' | ||
if [ "$POD_STATUS" == "Running" ]; then | ||
echo "The pod is in Running state." | ||
|
||
# Test connectivity from the pod to another resource within the cluster | ||
kubectl exec "$POD_NAME" -n "$NAMESPACE" -- sh -c "ping -c 3 google.com" | ||
|
||
# Check if the pod still exists before trying to delete it | ||
if check_pod_status "$POD_NAME" "$NAMESPACE"; then | ||
delete_pod_if_exists "$POD_NAME" "$NAMESPACE" | ||
fi | ||
|
||
# Delete the Multus CNI DaemonSet | ||
kubectl delete -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml &>/dev/null | ||
|
||
exit 0 | ||
fi | ||
|
||
# Increase total expected time | ||
TOTAL_WAITED=$((TOTAL_WAITED + WAIT_INTERVAL)) | ||
|
||
# Wait before next check | ||
sleep "$WAIT_INTERVAL" | ||
done | ||
|
||
exit 0 | ||
# If the pod is not in 'Running' state after 3 minutes, exit with exit code 1 | ||
echo "The pod is not in Running state after 3 minutes." | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters