Skip to content

Commit

Permalink
Add rollout upgrade integration test (#29)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Homayoon (Hue) Alimohammadi <[email protected]>
  • Loading branch information
bschimke95 and HomayoonAlimohammadi authored Sep 4, 2024
1 parent afd3a98 commit 4fad9a7
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 32 deletions.
44 changes: 35 additions & 9 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ jobs:
name: Build & Run E2E Images
runs-on: [self-hosted, linux, X64, jammy, large]
steps:
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
# We run into rate limiting issues if we don't authenticate
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check out repo
uses: actions/checkout@v4
- name: Install requirements
Expand All @@ -22,29 +30,32 @@ jobs:
sudo snap install kubectl --classic --channel=1.30/stable
- name: Build provider images
run: sudo make docker-build-e2e
- name: Build k8s-snap image
- name: Build k8s-snap images
working-directory: hack/
run: |
cd templates/docker
sudo docker build . -t k8s-snap:dev
./build-e2e-images.sh
- name: Save provider image
run: |
sudo docker save -o provider-images.tar ghcr.io/canonical/cluster-api-k8s/controlplane-controller:dev ghcr.io/canonical/cluster-api-k8s/bootstrap-controller:dev
sudo chmod 775 provider-images.tar
- name: Save k8s-snap image
run: |
sudo docker save -o k8s-snap-image.tar k8s-snap:dev
sudo chmod 775 k8s-snap-image.tar
sudo docker save -o k8s-snap-image-old.tar k8s-snap:dev-old
sudo docker save -o k8s-snap-image-new.tar k8s-snap:dev-new
sudo chmod 775 k8s-snap-image-old.tar
sudo chmod 775 k8s-snap-image-new.tar
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: e2e-images
path: |
provider-images.tar
k8s-snap-image.tar
k8s-snap-image-old.tar
k8s-snap-image-new.tar
run-e2e-tests:
name: Run E2E Tests
runs-on: [self-hosted, linux, X64, jammy, large]
runs-on: [self-hosted, linux, X64, jammy, xlarge]
needs: build-e2e-images
strategy:
matrix:
Expand All @@ -54,7 +65,17 @@ jobs:
- "Workload cluster creation"
- "Workload cluster scaling"
- "Workload cluster upgrade"
# TODO(ben): Remove once all tests are running stable.
fail-fast: false
steps:
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
# We run into rate limiting issues if we don't authenticate
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check out repo
uses: actions/checkout@v4
- name: Install requirements
Expand All @@ -71,8 +92,13 @@ jobs:
path: .
- name: Load provider image
run: sudo docker load -i provider-images.tar
- name: Load k8s-snap image
run: sudo docker load -i k8s-snap-image.tar
- name: Load k8s-snap old image
if: matrix.ginkgo_focus == 'Workload cluster upgrade'
run: |
sudo docker load -i k8s-snap-image-old.tar
- name: Load k8s-snap new image
run: |
sudo docker load -i k8s-snap-image-new.tar
- name: Create docker network
run: |
sudo docker network create kind --driver=bridge -o com.docker.network.bridge.enable_ip_masquerade=true
Expand Down
14 changes: 14 additions & 0 deletions hack/build-e2e-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Description:
# Build k8s-snap docker images required for e2e tests.
#
# Usage:
# ./build-e2e-images.sh

DIR="$(realpath "$(dirname "${0}")")"

cd "${DIR}/../templates/docker"
sudo docker build . -t k8s-snap:dev-old --build-arg BRANCH=main --build-arg KUBERNETES_VERSION=v1.29.6
sudo docker build . -t k8s-snap:dev-new --build-arg BRANCH=main --build-arg KUBERNETES_VERSION=v1.30.4
cd -
2 changes: 1 addition & 1 deletion pkg/ck8s/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (w *Workload) doK8sdRequest(ctx context.Context, method, endpoint string, r
return fmt.Errorf("k8sd request failed: %s", responseBody.Error)
}
if responseBody.Metadata == nil || response == nil {
// Nothing to decode
// No response expected.
return nil
}
if err := json.Unmarshal(responseBody.Metadata, response); err != nil {
Expand Down
13 changes: 12 additions & 1 deletion templates/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ FROM $BUILD_BASE AS builder
ARG REPO=https://github.com/canonical/k8s-snap
ARG BRANCH=main

ARG KUBERNETES_VERSION=""

## NOTE(neoaggelos): install dependencies needed to build the tools
## !!!IMPORTANT!!! Keep up to date with "snapcraft.yaml:parts.build-deps.build-packages"
RUN apt-get update \
Expand Down Expand Up @@ -86,7 +88,12 @@ RUN /src/k8s-snap/build-scripts/build-component.sh helm

## kubernetes build
FROM builder AS build-kubernetes
RUN /src/k8s-snap/build-scripts/build-component.sh kubernetes
ENV KUBERNETES_VERSION=${KUBERNETES_VERSION}
RUN if [ -n "$KUBERNETES_VERSION" ]; then \
echo "Overwriting Kubernetes version with $KUBERNETES_VERSION"; \
echo "$KUBERNETES_VERSION" > /src/k8s-snap/build-scripts/components/kubernetes/version; \
fi
RUN /src/k8s-snap/build-scripts/build-component.sh kubernetes

## runc build
FROM builder AS build-runc
Expand Down Expand Up @@ -156,3 +163,7 @@ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/k8s/

## NOTE(neoaggelos): Required for containerd to properly set up overlayfs for pods
VOLUME ["/var/snap/k8s/common/var/lib/containerd"]

## NOTE(ben): Remove existing kind image kubectl and kubelet binaries
# to avoid version confusion.
RUN rm -f /usr/bin/kubectl /usr/bin/kubelet
6 changes: 4 additions & 2 deletions test/e2e/cluster_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func ClusterUpgradeSpec(ctx context.Context, inputGetter func() ClusterUpgradeSp
ClusterctlConfigPath: input.ClusterctlConfigPath,
KubeconfigPath: input.BootstrapClusterProxy.GetKubeconfigPath(),
InfrastructureProvider: *input.InfrastructureProvider,
Flavor: ptr.Deref(input.Flavor, ""),
Flavor: ptr.Deref(input.Flavor, "upgrades"),
Namespace: namespace.Name,
ClusterName: clusterName,
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersion),
Expand All @@ -158,6 +158,7 @@ func ClusterUpgradeSpec(ctx context.Context, inputGetter func() ClusterUpgradeSp
Cluster: result.Cluster,
ControlPlane: result.ControlPlane,
KubernetesUpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
UpgradeMachineTemplate: ptr.To(fmt.Sprintf("%s-control-plane-old", clusterName)),
WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
})

Expand All @@ -167,13 +168,14 @@ func ClusterUpgradeSpec(ctx context.Context, inputGetter func() ClusterUpgradeSp
Cluster: result.Cluster,
UpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
MachineDeployments: result.MachineDeployments,
UpgradeMachineTemplate: ptr.To(fmt.Sprintf("%s-md-new-0", clusterName)),
WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
})

