Fix Integration tests (#2425)

* fix(ci): Bump golangci-lint to 1.51.1

* chore(lint): fix gofmt and goimport issues

* chore(lint): fix linter issues

- Adapted error comparison according to linter recommendation
- Disabled noctx linting for http request where canceling makes no sense
- Disabled nilerror linting where nil error is returned on purpose
- Disabled makezero linter where slice is explicitly deepcopied

* chore(ci): Update go version in tests workflows

* fix(ci): Allow boilerplate years from 2000-2099

Previously the regex only allowed the copyright notice to contain the
years 2018,2019,2020,2021, or 2022. This commit widens to regex to
20\d\d allowing any year in the range [2000-2099]

* feat(ci): Replace minikube with k3s for intregration tests

The existing setup for minikube is very complicated, replicating most of
the setup steps for a full kubernetes cluster in an only partially
supported minikube configuration (driver=none). Furthermore the existing
setup has been broken for sometime, likely, at least in part due to the
changes to CNI and CRI in recent kubernetes versions.

Since what we actually need is only a running Kubernetes cluster on the
node and access to a registry on localhost:5000, we can switch the
extremely complicated minikube setup for a lightweight cluster using
k3s. Minikube came with a default addon for running a registry on every
node, but the same is not the case for k3s, instead we make use of the
package helm controller and its HelmChart CR to deploy twuni/docker-registry.helm
and expose it on localhost using the integrated LoadBalancer controller.

* fix(test-684): pin base container version

The dockerfile for the regression test connected to issue 684 used a
rolling tag as base image, making it flaky and fail since it was
introduced.

This commit pins the base image to the digest of bionic-20200219, which,
based on the date of the commit that introduced to the dockerfile would
be the most newest ubuntu build and likely what the "rolling" tag
resolved to back then. Since this also an image from the pre-oci days of
ubuntu, this circumvents a bug in container-diff as well
(https://github.com/GoogleContainerTools/container-diff/issues/389)
This commit is contained in:
Joël Pepper
2023-03-21 12:30:54 -04:00
committed by GitHub
parent fe2413e6e3
commit 14ea7c4071
39 changed files with 134 additions and 145 deletions
+32
View File
@@ -0,0 +1,32 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
export INSTALL_K3S_EXEC="--write-kubeconfig-mode=0644"
# Sometimes there is a residual kubeconfig, export and set this explicitly
mkdir -p $HOME/.kube
export K3S_KUBECONFIG_OUTPUT="$HOME/.kube/config"
export KUBECONFIG="$HOME/.kube/config"
curl -sfL https://get.k3s.io | sh -
export SCRIPT_PATH="$(realpath $(dirname $0))"
timeout 5m bash -c 'until kubectl cluster-info 2>/dev/null | grep "CoreDNS" >/dev/null; do sleep 1; done'
# Install local registry and have it listen on localhost:5000
sudo cp $SCRIPT_PATH/local-registry-helm.yaml /var/lib/rancher/k3s/server/manifests/
# Wait until install of the registry completes
timeout 5m bash -c 'until kubectl get -n kube-system pod 2>/dev/null | grep local-registry | grep Completed >/dev/null; do sleep 1; done'
# Wait until registry becomes available on localhost:5000
timeout 5m bash -c 'until nc -z localhost 5000; do sleep 1; done'
echo "K3s is running and registry is available on localhost:5000"
+10
View File
@@ -0,0 +1,10 @@
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: local-registry
namespace: kube-system
spec:
chart: https://github.com/twuni/docker-registry.helm/archive/refs/tags/v2.2.2.tar.gz
set:
# Expose the registry server on localhost
service.type: "LoadBalancer"
-68
View File
@@ -1,68 +0,0 @@
#!/bin/bash
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
# conntrack is required for minikube 1.19 and higher for none driver
if ! conntrack --version &>/dev/null; then
echo "WARNING: No contrack is not installed"
sudo apt-get update -qq
sudo apt-get -qq -y install conntrack
fi
# taken from https://github.com/kubernetes/minikube/blob/b45b29c5df6f88c6ac0afd60079a6190dc1e32c9/hack/jenkins/linux_integration_tests_none.sh#L38
if ! kubeadm &>/dev/null; then
echo "WARNING: kubeadm is not installed. will try to install."
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubeadm"
sudo install kubeadm /usr/local/bin/kubeadm
fi
# "none" driver specific cleanup from previous runs.
sudo kubeadm reset -f --cri-socket unix:///var/run/cri-dockerd.sock || true
# kubeadm reset may not stop pods immediately
docker rm -f $(docker ps -aq) >/dev/null 2>&1 || true
# always install minikube, because version inconsistency is possible and could lead to weird errors
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube
sudo mv minikube /usr/local/bin/
# Minikube needs cri-dockerd to run clusters 1.24+
CRI_DOCKERD_VERSION="${CRI_DOCKERD_VERSION:-0.2.3}"
CRI_DOCKERD_BINARY_URL="https://github.com/Mirantis/cri-dockerd/releases/download/v${CRI_DOCKERD_VERSION}/cri-dockerd-${CRI_DOCKERD_VERSION}.amd64.tgz"
curl -Lo cri-dockerd.tgz $CRI_DOCKERD_BINARY_URL
tar xfz cri-dockerd.tgz
chmod +x cri-dockerd/cri-dockerd
sudo mv cri-dockerd/cri-dockerd /usr/bin/cri-dockerd
git clone https://github.com/Mirantis/cri-dockerd.git /tmp/cri-dockerd
sudo cp /tmp/cri-dockerd/packaging/systemd/* /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable cri-docker.service
sudo systemctl enable --now cri-docker.socket
CRICTL_VERSION="v1.17.0"
curl -L https://github.com/kubernetes-sigs/cri-tools/releases/download/$CRICTL_VERSION/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz --output crictl-${CRICTL_VERSION}-linux-amd64.tar.gz
sudo tar zxvf crictl-$CRICTL_VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-$CRICTL_VERSION-linux-amd64.tar.gz
sudo apt-get update
sudo apt-get install -y liblz4-tool
cat /proc/cpuinfo
minikube start --vm-driver=none --force --addons="registry,default-storageclass,storage-provisioner" || minikube logs;
minikube status
kubectl cluster-info