Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running e2e tests on AWS #45

Merged
merged 79 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
c556e00
support running e2e tests on aws
eaudetcobello Aug 19, 2024
e0c2d45
add ami id
eaudetcobello Aug 19, 2024
ee59151
hacks to get the cluster deployed
eaudetcobello Aug 21, 2024
ddb9a10
newest template updates
eaudetcobello Aug 21, 2024
1c67a63
Add clusterctl config
bschimke95 Jul 8, 2024
846c7ea
docs
bschimke95 Jul 10, 2024
7a695a4
move clusterctl and update template-variables
bschimke95 Jul 11, 2024
f48bfd7
delete obsolete docs
bschimke95 Jul 12, 2024
0931a0f
remove clusterctl
eaudetcobello Aug 21, 2024
a0ad6a5
review comments
eaudetcobello Aug 21, 2024
72187a9
reformat
eaudetcobello Aug 21, 2024
a90793e
remove microk8s references
eaudetcobello Aug 21, 2024
a3d9b85
add ami id to .rc file
eaudetcobello Aug 21, 2024
cd4073e
configurable root volume size. fix var. name
eaudetcobello Aug 21, 2024
1d08d54
proper e2e config
eaudetcobello Aug 24, 2024
817c4a1
revert add aws pkg
eaudetcobello Aug 24, 2024
3bf3bc7
newline at eof
eaudetcobello Aug 24, 2024
0a3e710
add info to readme
eaudetcobello Aug 28, 2024
9255fd5
add region env. var
eaudetcobello Aug 28, 2024
98f590a
explain how to run the tests with tilt
eaudetcobello Aug 28, 2024
6d66f7b
add the ability to run tests on aws
eaudetcobello Aug 29, 2024
c21680b
Add running cluster in CI
eaudetcobello Sep 3, 2024
76dfe12
reset e2e.yaml
eaudetcobello Sep 3, 2024
1100cb2
Remove new file docs/overview.md
eaudetcobello Sep 3, 2024
1ce27e7
Make install script more robust
eaudetcobello Sep 4, 2024
79057da
Add Github action
eaudetcobello Sep 4, 2024
92f4e81
can run tests locally in lxd container
eaudetcobello Sep 5, 2024
f291eb8
only pass env. vars in script step
eaudetcobello Sep 5, 2024
fc3950b
add debug action
eaudetcobello Sep 9, 2024
250584e
delete file
eaudetcobello Sep 12, 2024
786b3b4
update comments
eaudetcobello Sep 12, 2024
cfc5949
test
eaudetcobello Sep 25, 2024
4746fd5
cleanup ck8s-aws.yaml
eaudetcobello Sep 26, 2024
081b14a
don't use custom script
eaudetcobello Sep 26, 2024
718caa7
launch test on aws
eaudetcobello Sep 26, 2024
fa793f8
tidy
eaudetcobello Oct 15, 2024
93a6607
update templates
eaudetcobello Oct 16, 2024
4919b04
use dev tag so locally built images are used
eaudetcobello Oct 17, 2024
06fbc70
use self-hosted
eaudetcobello Oct 17, 2024
fcef40f
skip remediation tests on aws, add aws infra in action
eaudetcobello Oct 17, 2024
ac84c08
change run condition
eaudetcobello Oct 17, 2024
9045fc9
add -y to apt install
eaudetcobello Oct 17, 2024
c13b9c7
remove outdated files
eaudetcobello Oct 17, 2024
266d2f7
refactor workflow
eaudetcobello Oct 17, 2024
2584999
pull instead of build
eaudetcobello Oct 17, 2024
3b510f6
dont require skipped job
eaudetcobello Oct 17, 2024
b85c082
set awsb64encoded_credentials
eaudetcobello Oct 17, 2024
044aa93
only run one test for now
eaudetcobello Oct 17, 2024
7096177
install clusterawsadm
eaudetcobello Oct 17, 2024
a2a2573
-E and change to create public IP
eaudetcobello Oct 17, 2024
8e7d62d
improve aws-nuke cleanup
eaudetcobello Oct 18, 2024
2b3f850
add kubectl
eaudetcobello Oct 18, 2024
14fd2a5
add tmate
eaudetcobello Oct 18, 2024
1fb4a3a
only run one test
eaudetcobello Oct 18, 2024
e88a76a
detached
eaudetcobello Oct 18, 2024
29f7eac
change ssh key name
eaudetcobello Oct 18, 2024
c9254da
revert to 1.28.3 img and always cleanup
eaudetcobello Oct 18, 2024
879d15b
dont harcode namespace
eaudetcobello Oct 18, 2024
a0cd042
use explicit vpc, subnet, sg
eaudetcobello Oct 18, 2024
9a60c49
skip cleanup
eaudetcobello Oct 18, 2024
e0e8275
try reconcile
eaudetcobello Oct 18, 2024
8b2bfbc
reconcile -> applyonce
eaudetcobello Oct 21, 2024
2994cd2
try juju
eaudetcobello Oct 22, 2024
83f3b44
use one file
eaudetcobello Oct 22, 2024
2f54e43
cleanup
eaudetcobello Oct 22, 2024
f374d8f
revert
eaudetcobello Oct 22, 2024
e08976e
revert
eaudetcobello Oct 22, 2024
4b8c46f
revert
eaudetcobello Oct 22, 2024
5d58ef3
update readme
eaudetcobello Oct 22, 2024
9f396b3
revert
eaudetcobello Oct 22, 2024
d4e2a1b
use skip and update readme
eaudetcobello Oct 22, 2024
46f42ce
revert
eaudetcobello Oct 22, 2024
a9d0f2b
revert
eaudetcobello Oct 22, 2024
71dfed0
increase timeouts
eaudetcobello Oct 23, 2024
dd4f5c9
bump to 1.8.4
eaudetcobello Oct 23, 2024
533bb54
bump to 1.8.4
eaudetcobello Oct 23, 2024
2068096
review comments
eaudetcobello Oct 23, 2024
2ef3389
revert
eaudetcobello Oct 23, 2024
374cc2d
forgot $
eaudetcobello Oct 23, 2024
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: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ GINKGO_NODES ?= 1 # GINKGO_NODES is the number of parallel nodes to run
GINKGO_TIMEOUT ?= 2h
GINKGO_POLL_PROGRESS_AFTER ?= 60m
GINKGO_POLL_PROGRESS_INTERVAL ?= 5m
E2E_CONF_FILE ?= $(TEST_DIR)/e2e/config/ck8s-docker.yaml
E2E_INFRA ?= docker
E2E_CONF_FILE ?= $(TEST_DIR)/e2e/config/ck8s-$(E2E_INFRA).yaml
SKIP_RESOURCE_CLEANUP ?= false
USE_EXISTING_CLUSTER ?= false
GINKGO_NOCOLOR ?= false
Expand Down
67 changes: 67 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,73 @@ To run a specific e2e test, such as `[PR-Blocking]`, use the `GINKGO_FOCUS` envi
make GINKGO_FOCUS="\\[PR-Blocking\\]" test-e2e # only run e2e test with `[PR-Blocking]` in its spec name
```

### Use an existing cluster as the management cluster

This is useful if you want to use a cluster managed by Tilt.

```shell
make USE_EXISTING_CLUSTER=true test-e2e
```

### Run e2e tests on AWS

To run the tests on AWS you will need to set the AWS_B64ENCODED_CREDENTIALS environment variable.

Then, you can run:

```shell
make E2E_INFRA=aws test-e2e
```

Note: The remediation tests currently do not pass on cloud providers. We recommend excluding these tests from your test runs.

For more information, please refer to the following:

[Kubernetes Slack Discussion](kubernetes.slack.com/archives/C8TSNPY4T/p1680525266510109)

[Github Issue #4198](github.com/kubernetes-sigs/cluster-api-provider-aws/issues/4198)

### Running the tests with Tilt

This section explains how to run the E2E tests on AWS using a management cluster run by Tilt.

This section assumes you have *kind* and *Docker* installed. (See [Prerequisites](https://cluster-api.sigs.k8s.io/developer/tilt#prerequisites))

First, clone the upstream cluster-api and cluster-api-provider-aws repositories.
```shell
git clone https://github.com/kubernetes-sigs/cluster-api.git
git clone https://github.com/kubernetes-sigs/cluster-api-provider-aws.git
```

Next, you need to create a `tilt-settings.yaml` file inside the `cluster-api` directory.
The kustomize_substitutions you provide here are automatically applied to the *management cluster*.
```shell
default_registry: "ghcr.io/canonical/cluster-api-k8s"
provider_repos:
- ../cluster-api-k8s
- ../cluster-api-provider-aws
enable_providers:
- aws
- ck8s-bootstrap
- ck8s-control-plane
```

Tilt will know how to run the aws provider controllers because the `cluster-api-provider-aws` repository has a `tilt-provider.yaml` file at it's root. Canonical Kubernetes also provides this file at the root of the repository. The CK8s provider names, ck8s-bootstrap and ck8s-control-plane, are defined in CK8's `tilt-provider.yaml` file.

Next, you have to customize the variables that will be substituted into the cluster templates applied by the tests (these are under `test/e2e/data/infrastructure-aws`). You can customize the variables in the `test/e2e/config/ck8s-aws.yaml` file under the `variables` key.

Finally, in one terminal, go into the `cluster-api` directory and run `make tilt-up`. You should see a kind cluster be created, and finally a message indicating that Tilt is available at a certain address.

In a second terminal in the `cluster-api-k8s` directory, run `make USE_EXISTING_CLUSTER=true test-e2e`.

### Cleaning up after an e2e test

The test framework tries it's best to cleanup resources after a test suite, but it is possible that
cloud resources are left over. This can be very problematic especially if you run the tests multiple times
while iterating on development (see [Cluster API Book - Tear down](https://cluster-api.sigs.k8s.io/developer/e2e#tear-down)).

You can use a tool like [aws-nuke](https://github.com/eriksten/aws-nuke) to cleanup your AWS account after a test.

## Develop an e2e test

Refer to [Developing E2E tests](https://cluster-api.sigs.k8s.io/developer/e2e) for a complete guide for developing e2e tests.
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/cluster_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package e2e
import (
. "github.com/onsi/ginkgo/v2"
"k8s.io/utils/ptr"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
)

var _ = Describe("Workload cluster upgrade [CK8s-Upgrade]", func() {
Expand All @@ -33,7 +34,7 @@ var _ = Describe("Workload cluster upgrade [CK8s-Upgrade]", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
InfrastructureProvider: ptr.To("docker"),
InfrastructureProvider: ptr.To(clusterctl.DefaultInfrastructureProvider),
ControlPlaneMachineCount: ptr.To[int64](3),
WorkerMachineCount: ptr.To[int64](1),
}
Expand Down
128 changes: 128 additions & 0 deletions test/e2e/config/ck8s-aws.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
managementClusterName: capi-test

# E2E test scenario using local dev images and manifests built from the source tree for following providers:
# - bootstrap ck8s
# - control-plane ck8s
images:
# Use local dev images built source tree;
- name: ghcr.io/canonical/cluster-api-k8s/controlplane-controller:dev
loadBehavior: mustLoad
- name: ghcr.io/canonical/cluster-api-k8s/bootstrap-controller:dev
loadBehavior: mustLoad

# List of providers that will be installed into the management cluster
# See InitManagementClusterAndWatchControllerLogs function call
providers:
- name: cluster-api
type: CoreProvider
versions:
- name: v1.8.4
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.4/core-components.yaml
type: url
contract: v1beta1
files:
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
replacements:
- old: "imagePullPolicy: Always"
new: "imagePullPolicy: IfNotPresent"
- name: aws
type: InfrastructureProvider
versions:
- name: v2.6.1
value: "https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/infrastructure-components.yaml"
type: url
contract: v1beta2
files:
- sourcePath: "../data/shared/v1beta1_aws/metadata.yaml"
replacements:
- old: "imagePullPolicy: Always"
new: "imagePullPolicy: IfNotPresent"

# when bootstrapping with tilt, it will use
# https://github.com/kubernetes-sigs/cluster-api/blob/main/hack/tools/internal/tilt-prepare/main.go
# name here should match defaultProviderVersion
eaudetcobello marked this conversation as resolved.
Show resolved Hide resolved
- name: v1.9.99
value: "https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/infrastructure-components.yaml"
type: url
contract: v1beta2
files:
- sourcePath: "../data/shared/v1beta1_aws/metadata.yaml"
replacements:
- old: "imagePullPolicy: Always"
new: "imagePullPolicy: IfNotPresent"
files:
- sourcePath: "../data/infrastructure-aws/cluster-template.yaml"
- name: ck8s
type: BootstrapProvider
versions:
# Could add older release version for upgrading test, but
# by default, will only use the latest version defined in
# ${ProjectRoot}/metadata.yaml to init the management cluster
# this version should be updated when ${ProjectRoot}/metadata.yaml
# is modified
- name: v0.1.99 # next; use manifest from source files
value: "../../../bootstrap/config/default"
replacements:
- old: "ghcr.io/canonical/cluster-api-k8s/bootstrap-controller:latest"
new: "ghcr.io/canonical/cluster-api-k8s/bootstrap-controller:dev"
files:
- sourcePath: "../../../metadata.yaml"
- name: ck8s
type: ControlPlaneProvider
versions:
- name: v0.1.99 # next; use manifest from source files
value: "../../../controlplane/config/default"
replacements:
- old: "ghcr.io/canonical/cluster-api-k8s/controlplane-controller:latest"
new: "ghcr.io/canonical/cluster-api-k8s/controlplane-controller:dev"
files:
- sourcePath: "../../../metadata.yaml"

# These variables replace the variables in test/e2e/data/infrastructure-aws manifests
# They are used during clusterctl generate cluster
variables:
KUBERNETES_VERSION_MANAGEMENT: "v1.30.0"
KUBERNETES_VERSION: "v1.30.0"
KUBERNETES_VERSION_UPGRADE_TO: "v1.30.1"
IP_FAMILY: "IPv4"
KIND_IMAGE_VERSION: "v1.30.0"
AWS_CONTROL_PLANE_INSTANCE_TYPE: t3.large
AWS_NODE_INSTANCE_TYPE: t3.large
AWS_PUBLIC_IP: true
AWS_CREATE_BASTION: true
AWS_SSH_KEY_NAME: "default"
AWS_AMI_ID: "ami-01b139e6226d65e4f"
AWS_CONTROL_PLANE_ROOT_VOLUME_SIZE: 16
AWS_NODE_ROOT_VOLUME_SIZE: 16
AWS_REGION: "us-east-2"
AWS_CCM_IMAGE: "registry.k8s.io/provider-aws/cloud-controller-manager:v1.28.3"
# https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/test/e2e/data/e2e_conf.yaml#L203C1-L205C27
# There is some work to be done here on figuring out which experimental features
# we want to enable/disable.
EXP_CLUSTER_RESOURCE_SET: "true"
EXP_MACHINE_SET_PREFLIGHT_CHECKS: "false"
CLUSTER_TOPOLOGY: "true"
CAPA_LOGLEVEL: "4"

intervals:
# Ref: https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/test/e2e/data/e2e_conf.yaml
default/wait-machines: [ "35m", "10s" ]
default/wait-cluster: [ "35m", "10s" ]
default/wait-control-plane: [ "35m", "10s" ]
default/wait-worker-nodes: [ "35m", "10s" ]
conformance/wait-control-plane: [ "35m", "10s" ]
conformance/wait-worker-nodes: [ "35m", "10s" ]
default/wait-controllers: [ "35m", "10s" ]
default/wait-delete-cluster: [ "35m", "10s" ]
default/wait-machine-upgrade: [ "35m", "10s" ]
default/wait-contolplane-upgrade: [ "35m", "10s" ]
default/wait-machine-status: [ "35m", "10s" ]
default/wait-failed-machine-status: [ "35m", "10s" ]
default/wait-infra-subnets: [ "5m", "30s" ]
default/wait-machine-pool-nodes: [ "35m", "10s" ]
default/wait-machine-pool-upgrade: [ "35m", "10s" ]
default/wait-create-identity: [ "3m", "10s" ]
default/wait-job: [ "35m", "10s" ]
default/wait-deployment-ready: [ "35m", "10s" ]
default/wait-loadbalancer-ready: [ "5m", "30s" ]
8 changes: 4 additions & 4 deletions test/e2e/config/ck8s-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ providers:
- name: cluster-api
type: CoreProvider
versions:
- name: v1.6.2
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.6.2/core-components.yaml
- name: v1.8.4
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.4/core-components.yaml
type: url
files:
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
Expand All @@ -28,8 +28,8 @@ providers:
versions:
# By default, will use the latest version defined in ../data/shared/v1beta1/metadata.yaml
# to init the management cluster
- name: v1.6.2 # used during e2e-test
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.6.2/infrastructure-components-development.yaml
- name: v1.8.4 # used during e2e-test
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.4/infrastructure-components-development.yaml
type: url
files:
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("Workload cluster creation", func() {
Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion))

clusterName = fmt.Sprintf("capick8s-create-%s", util.RandomString(6))
infrastructureProvider = "docker"
eaudetcobello marked this conversation as resolved.
Show resolved Hide resolved
infrastructureProvider = clusterctl.DefaultInfrastructureProvider

// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
namespace, cancelWatches = setupSpecNamespace(ctx, specName, bootstrapClusterProxy, artifactFolder)
Expand Down
Loading