Skip to content

Commit 87b3bad

Browse files
edcdavidjc-rhhamadise
authored
Adding Multus and Calico CNI to Minikube (#51)
* Adding Multus and Calico CNI to Minikube * PR review Jun * addind doc for Multus * PR review Jun and Salah * Fix yamllint * fix * PR review Jun * Fix * namespace improvement * Moving to docker, improved reliability, and support for multi-namespaces * fix minikube * merge * PR review Jun and fix for minikube bug * Wait for pods to be terminated after scale in Co-authored-by: Jun Chen <[email protected]> Co-authored-by: Salaheddine Hamadi <[email protected]>
1 parent 03ca703 commit 87b3bad

File tree

14 files changed

+106
-17
lines changed

14 files changed

+106
-17
lines changed

.github/actions/start-minikube/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
minikube_driver:
99
default: docker
1010
minikube_extra_options:
11-
default: '--embed-certs --nodes 3'
11+
default: '--embed-certs --nodes 3 --cni=calico'
1212
oc_kcm_timeout:
1313
default: 5m
1414

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Deploys the partner and test pods and the operator
66
install:
77
./scripts/fix-minikube-labels.sh
8+
./scripts/deploy-multus-network.sh
89
./scripts/deploy-partner-pods.sh
910
./scripts/deploy-test-pods.sh
1011
./scripts/deploy-hpa.sh

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,22 @@ In order to run the local test setup, the following dependencies are needed:
8080
* [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
8181

8282
## Setup
83+
Install the latest minikube by following the instructions at:
84+
```https://minikube.sigs.k8s.io/docs/start/```
8385

8486
To start minikube, issue the following command:
8587

8688
```shell-script
87-
minikube start --embed-certs --driver="virtualbox" --nodes 3
89+
minikube start --embed-certs --driver="virtualbox" --nodes 3 --network-plugin=cni --cni=calico
8890
```
8991

9092
The `--embed-certs` flag will cause minikube to embed certificates directly in its kubeconfig file.
9193
This will allow the minikube cluster to be reached directly from the container without the need of binding additional volumes for certificates.
9294

9395
The `--nodes 3` flag creates a cluster with one master node and two worker nodes. This is to support anti-affinity and pod-recreation test case.
9496

97+
The `--network-plugin=cni --cni=calico` flags configure CNI support and installs Calico. This is required to install Multus later on.
98+
9599
To avoid having to specify this flag, set the `embed-certs` configuration key:
96100

97101
```shell-script

scripts/deploy-debug-ds.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ source $SCRIPT_DIR/init-env.sh
77
export REDHAT_RHEL_REGISTRY="${REDHAT_RHEL_REGISTRY:-registry.redhat.io/rhel8}"
88
# check if we're using minikube by looking for kube-apiserver-minikube pod
99
# if it's minikube, don't install debug partner
10-
res=`oc version | grep Server`
11-
if [[ -z "$res" ]]
10+
if $TNF_NON_OCP_CLUSTER
1211
then
1312
echo "minikube detected, skip installing debug daemonSet"
1413
else

scripts/deploy-minikube.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
22
set -x
33
minikube delete
4-
minikube start --driver=virtualbox --embed-certs --nodes 3
4+
5+
# Minikube configures the Calico CNI to deploy multus
6+
minikube start --driver=docker --embed-certs --nodes 3 --cni=calico --feature-gates="LocalStorageCapacityIsolation=false"

scripts/deploy-multus-network.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# Initialization
4+
SCRIPT_DIR=$(dirname "$0")
5+
source $SCRIPT_DIR/init-env.sh
6+
7+
if $TNF_NON_OCP_CLUSTER
8+
then
9+
echo "minikube detected, deploying Multus, Calico CNI needed in Minikube for this to work"
10+
11+
rm -rf ./temp
12+
git clone --depth 1 https://github.com/k8snetworkplumbingwg/multus-cni.git ./temp/multus-cni
13+
14+
# fix for dimensioning bug
15+
sed 's/memory: "50Mi"/memory: "100Mi"/g' temp/multus-cni/deployments/multus-daemonset-thick-plugin.yml -i
16+
17+
# Deploy Multus
18+
oc apply -f ./temp/multus-cni/deployments/multus-daemonset-thick-plugin.yml
19+
20+
# Wait for all calico and multus daemonset pods to be running
21+
oc rollout status daemonset calico-node -n kube-system --timeout=$TNF_DEPLOYMENT_TIMEOUT
22+
oc rollout status daemonset kube-multus-ds -n kube-system --timeout=$TNF_DEPLOYMENT_TIMEOUT
23+
24+
# Creates the network attachment on eth0 (bridge) on partner namespace
25+
mkdir -p ./temp
26+
cat ./test-target/multus.yaml | RANGE_START="192.168.1.2" RANGE_END="192.168.1.49" $SCRIPT_DIR/mo > ./temp/rendered-multus.yaml
27+
oc apply -f ./temp/rendered-multus.yaml
28+
29+
# Creating a network attachment for the default namespace as well
30+
cat ./test-target/multus.yaml | TNF_EXAMPLE_CNF_NAMESPACE=default RANGE_START="192.168.1.50" RANGE_END="192.168.1.99" $SCRIPT_DIR/mo > ./temp/rendered-multus.yaml
31+
oc apply -f ./temp/rendered-multus.yaml
32+
33+
rm ./temp/rendered-multus.yaml
34+
sleep 3
35+
else
36+
echo "Minukube not detected, Skipping Multus installation"
37+
fi

scripts/deploy-operator.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ fi
1515
# Installing OLM
1616
$SCRIPT_DIR/install-olm.sh
1717

18-
# Create namespace if it does not exist
19-
oc create namespace ${TNF_EXAMPLE_CNF_NAMESPACE} 2>/dev/null
20-
2118
$SCRIPT_DIR/delete-operator.sh
2219

2320
# Creates a secret if a pem file exists

scripts/deploy-partner-pods.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ SCRIPT_DIR=$(dirname "$0")
55
source $SCRIPT_DIR/init-env.sh
66

77
mkdir -p ./temp
8-
cat ./test-partner/partner-deployment.yaml | $SCRIPT_DIR/mo > ./temp/rendered-partner-template.yaml
8+
cat ./test-partner/partner-deployment.yaml | MULTUS_ANNOTATION=$MULTUS_ANNOTATION $SCRIPT_DIR/mo > ./temp/rendered-partner-template.yaml
99
oc apply -f ./temp/rendered-partner-template.yaml
1010
rm ./temp/rendered-partner-template.yaml
1111
sleep 3
1212

1313
oc wait deployment tnfpartner -n default --for=condition=available --timeout=$TNF_DEPLOYMENT_TIMEOUT
14+
15+
# Minikube bug needs a scale in/out to reflect the multus changes, bug?
16+
oc scale --replicas=0 deployment tnfpartner -n default
17+
# wait for the pods to be really terminated
18+
kubectl wait --for=delete pod --selector=app=tnfpartner --timeout=$TNF_DEPLOYMENT_TIMEOUT
19+
# sacle out again
20+
oc scale --replicas=1 deployment tnfpartner -n default
21+
# wait for the deployment to be available
22+
oc wait deployment tnfpartner -n default --for=condition=available --timeout=$TNF_DEPLOYMENT_TIMEOUT

scripts/deploy-test-pods.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
SCRIPT_DIR=$(dirname "$0")
55
source $SCRIPT_DIR/init-env.sh
66

7-
# Create namespace if it does not exist
8-
oc create namespace ${TNF_EXAMPLE_CNF_NAMESPACE} 2>/dev/null
9-
107
mkdir -p ./temp
11-
cat ./test-target/local-pod-under-test.yaml | $SCRIPT_DIR/mo > ./temp/rendered-local-pod-under-test-template.yaml
8+
cat ./test-target/local-pod-under-test.yaml | MULTUS_ANNOTATION=$MULTUS_ANNOTATION $SCRIPT_DIR/mo > ./temp/rendered-local-pod-under-test-template.yaml
129
oc apply -f ./temp/rendered-local-pod-under-test-template.yaml
1310
rm ./temp/rendered-local-pod-under-test-template.yaml
1411
sleep 3
1512

16-
oc wait deployment test -n $TNF_EXAMPLE_CNF_NAMESPACE --for=condition=available --timeout=$TNF_DEPLOYMENT_TIMEOUT
13+
oc wait deployment test -n $TNF_EXAMPLE_CNF_NAMESPACE --for=condition=available --timeout=$TNF_DEPLOYMENT_TIMEOUT
14+
oc scale --replicas=0 deployment test -n $TNF_EXAMPLE_CNF_NAMESPACE
15+
16+
# Minikube bug needs another scale out?
17+
oc wait deployment test -n $TNF_EXAMPLE_CNF_NAMESPACE --for=condition=available --timeout=$TNF_DEPLOYMENT_TIMEOUT
18+
oc scale --replicas=2 deployment test -n $TNF_EXAMPLE_CNF_NAMESPACE

scripts/fix-minikube-labels.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
SCRIPT_DIR=$(dirname "$0")
55
source $SCRIPT_DIR/init-env.sh
66

7-
res=`oc version | grep Server`
8-
if [ -z "$res" ]
7+
if $TNF_NON_OCP_CLUSTER
98
then
109
echo "minikube detected, applying worker labels on all nodes"
1110
oc get nodes -oname | xargs -I{} oc label {} node-role.kubernetes.io/worker=worker --overwrite

0 commit comments

Comments
 (0)