From b0930391751d2b2bd4798216b0d42a7a1b5ee349 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Mon, 26 Dec 2022 16:21:26 +0800 Subject: [PATCH] Add test --- .github/workflows/test.yaml | 84 +++++++++++++++++++ test/etc/systemd/system/kubelet.service | 14 ++++ .../system/kubelet.service.d/10-kubeadm.conf | 11 +++ test/var/lib/kubelet/config.yaml | 2 + test/var/lib/kubelet/kubeadm-flags.env | 1 + 5 files changed, 112 insertions(+) create mode 100644 .github/workflows/test.yaml create mode 100644 test/etc/systemd/system/kubelet.service create mode 100644 test/etc/systemd/system/kubelet.service.d/10-kubeadm.conf create mode 100644 test/var/lib/kubelet/config.yaml create mode 100644 test/var/lib/kubelet/kubeadm-flags.env diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..04bbf8d --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,84 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + branches: + - main + + workflow_dispatch: + +jobs: + test: + # https://docs.github.com/en/actions/using-jobs/using-concurrency + concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-${{ matrix.kube-version }} + cancel-in-progress: true + + # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs + strategy: + fail-fast: false + matrix: + kube-release: + - 1.23 + + continue-on-error: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install conntrack + run: | + sudo apt update + sudo apt install -y conntrack + + # Install Kubernetes use apt source with specified version + - name: Install Kubernetes + run: | + sudo snap install kubelet --channel=${{ matrix.kube-release }}/stable --classic + sudo snap install kubectl --channel=${{ matrix.kube-release }}/stable --classic + sudo snap install kubeadm --channel=${{ matrix.kube-release }}/stable --classic + wget -O crictl-linux-amd64.tar.gz https://github.com/kubernetes-sigs/cri-tools/releases/download/v${{ matrix.kube-release }}.0/crictl-v${{ matrix.kube-release }}.0-linux-amd64.tar.gz && \ + sudo tar zxvf crictl-linux-amd64.tar.gz -C /usr/local/bin && \ + rm -f crictl-linux-amd64.tar.gz + + - name: Swap off + run: | + sudo swapoff -a + sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab + + - name: Start Kubelet + run: | + sudo mkdir /etc/systemd/system/kubelet.service.d/ + sudo cp ./test/etc/systemd/system/kubelet.service.d/10-kubeadm.conf /etc/systemd/system/kubelet.service.d/10-kubeadm.conf + sudo sed -i "s#/usr/bin#/snap/bin#" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf + sudo cp ./test/etc/systemd/system/kubelet.service /etc/systemd/system/kubelet.service + sudo cp ./test/var/lib/kubelet/kubeadm-flags.env /var/lib/kubelet/kubeadm-flags.env + sudo cp ./test/var/lib/kubelet/config.yaml /var/lib/kubelet/config.yaml + sudo systemctl daemon-reload + sudo systemctl enable kubelet --now + sleep 2 + sudo systemctl status kubelet || journalctl -xe -u kubelet || true + + - name: Initialize Kubernetes + run: | + sudo kubeadm init || { + journalctl -xeu kubelet + exit 1 + } + + - name: Setup kubeconfig + run: | + mkdir -p $HOME/.kube + sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config + sudo chown $(id -u):$(id -g) $HOME/.kube/config + + - name: Get pods + run: | + kubectl get pods -o wide --all-namespaces + + - name: Get nodes + run: | + kubectl get nodes -o wide diff --git a/test/etc/systemd/system/kubelet.service b/test/etc/systemd/system/kubelet.service new file mode 100644 index 0000000..15d3e91 --- /dev/null +++ b/test/etc/systemd/system/kubelet.service @@ -0,0 +1,14 @@ +[Unit] +Description=kubelet: The Kubernetes Node Agent +Documentation=https://kubernetes.io/docs/home/ +Wants=network-online.target +After=network-online.target + +[Service] +ExecStart=/usr/bin/kubelet +Restart=always +StartLimitInterval=0 +RestartSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/test/etc/systemd/system/kubelet.service.d/10-kubeadm.conf b/test/etc/systemd/system/kubelet.service.d/10-kubeadm.conf new file mode 100644 index 0000000..bd1b077 --- /dev/null +++ b/test/etc/systemd/system/kubelet.service.d/10-kubeadm.conf @@ -0,0 +1,11 @@ +# Note: This dropin only works with kubeadm and kubelet v1.11+ +[Service] +Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf" +Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml" +# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically +EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env +# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use +# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file. +EnvironmentFile=-/etc/default/kubelet +ExecStart= +ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS diff --git a/test/var/lib/kubelet/config.yaml b/test/var/lib/kubelet/config.yaml new file mode 100644 index 0000000..925b5f8 --- /dev/null +++ b/test/var/lib/kubelet/config.yaml @@ -0,0 +1,2 @@ +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration diff --git a/test/var/lib/kubelet/kubeadm-flags.env b/test/var/lib/kubelet/kubeadm-flags.env new file mode 100644 index 0000000..60e1fc7 --- /dev/null +++ b/test/var/lib/kubelet/kubeadm-flags.env @@ -0,0 +1 @@ +KUBELET_KUBEADM_ARGS="" \ No newline at end of file