By("Waiting until nodes are ready")
workloadProxy := input.BootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, result.Cluster.Name)
workloadClient := workloadProxy.GetClient()
framework.WaitForNodesReady(ctx, framework.WaitForNodesReadyInput{
WaitForNodesReady(ctx, WaitForNodesReadyInput{
Lister: workloadClient,
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
Count: int(result.ExpectedTotalNodes()),
Expand Down
15 changes: 6 additions & 9 deletions test/e2e/cluster_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ import (
)

var _ = Describe("Workload cluster upgrade [CK8s-Upgrade]", func() {
BeforeEach(func() {
// TODO(bschimke): Remove once we find a way to run e2e tests with other infrastructure providers that support snap.
Skip("Skipping the upgrade tests as snap does not work on CAPD.")
})

Context("Upgrading a cluster with 1 control plane", func() {
ClusterUpgradeSpec(ctx, func() ClusterUpgradeSpecInput {
// Skipping this test as in-place upgrades are not supported yet.
// TODO(ben): Remove this skip when in-place upgrades are supported.
//Context("Upgrading a cluster with 1 control plane", func() {
/* ClusterUpgradeSpec(ctx, func() ClusterUpgradeSpecInput {
return ClusterUpgradeSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Expand All @@ -42,8 +39,8 @@ var _ = Describe("Workload cluster upgrade [CK8s-Upgrade]", func() {
ControlPlaneMachineCount: ptr.To[int64](1),
WorkerMachineCount: ptr.To[int64](2),
}
})
})
}) */
//})

Context("Upgrading a cluster with HA control plane", func() {
ClusterUpgradeSpec(ctx, func() ClusterUpgradeSpecInput {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/config/ck8s-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ providers:
- old: "imagePullPolicy: Always"
new: "imagePullPolicy: IfNotPresent"
files:
- sourcePath: "../data/infrastructure-docker/cluster-template.yaml"
- sourcePath: "../data/infrastructure-docker/cluster-template-kcp-remediation.yaml"
- sourcePath: "../data/infrastructure-docker/cluster-template-md-remediation.yaml"
- sourcePath: "../data/infrastructure-docker/cluster-template-upgrades.yaml"
- sourcePath: "../data/infrastructure-docker/cluster-template.yaml"
- name: ck8s
type: BootstrapProvider
versions:
Expand Down Expand Up @@ -84,8 +85,8 @@ providers:

variables:
KUBERNETES_VERSION_MANAGEMENT: "v1.28.0"
KUBERNETES_VERSION: "v1.30.0"
KUBERNETES_VERSION_UPGRADE_TO: "v1.30.1"
KUBERNETES_VERSION: "v1.29.6"
KUBERNETES_VERSION_UPGRADE_TO: "v1.30.3"
IP_FAMILY: "IPv4"
KIND_IMAGE_VERSION: "v1.28.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ metadata:
spec:
template:
spec:
customImage: k8s-snap:dev
customImage: k8s-snap:dev-old
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
Expand Down Expand Up @@ -127,7 +127,7 @@ metadata:
spec:
template:
spec:
customImage: k8s-snap:dev
customImage: k8s-snap:dev-old
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ metadata:
spec:
template:
spec:
customImage: k8s-snap:dev
customImage: k8s-snap:dev-old
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
Expand Down Expand Up @@ -101,7 +101,7 @@ metadata:
spec:
template:
spec:
customImage: k8s-snap:dev
customImage: k8s-snap:dev-old
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
kind: CK8sConfigTemplate
Expand Down
Loading

0 comments on commit 4fad9a7

Please sign in to comment.