Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,6 @@ sshuttle.pid

# Book
docs/book/book/

# venv
.venv
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)
## --------------------------------------

# The number of ginkgo tests to run concurrently
E2E_GINKGO_PARALLEL=2
E2E_GINKGO_PARALLEL ?= 2

E2E_ARGS ?=

Expand All @@ -143,6 +143,7 @@ E2E_KUSTOMIZE_DIR=test/e2e/data/kustomize
.PHONY: e2e-templates
e2e-templates: ## Generate cluster templates for e2e tests
e2e-templates: $(addprefix $(E2E_TEMPLATES_DIR)/, \
cluster-template-v1alpha5.yaml \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to use this to write v1alpha5 simulator tests!

cluster-template-external-cloud-provider.yaml \
cluster-template-multi-az.yaml \
cluster-template-multi-network.yaml \
Expand Down
18 changes: 16 additions & 2 deletions scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

################################################################################
# usage: ci-conformance.sh
# This program runs the clusterctl conformance e2e tests.
# usage: ci-e2e.sh
# This program runs the e2e tests.
################################################################################

set -x
Expand Down Expand Up @@ -84,6 +84,20 @@ fi

"hack/ci/create_devstack.sh"

# Upload image for e2e clusterctl upgrade tests
source "${REPO_ROOT}/hack/ci/${RESOURCE_TYPE}.sh"
CONTAINER_ARCHIVE="${ARTIFACTS}/capo-e2e-image.tar"
SSH_KEY="$(get_ssh_private_key_file)"
SSH_ARGS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o PasswordAuthentication=no"
CONTROLLER_IP=${CONTROLLER_IP:-"10.0.3.15"}

make e2e-image
docker save -o "${CONTAINER_ARCHIVE}" gcr.io/k8s-staging-capi-openstack/capi-openstack-controller:e2e
scp -i "${SSH_KEY}" ${SSH_ARGS} "${CONTAINER_ARCHIVE}" "cloud@${CONTROLLER_IP}:capo-e2e-image.tar"
ssh -i "${SSH_KEY}" ${SSH_ARGS} "cloud@${CONTROLLER_IP}" -- sudo chown root:root capo-e2e-image.tar
ssh -i "${SSH_KEY}" ${SSH_ARGS} "cloud@${CONTROLLER_IP}" -- sudo chmod u=rw,g=r,o=r capo-e2e-image.tar
ssh -i "${SSH_KEY}" ${SSH_ARGS} "cloud@${CONTROLLER_IP}" -- sudo mv capo-e2e-image.tar /var/www/html/capo-e2e-image.tar
Comment on lines +88 to +99
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions on how to improve this?
The point of this is to build the e2e image, save it as an archive and upload it to the controller where it can be fetched for the secondary management cluster. (In the KinD bootstrap cluster, we simply inject the image directly, but we cannot do this for the secondary management cluster that it used for the upgrade test.)

The main issue I have with it is that we build the e2e image twice. Once here and once when running make test-e2e below. For the upgrade test it may be okay but it is completely unnecessary for all the other tests.


export OPENSTACK_CLOUD_YAML_FILE
OPENSTACK_CLOUD_YAML_FILE="$(pwd)/clouds.yaml"
make test-e2e
Expand Down
23 changes: 22 additions & 1 deletion test/e2e/data/e2e_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ providers:
- name: v1.2.4
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.2.4/core-components.yaml"
type: url
contract: v1beta1
files:
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
replacements:
Expand All @@ -48,6 +49,7 @@ providers:
- name: v1.2.4
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.2.4/bootstrap-components.yaml"
type: url
contract: v1beta1
files:
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
replacements:
Expand All @@ -61,6 +63,7 @@ providers:
- name: v1.2.4
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.2.4/control-plane-components.yaml"
type: url
contract: v1beta1
files:
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
replacements:
Expand All @@ -71,9 +74,26 @@ providers:
- name: openstack
type: InfrastructureProvider
versions:
# This is only for clusterctl upgrade tests
- name: v0.6.3
value: "https://github.com/kubernetes-sigs/cluster-api-provider-openstack/releases/download/v0.6.3/infrastructure-components.yaml"
type: url
contract: v1beta1
files:
- sourcePath: "../data/shared/v1beta1_provider/metadata.yaml"
- sourcePath: "./infrastructure-openstack/cluster-template.yaml"
replacements:
- old: "imagePullPolicy: Always"
new: "imagePullPolicy: IfNotPresent"
- old: "--v=2"
new: "--v=4"
- old: "--leader-elect"
new: "--leader-elect=false\n - --sync-period=1m"
Comment on lines +77 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all honesty this remains magic to me. I'll work it out one day when it breaks.

@tobiasgiese @jichenjc @seanschneeweiss Are any of you able to give this stanza meaningful review?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything in particular that you are wondering about? My understanding of this is that it is used to create a repository that clusterctl is then configured to use as the source of truth instead of reaching out to github to check what releases we have. This is mostly useful for not-yet-released versions, but since the same config is also used for upgrade tests, we need to explicitly list the versions that should be "available" to the test.

I didn't think much about the additional config here (replacements and files) but I think they make sense and follow what we already have as well as what CAPI is doing.

- name: v0.6.99
value: ../../../config/default
contract: v1beta1
# This is the upcoming version.
# Specify no contract so that upgrade tests that start from a specific contract won't pick it up.
# contract: v1beta1
files:
- sourcePath: "../data/shared/v1beta1_provider/metadata.yaml"
- sourcePath: "./infrastructure-openstack/cluster-template.yaml"
Expand Down Expand Up @@ -116,6 +136,7 @@ variables:
OPENSTACK_VOLUME_TYPE_ALT: "test-volume-type"
CONFORMANCE_WORKER_MACHINE_COUNT: "5"
CONFORMANCE_CONTROL_PLANE_MACHINE_COUNT: "1"
INIT_WITH_KUBERNETES_VERSION: "v1.25.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used only for the management cluster? We still have the issue that our CI installation image is stuck on 1.18.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the secondary management cluster. It will be used when rendering the cluster-template here.
I also noticed that the installation image is stuck on 1.18, but we use the CI artifacts script to actually upgrade before kubeadm is run.


intervals:
conformance/wait-control-plane: ["30m", "10s"]
Expand Down
1 change: 1 addition & 0 deletions test/e2e/data/kustomize/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ resources:

components:
- ../common-patches
- ../upgrade-patches
31 changes: 31 additions & 0 deletions test/e2e/data/kustomize/upgrade-patches/ci-hack-kcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# Workaround for https://github.com/kubernetes-sigs/cluster-api/issues/7457
# There is a small but important difference between these two:
# path: /a/b/c
# *creates* the c array, overwriting anything that was there before
# path: /a/b/c/-
# *adds* to the c array and does not work if the array is missing
#
# We add to the postKubeadmCommands (instead of pre*) since we need the CI artifacts
# script to run first. Without this, the container images are not imported properly.
- op: add
path: /spec/kubeadmConfigSpec/postKubeadmCommands
value:
- /usr/local/bin/ci-artifacts-openstack.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this run? Is it on the test runner or on the target? I assume the latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It runs on the target yes. I'm mimicking what we already use to to get the "CI artifacts".
For that we call GenerateCIArtifactsInjectedTemplateForDebian which injects a script that runs as part of the preKubeadmCommands.

At first I actually tried adding the new script to the ci-artifacts-platform-kustomization.yaml, but that turned out to be harder than expected since it is way too easy to overwrite each others file in those patches. 😬 So I ended up putting it here together with the common patches.

- op: add
path: /spec/kubeadmConfigSpec/files/-
value:
content: |
#!/bin/bash
DOWNLOAD_E2E_IMAGE=${DOWNLOAD_E2E_IMAGE:=false}
if [ ! "${DOWNLOAD_E2E_IMAGE}" = true ]; then
echo "Not downloading E2E image, exiting"
exit 0
fi
# Download the locally built CAPO controller image
echo "Downloading ${E2E_IMAGE_URL}"
wget "${E2E_IMAGE_URL}" -O "/tmp/capo-controller-manager.tar"
sudo ctr -n k8s.io images import "/tmp/capo-controller-manager.tar" || echo "* ignoring expected 'ctr images import' result"
owner: root:root
path: /usr/local/bin/ci-artifacts-openstack.sh
permissions: "0750"
31 changes: 31 additions & 0 deletions test/e2e/data/kustomize/upgrade-patches/ci-hack-kct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# Workaround for https://github.com/kubernetes-sigs/cluster-api/issues/7457
# There is a small but important difference between these two:
# path: /a/b/c
# *creates* the c array, overwriting anything that was there before
# path: /a/b/c/-
# *adds* to the c array and does not work if the array is missing
#
# We add to the postKubeadmCommands (instead of pre*) since we need the CI artifacts
# script to run first. Without this, the container images are not imported properly.
- op: add
path: /spec/template/spec/postKubeadmCommands
value:
- /usr/local/bin/ci-artifacts-openstack.sh
- op: add
path: /spec/template/spec/files/-
value:
content: |
#!/bin/bash
DOWNLOAD_E2E_IMAGE=${DOWNLOAD_E2E_IMAGE:=false}
if [ ! "${DOWNLOAD_E2E_IMAGE}" = true ]; then
echo "Not downloading E2E image, exiting"
exit 0
fi
# Download the locally built CAPO controller image
echo "Downloading ${E2E_IMAGE_URL}"
wget "${E2E_IMAGE_URL}" -O "/tmp/capo-controller-manager.tar"
sudo ctr -n k8s.io images import "/tmp/capo-controller-manager.tar" || echo "* ignoring expected 'ctr images import' result"
owner: root:root
path: /usr/local/bin/ci-artifacts-openstack.sh
permissions: "0750"
14 changes: 14 additions & 0 deletions test/e2e/data/kustomize/upgrade-patches/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Modifications to release templates for clusterctl upgrade scenarios
---
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

patches:
- target:
kind: KubeadmControlPlane
name: \${CLUSTER_NAME}-control-plane
path: ci-hack-kcp.yaml
- target:
kind: KubeadmConfigTemplate
name: \${CLUSTER_NAME}-md-0
path: ci-hack-kct.yaml
6 changes: 6 additions & 0 deletions test/e2e/data/kustomize/v1alpha5/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
resources:
- ../../../../../kustomize/v1alpha5/default

components:
- ../common-patches
1 change: 1 addition & 0 deletions test/e2e/shared/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
FlavorExternalCloudProvider = "external-cloud-provider-ci-artifacts"
FlavorMultiNetwork = "multi-network-ci-artifacts"
FlavorMultiAZ = "multi-az-ci-artifacts"
FlavorV1alpha5 = "v1alpha5-ci-artifacts"
)

