Skip to content

Commit

Permalink
Add calico test case
Browse files Browse the repository at this point in the history
Contributed by Marek Chodor <[email protected]> in GoogleCloudPlatform#269
  • Loading branch information
jingyuanliang committed Feb 21, 2024
1 parent 0492743 commit 975b397
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
69 changes: 69 additions & 0 deletions scripts/testcase/testcase-calico.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export KUBERNETES_SERVICE_HOST=kubernetes.default.svc
export KUBERNETES_SERVICE_PORT=443

export ENABLE_CALICO_NETWORK_POLICY=true
export ENABLE_BANDWIDTH_PLUGIN=false
export ENABLE_CILIUM_PLUGIN=false
export ENABLE_MASQUERADE=false
export ENABLE_IPV6=true
export CNI_SPEC_IPV6_ROUTE="{\"dst\": \"2600:1900:4000::/42\"}"
export CALICO_CNI_SPEC_TEMPLATE_FILE="/host/etc/cni/net.d/10-calico.conflist.template"
export CALICO_CNI_SERVICE_ACCOUNT="calico-cni-sa"
export WRITE_CALICO_CONFIG_FILE=true
export IPV6_FORWARDING_CONF=/tmp/mock-calico-enable-forwarding

CALICO_CNI_SPEC_TEMPLATE=$(cat testdata/calico-spec-template.json)
export CALICO_CNI_SPEC_TEMPLATE

function before_test() {

function curl() {
# shellcheck disable=SC2317
case "$*" in
*http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0*)
echo '{"ipv6s": ["2600:1900:4000:318:0:7:0:0"]}'
;;
*https://kubernetes.default.svc:443/api/v1/nodes/*)
echo '{
"metadata": {
"labels": {
},
"creationTimestamp": "2024-01-03T11:54:01Z",
"name": "gke-my-cluster-default-pool-128bc25d-9c94",
"resourceVersion": "891003",
"uid": "f2353a2f-ca8c-4ca0-8dd3-ad1f964a54f0"
},
"spec": {
"podCIDR": "10.52.1.0/24",
"podCIDRs": [
"10.52.1.0/24"
],
"providerID": "gce://my-gke-project/us-central1-c/gke-my-cluster-default-pool-128bc25d-9c94"
}
}'
;;
*)
#unsupported
exit 1
esac
}
export -f curl

}

function verify() {
local expected
local actual

expected=$(jq -S . <"testdata/expected-calico.json")
actual=$(jq -S . <"/host/etc/cni/net.d/10-calico.conflist.template")

if [ "$expected" != "$actual" ] ; then
echo "Expected cni_spec value:"
echo "$expected"
echo "but actual was"
echo "$actual"
return 1
fi

}
39 changes: 39 additions & 0 deletions scripts/testdata/calico-spec-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "gke-pod-network",
"cniVersion": "0.3.1",
"plugins": [
{
"type": "calico",
"mtu": 1460,
"log_level": "warning",
"log_file_path": "/var/log/calico/cni/cni.log",
"datastore_type": "kubernetes",
"nodename": "__KUBERNETES_NODE_NAME__",
"nodename_file_optional": true,
"ipam": {
"type": "host-local",
"ranges": [
[ { "subnet": "usePodCidr" } ]@ipv6SubnetOptional
],
"routes": [
{"dst": "0.0.0.0/0"}@ipv6RouteOptional
]
},
"policy": {
"type": "k8s"
},
"kubernetes": {
"kubeconfig": "__KUBECONFIG_FILEPATH__"
}
},
{
"type": "portmap",
"capabilities": {"portMappings": true},
"snat": true
},
{
"type": "bandwidth",
"capabilities": {"bandwidth": true}
}
]
}
39 changes: 39 additions & 0 deletions scripts/testdata/expected-calico.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "gke-pod-network",
"cniVersion": "0.3.1",
"plugins": [
{
"type": "calico",
"mtu": 1460,
"log_level": "warning",
"log_file_path": "/var/log/calico/cni/cni.log",
"datastore_type": "kubernetes",
"nodename": "__KUBERNETES_NODE_NAME__",
"nodename_file_optional": true,
"ipam": {
"type": "host-local",
"ranges": [
[ { "subnet": "usePodCidr" } ], [{"subnet": "2600:1900:4000:318:0:7:0:0/112"}]
],
"routes": [
{"dst": "0.0.0.0/0"}, {"dst": "2600:1900:4000::/42"}
]
},
"policy": {
"type": "k8s"
},
"kubernetes": {
"kubeconfig": "__KUBECONFIG_FILEPATH__"
}
},
{
"type": "portmap",
"capabilities": {"portMappings": true},
"snat": true
},
{
"type": "bandwidth",
"capabilities": {"bandwidth": true}
}
]
}

0 comments on commit 975b397

Please sign in to comment.