Skip to content

Commit

Permalink
kola/kubeadm: handle various CNI
Browse files Browse the repository at this point in the history
this commit adds logic and templates to test more CNIs in a
kubernetes context.

- calico
- flannel
- cilium

Tests have a common implementation but it differs using templates
following the tested CNI

Signed-off-by: Mathieu Tortuyaux <[email protected]>
  • Loading branch information
Mathieu Tortuyaux committed Jul 29, 2021
1 parent 2cb618b commit 4aabe45
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
30 changes: 23 additions & 7 deletions kola/tests/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ import (
)

var (
// CNIs is the list of CNIs to deploy
// in the cluster setup
CNIs = []string{
"calico",
"flannel",
"cilium",
}
// params are used to render script templates
// Release is the kubernetes release version we want to use
// ReleaseVersion is the version of the kubelet service and kubeadm dropin
// TODO: when a new version of kubernetes will be tested, it would be nice
// to have a map[string]Release with Release struct holding the parameter below
params = map[string]interface{}{
// TODO: it's actually the CLI version
// we should pass the CLI and cilium version
// https://github.com/cilium/cilium-cli/issues/118
"CiliumVersion": "v0.8.3",
"CNIVersion": "v0.8.7",
"CRIctlVersion": "v1.17.0",
"ReleaseVersion": "v0.4.0",
Expand All @@ -64,18 +75,23 @@ systemd:
)

func init() {
register.Register(&register.Test{
Name: "kubeadm.base",
Distros: []string{"cl"},
ExcludePlatforms: []string{"esx"},
Run: kubeadmBaseTest,
})
for _, CNI := range CNIs {
register.Register(&register.Test{
Name: fmt.Sprintf("kubeadm.%s.base", CNI),
Distros: []string{"cl"},
ExcludePlatforms: []string{"esx"},
Run: func(c cluster.TestCluster) {
kubeadmBaseTest(c, CNI)
},
})
}
}

// kubeadmBaseTest asserts that the cluster is up and running
func kubeadmBaseTest(c cluster.TestCluster) {
func kubeadmBaseTest(c cluster.TestCluster, CNI string) {
board := kola.QEMUOptions.Board
params["Arch"] = strings.SplitN(board, "-", 2)[0]
params["CNI"] = CNI
kubectl, err := setup(c)
if err != nil {
c.Fatalf("unable to setup cluster: %v", err)
Expand Down
25 changes: 25 additions & 0 deletions kola/tests/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ storage:
hash:
function: sha512
sum: {{ .KubectlSum }}
{{ if eq .CNI "cilium" }}
- path: {{ .DownloadDir }}/cilium.tar.gz
filesystem: root
mode: 0755
contents:
remote:
url: https://github.com/cilium/cilium-cli/releases/download/{{ .CiliumVersion }}/cilium-linux-amd64.tar.gz
{{ end }}
- path: /home/core/install.sh
filesystem: root
mode: 0755
Expand Down Expand Up @@ -280,6 +288,7 @@ etcd:
{{ end }}
EOF
{{ if eq .CNI "calico" }}
cat << EOF > calico.yaml
# Source: https://docs.projectcalico.org/manifests/custom-resources.yaml
apiVersion: operator.tigera.io/v1
Expand All @@ -298,6 +307,7 @@ spec:
nodeSelector: all()
flexVolumePath: /opt/libexec/kubernetes/kubelet-plugins/volume/exec/
EOF
{{ end }}
{
systemctl enable --quiet --now kubelet
Expand All @@ -307,8 +317,23 @@ EOF
cp /etc/kubernetes/admin.conf /home/core/.kube/config
chown -R core:core /home/core/.kube; chmod a+r /home/core/.kube/config;
{{ if eq .CNI "calico" }}
kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
kubectl apply -f calico.yaml
{{ end }}
{{ if eq .CNI "flannel" }}
curl -sSfL https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml > kube-flannel.yml
sed -i "s#10.244.0.0/16#{{ .PodSubnet }}#" kube-flannel.yml
kubectl apply -f kube-flannel.yml
{{ end }}
{{ if eq .CNI "cilium" }}
sudo tar -xf {{ .DownloadDir }}/cilium.tar.gz -C {{ .DownloadDir }}
/opt/bin/cilium install \
--config enable-endpoint-routes=true \
--config cluster-pool-ipv4-cidr={{ .PodSubnet }}
# --wait will wait for status to report success
/opt/bin/cilium status --wait
{{ end }}
} 1>&2
Expand Down

0 comments on commit 4aabe45

Please sign in to comment.