// DefaultScheme returns the default scheme to use for testing.
Expand Down
55 changes: 55 additions & 0 deletions test/e2e/suites/e2e/clusterctl_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build e2e
// +build e2e

/*
Copyright 2021 The Kubernetes Authors.
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.
*/

package e2e

import (
"context"

. "github.com/onsi/ginkgo"
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"

"sigs.k8s.io/cluster-api-provider-openstack/test/e2e/shared"
)

// Note: There isn't really anything fixing this to the v0.6 release. The test will
// simply pick the latest release with the correct contract from the E2EConfig, as seen here
// https://github.com/kubernetes-sigs/cluster-api/blob/3abb9089485f51d46054096c17ccb8b59f0f7331/test/e2e/clusterctl_upgrade.go#L265
// When new minor releases are added (with the same contract) we will need to work on this
// if we want to continue testing v0.6.
var _ = Describe("When testing clusterctl upgrades (v0.6=>current) [clusterctl-upgrade]", func() {
ctx := context.TODO()
shared.SetEnvVar("USE_CI_ARTIFACTS", "true", false)
shared.SetEnvVar("DOWNLOAD_E2E_IMAGE", "true", false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this setting an environment variable on the test runner? If so, how does that affect /usr/local/bin/ci-artifacts-openstack.sh which I'm assuming (possibly incorrectly) is executing on the target?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! It is used when rendering the cluster-template. Both these variables are used in the cluster-template that we use in the tests. You can see the rendered result in _artifacts/templates. Here is the one from the previous (successful) e2e test run on this PR: https://storage.googleapis.com/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_cluster-api-provider-openstack/1371/pull-cluster-api-provider-openstack-e2e-test/1594601712893562880/artifacts/templates/cluster-template-ci-artifacts.yaml (and here is the complete _artifacts folder from that run for reference).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to have to look at the template renderer. I didn't think it would support bash syntax like ${DOWNLOAD_E2E_IMAGE:=false}.

If that question itself reveals my fundamental misunderstanding, please can you enlighten me?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substitution language is linked from the clusterctl documentation here: https://cluster-api.sigs.k8s.io/clusterctl/commands/generate-yaml.html

shared.SetEnvVar("E2E_IMAGE_URL", "http://10.0.3.15/capo-e2e-image.tar", false)

capi_e2e.ClusterctlUpgradeSpec(ctx, func() capi_e2e.ClusterctlUpgradeSpecInput {
return capi_e2e.ClusterctlUpgradeSpecInput{
E2EConfig: e2eCtx.E2EConfig,
ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath,
BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
ArtifactFolder: e2eCtx.Settings.ArtifactFolder,
SkipCleanup: false,
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.2.4/clusterctl-{OS}-{ARCH}",
InitWithProvidersContract: "v1beta1",
MgmtFlavor: shared.FlavorDefault,
WorkloadFlavor: shared.FlavorV1alpha5,
}
})
})