From 1de01e5e3c3ae1ef48758d5514d0abe5cfe502fc Mon Sep 17 00:00:00 2001 From: Amol Deodhar Date: Wed, 1 May 2024 09:22:14 -0400 Subject: [PATCH] restructure e2e test resources to be more dry --- .../assert-child-cluster-resources.yaml | 61 -------- .../default-CAPL-cluster/chainsaw-test.yaml | 133 ------------------ .../minimal-linodecluster/chainsaw-test.yaml | 4 +- .../minimal-linodemachine/chainsaw-test.yaml | 4 +- .../minimal-linodemachine/create-cluster.yaml | 21 --- .../create-linodemachine.yaml | 32 ----- .../vpc-integration/chainsaw-test.yaml | 4 +- .../vpc-integration/create-cluster-vpc.yaml | 34 ----- .../chainsaw-test.yaml | 2 +- .../minimal-linodevpc/chainsaw-test.yaml | 2 +- .../assert-capi-capl-resources.yaml | 15 ++ e2e/test-resources/assert-linodemachine.yaml | 5 + e2e/test-resources/assert-linodevpc.yaml | 4 + .../cluster.yaml} | 0 e2e/test-resources/helmreleaseproxy.yaml | 14 ++ .../kubeadmcontrolplane.yaml} | 11 -- .../linodecluster.yaml} | 0 e2e/test-resources/linodemachine.yaml | 11 ++ e2e/test-resources/linodemachinetemplate.yaml | 9 ++ .../linodeobjectstoragebucket.yaml} | 0 e2e/test-resources/machine.yaml | 10 ++ e2e/test-resources/machinedeployment.yaml | 12 ++ .../vpc.yaml} | 0 23 files changed, 88 insertions(+), 300 deletions(-) delete mode 100644 e2e/capl-cluster-flavors/default-CAPL-cluster/assert-child-cluster-resources.yaml delete mode 100755 e2e/capl-cluster-flavors/default-CAPL-cluster/chainsaw-test.yaml delete mode 100644 e2e/linodemachine-controller/minimal-linodemachine/create-cluster.yaml delete mode 100644 e2e/linodemachine-controller/minimal-linodemachine/create-linodemachine.yaml delete mode 100644 e2e/linodemachine-controller/vpc-integration/create-cluster-vpc.yaml create mode 100644 e2e/test-resources/assert-capi-capl-resources.yaml create mode 100644 e2e/test-resources/assert-linodemachine.yaml create mode 100644 e2e/test-resources/assert-linodevpc.yaml rename e2e/{linodecluster-controller/minimal-linodecluster/create-cluster.yaml => test-resources/cluster.yaml} (100%) create mode 100644 e2e/test-resources/helmreleaseproxy.yaml rename e2e/{linodemachine-controller/vpc-integration/create-linodemachine.yaml => test-resources/kubeadmcontrolplane.yaml} (73%) rename e2e/{linodecluster-controller/minimal-linodecluster/create-linodecluster.yaml => test-resources/linodecluster.yaml} (100%) create mode 100644 e2e/test-resources/linodemachine.yaml create mode 100644 e2e/test-resources/linodemachinetemplate.yaml rename e2e/{linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/create-linodeobjectstoragebucket.yaml => test-resources/linodeobjectstoragebucket.yaml} (100%) create mode 100644 e2e/test-resources/machine.yaml create mode 100644 e2e/test-resources/machinedeployment.yaml rename e2e/{linodevpc-controller/minimal-linodevpc/create-vpc.yaml => test-resources/vpc.yaml} (100%) diff --git a/e2e/capl-cluster-flavors/default-CAPL-cluster/assert-child-cluster-resources.yaml b/e2e/capl-cluster-flavors/default-CAPL-cluster/assert-child-cluster-resources.yaml deleted file mode 100644 index a1575a44f..000000000 --- a/e2e/capl-cluster-flavors/default-CAPL-cluster/assert-child-cluster-resources.yaml +++ /dev/null @@ -1,61 +0,0 @@ ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachine -metadata: - labels: - cluster.x-k8s.io/cluster-name: ($cluster) -spec: - region: (env('LINODE_REGION')) - type: g6-standard-2 -status: - ready: true - instanceState: running ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Machine -metadata: - labels: - cluster.x-k8s.io/cluster-name: ($cluster) -spec: - clusterName: ($cluster) -status: - bootstrapReady: true - infrastructureReady: true ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: MachineDeployment -metadata: - labels: - cluster.x-k8s.io/cluster-name: ($cluster) -spec: - clusterName: ($cluster) - replicas: 1 -status: - readyReplicas: 1 - unavailableReplicas: 0 - availableReplicas: 1 ---- -apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -kind: KubeadmControlPlane -metadata: - labels: - cluster.x-k8s.io/cluster-name: ($cluster) -status: - readyReplicas: 1 - unavailableReplicas: 0 - ready: true ---- -apiVersion: addons.cluster.x-k8s.io/v1alpha1 -kind: HelmReleaseProxy -metadata: - labels: - cluster.x-k8s.io/cluster-name: ($cluster) -status: - conditions: - - type: Ready - status: "True" - - type: ClusterAvailable - status: "True" - - type: HelmReleaseReady - status: "True" - status: deployed diff --git a/e2e/capl-cluster-flavors/default-CAPL-cluster/chainsaw-test.yaml b/e2e/capl-cluster-flavors/default-CAPL-cluster/chainsaw-test.yaml deleted file mode 100755 index 687ee2c1d..000000000 --- a/e2e/capl-cluster-flavors/default-CAPL-cluster/chainsaw-test.yaml +++ /dev/null @@ -1,133 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json -apiVersion: chainsaw.kyverno.io/v1alpha1 -kind: Test -metadata: - creationTimestamp: null - name: default-capl-cluster - # Labels to allow the test to be triggered based on selector flag - labels: - default-cluster: - flavors: - all: -spec: - bindings: - # A short identifier for the E2E test run - - name: run - value: (join('-', ['e2e', 'default-cluster', env('GIT_REF')])) - - name: cluster - # Format the cluster name - value: (trim((truncate(($run), `32`)), '-')) - template: true - steps: - - name: Check if CAPI provider resources exist - try: - - assert: - file: assert-capi-resources.yaml - - name: Generate cluster using clusterctl - try: - - script: - env: - - name: CLUSTER - value: ($cluster) - - name: NAMESPACE - value: ($namespace) - - name: CLUSTERCTL_CONFIG - value: (env('CLUSTERCTL_CONFIG')) - content: | - set -e - clusterctl generate cluster $CLUSTER -n $NAMESPACE \ - --kubernetes-version v1.29.1 \ - --infrastructure local-linode:v0.0.0 \ - --control-plane-machine-count 1 --worker-machine-count 1 \ - --config $CLUSTERCTL_CONFIG > default-cluster.yaml - check: - ($error == null): true - - name: Apply generated cluster yaml - try: - - apply: - file: default-cluster.yaml - - assert: - file: assert-child-cluster-resources.yaml - catch: - - describe: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachine - - describe: - apiVersion: cluster.x-k8s.io/v1beta1 - kind: Machine - - describe: - apiVersion: cluster.x-k8s.io/v1beta1 - kind: MachineDeployment - - describe: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlane - - describe: - apiVersion: addons.cluster.x-k8s.io/v1alpha1 - kind: HelmReleaseProxy - - name: Check if the linodes are created - try: - - script: - env: - - name: TARGET_API - value: api.linode.com - - name: TARGET_API_VERSION - value: v4beta - - name: URI - value: linode/instances - - name: FILTER - value: (to_string({"tags":($cluster)})) - content: | - set -e - curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "X-Filter: $FILTER" \ - -H "Content-Type: application/json" \ - "https://$TARGET_API/$TARGET_API_VERSION/$URI" - check: - ($error): ~ - (json_parse($stdout)): - results: 2 - - name: Delete child cluster - try: - - delete: - ref: - apiVersion: cluster.x-k8s.io/v1beta1 - kind: Cluster - name: ($cluster) - - delete: - ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeVPC - name: ($cluster) - - error: - file: check-child-cluster-and-vpc-deleted.yaml - - name: Check if the linodes are deleted - try: - - script: - env: - - name: TARGET_API - value: api.linode.com - - name: TARGET_API_VERSION - value: v4beta - - name: URI - value: linode/instances - - name: FILTER - value: (to_string({"tags":($cluster)})) - content: | - set -e - curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "X-Filter: $FILTER" \ - -H "Content-Type: application/json" \ - "https://$TARGET_API/$TARGET_API_VERSION/$URI" - check: - ($error): ~ - (json_parse($stdout)): - results: 0 - - name: Delete generated child cluster manifest yaml - try: - - script: - content: | - rm -f default-cluster.yaml - check: - ($error == null): true diff --git a/e2e/linodecluster-controller/minimal-linodecluster/chainsaw-test.yaml b/e2e/linodecluster-controller/minimal-linodecluster/chainsaw-test.yaml index 1ab13799e..15f1260a1 100755 --- a/e2e/linodecluster-controller/minimal-linodecluster/chainsaw-test.yaml +++ b/e2e/linodecluster-controller/minimal-linodecluster/chainsaw-test.yaml @@ -28,7 +28,7 @@ spec: - name: Create Cluster resource try: - apply: - file: create-cluster.yaml + file: ../../test-resources/cluster.yaml catch: - describe: apiVersion: cluster.x-k8s.io/v1beta1 @@ -36,7 +36,7 @@ spec: - name: Create LinodeCluster resource try: - apply: - file: create-linodecluster.yaml + file: ../../test-resources/linodecluster.yaml - assert: file: assert-linodecluster.yaml catch: diff --git a/e2e/linodemachine-controller/minimal-linodemachine/chainsaw-test.yaml b/e2e/linodemachine-controller/minimal-linodemachine/chainsaw-test.yaml index b44d66244..281c4d0a4 100755 --- a/e2e/linodemachine-controller/minimal-linodemachine/chainsaw-test.yaml +++ b/e2e/linodemachine-controller/minimal-linodemachine/chainsaw-test.yaml @@ -26,7 +26,7 @@ spec: - name: Create Cluster resource try: - apply: - file: create-cluster.yaml + file: ../../test-resources/cluster.yaml catch: - describe: apiVersion: cluster.x-k8s.io/v1beta1 @@ -34,7 +34,7 @@ spec: - name: Create LinodeMachine resource try: - apply: - file: create-linodemachine.yaml + file: ../../test-resources/linodemachine.yaml - assert: file: assert-linodemachine.yaml catch: diff --git a/e2e/linodemachine-controller/minimal-linodemachine/create-cluster.yaml b/e2e/linodemachine-controller/minimal-linodemachine/create-cluster.yaml deleted file mode 100644 index 1914a1737..000000000 --- a/e2e/linodemachine-controller/minimal-linodemachine/create-cluster.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: ($cluster) -spec: - controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlane - name: ($cluster) - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeCluster - name: ($cluster) ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeCluster -metadata: - name: ($cluster) -spec: - region: us-sea diff --git a/e2e/linodemachine-controller/minimal-linodemachine/create-linodemachine.yaml b/e2e/linodemachine-controller/minimal-linodemachine/create-linodemachine.yaml deleted file mode 100644 index 67b11b6fd..000000000 --- a/e2e/linodemachine-controller/minimal-linodemachine/create-linodemachine.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -kind: KubeadmControlPlane -metadata: - name: ($cluster) -spec: - kubeadmConfigSpec: - clusterConfiguration: - apiServer: - extraArgs: - cloud-provider: external - controllerManager: - extraArgs: - cloud-provider: external - machineTemplate: - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachineTemplate - name: ($cluster) - replicas: 1 - version: 1.29.1 ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachineTemplate -metadata: - name: ($cluster) -spec: - template: - spec: - region: us-sea - type: g5-nanode-1 - diff --git a/e2e/linodemachine-controller/vpc-integration/chainsaw-test.yaml b/e2e/linodemachine-controller/vpc-integration/chainsaw-test.yaml index 4911cdc9c..00ea8fe93 100755 --- a/e2e/linodemachine-controller/vpc-integration/chainsaw-test.yaml +++ b/e2e/linodemachine-controller/vpc-integration/chainsaw-test.yaml @@ -30,7 +30,7 @@ spec: - name: Create Cluster and LinodeVPC resources try: - apply: - file: create-cluster-vpc.yaml + file: ../../test-resources/vpc.yaml - assert: file: assert-vpc.yaml catch: @@ -46,7 +46,7 @@ spec: - name: Create LinodeMachine resource try: - apply: - file: create-linodemachine.yaml + file: ../../test-resources/linodemachine.yaml - assert: file: assert-linodemachine.yaml catch: diff --git a/e2e/linodemachine-controller/vpc-integration/create-cluster-vpc.yaml b/e2e/linodemachine-controller/vpc-integration/create-cluster-vpc.yaml deleted file mode 100644 index eb7fabafd..000000000 --- a/e2e/linodemachine-controller/vpc-integration/create-cluster-vpc.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: ($cluster) -spec: - controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlane - name: ($cluster) - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeCluster - name: ($cluster) ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeCluster -metadata: - name: ($cluster) -spec: - region: us-sea - vpcRef: - kind: LinodeVPC - name: ($vpc) ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeVPC -metadata: - name: ($vpc) -spec: - region: us-sea - subnets: - - label: test-subnet - ipv4: 10.0.0.0/24 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml index 165cd2025..61db6a39b 100755 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml @@ -28,7 +28,7 @@ spec: - name: Create LinodeObjectStorageBucket try: - apply: - file: create-linodeobjectstoragebucket.yaml + file: ../../test-resources/linodeobjectstoragebucket.yaml - assert: file: assert-obj-and-secret.yaml catch: diff --git a/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml b/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml index 8fd770845..f2f186bf2 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml @@ -25,7 +25,7 @@ spec: - name: Create LinodeVPC try: - apply: - file: create-vpc.yaml + file: ../../test-resources/vpc.yaml - assert: file: assert-vpc.yaml catch: diff --git a/e2e/test-resources/assert-capi-capl-resources.yaml b/e2e/test-resources/assert-capi-capl-resources.yaml new file mode 100644 index 000000000..8a5b8dbab --- /dev/null +++ b/e2e/test-resources/assert-capi-capl-resources.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: capi-controller-manager + namespace: capi-system +status: + availableReplicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: capl-controller-manager + namespace: capl-system +status: + availableReplicas: 1 diff --git a/e2e/test-resources/assert-linodemachine.yaml b/e2e/test-resources/assert-linodemachine.yaml new file mode 100644 index 000000000..81cd1fd17 --- /dev/null +++ b/e2e/test-resources/assert-linodemachine.yaml @@ -0,0 +1,5 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachine +metadata: + labels: + cluster.x-k8s.io/cluster-name: ($cluster) diff --git a/e2e/test-resources/assert-linodevpc.yaml b/e2e/test-resources/assert-linodevpc.yaml new file mode 100644 index 000000000..70ebae6b4 --- /dev/null +++ b/e2e/test-resources/assert-linodevpc.yaml @@ -0,0 +1,4 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeVPC +metadata: + name: ($cluster) diff --git a/e2e/linodecluster-controller/minimal-linodecluster/create-cluster.yaml b/e2e/test-resources/cluster.yaml similarity index 100% rename from e2e/linodecluster-controller/minimal-linodecluster/create-cluster.yaml rename to e2e/test-resources/cluster.yaml diff --git a/e2e/test-resources/helmreleaseproxy.yaml b/e2e/test-resources/helmreleaseproxy.yaml new file mode 100644 index 000000000..34071efef --- /dev/null +++ b/e2e/test-resources/helmreleaseproxy.yaml @@ -0,0 +1,14 @@ +apiVersion: addons.cluster.x-k8s.io/v1alpha1 +kind: HelmReleaseProxy +metadata: + labels: + cluster.x-k8s.io/cluster-name: ($cluster) +status: + conditions: + - type: Ready + status: "True" + - type: ClusterAvailable + status: "True" + - type: HelmReleaseReady + status: "True" + status: deployed diff --git a/e2e/linodemachine-controller/vpc-integration/create-linodemachine.yaml b/e2e/test-resources/kubeadmcontrolplane.yaml similarity index 73% rename from e2e/linodemachine-controller/vpc-integration/create-linodemachine.yaml rename to e2e/test-resources/kubeadmcontrolplane.yaml index 0cdbaf44a..f10b401ba 100644 --- a/e2e/linodemachine-controller/vpc-integration/create-linodemachine.yaml +++ b/e2e/test-resources/kubeadmcontrolplane.yaml @@ -1,4 +1,3 @@ ---- apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlane metadata: @@ -19,13 +18,3 @@ spec: name: ($cluster) replicas: 1 version: 1.29.1 ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachineTemplate -metadata: - name: ($cluster) -spec: - template: - spec: - region: us-sea - type: g5-nanode-1 diff --git a/e2e/linodecluster-controller/minimal-linodecluster/create-linodecluster.yaml b/e2e/test-resources/linodecluster.yaml similarity index 100% rename from e2e/linodecluster-controller/minimal-linodecluster/create-linodecluster.yaml rename to e2e/test-resources/linodecluster.yaml diff --git a/e2e/test-resources/linodemachine.yaml b/e2e/test-resources/linodemachine.yaml new file mode 100644 index 000000000..20782a0e2 --- /dev/null +++ b/e2e/test-resources/linodemachine.yaml @@ -0,0 +1,11 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachine +metadata: + labels: + cluster.x-k8s.io/cluster-name: ($cluster) +spec: + region: (env('LINODE_REGION')) + type: g6-standard-2 +status: + ready: true + instanceState: running diff --git a/e2e/test-resources/linodemachinetemplate.yaml b/e2e/test-resources/linodemachinetemplate.yaml new file mode 100644 index 000000000..a8ab26e1f --- /dev/null +++ b/e2e/test-resources/linodemachinetemplate.yaml @@ -0,0 +1,9 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachineTemplate +metadata: + name: ($cluster) +spec: + template: + spec: + region: us-sea + type: g5-nanode-1 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/create-linodeobjectstoragebucket.yaml b/e2e/test-resources/linodeobjectstoragebucket.yaml similarity index 100% rename from e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/create-linodeobjectstoragebucket.yaml rename to e2e/test-resources/linodeobjectstoragebucket.yaml diff --git a/e2e/test-resources/machine.yaml b/e2e/test-resources/machine.yaml new file mode 100644 index 000000000..2157b114a --- /dev/null +++ b/e2e/test-resources/machine.yaml @@ -0,0 +1,10 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Machine +metadata: + labels: + cluster.x-k8s.io/cluster-name: ($cluster) +spec: + clusterName: ($cluster) +status: + bootstrapReady: true + infrastructureReady: true diff --git a/e2e/test-resources/machinedeployment.yaml b/e2e/test-resources/machinedeployment.yaml new file mode 100644 index 000000000..c762a7055 --- /dev/null +++ b/e2e/test-resources/machinedeployment.yaml @@ -0,0 +1,12 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: MachineDeployment +metadata: + labels: + cluster.x-k8s.io/cluster-name: ($cluster) +spec: + clusterName: ($cluster) + replicas: 1 +status: + readyReplicas: 1 + unavailableReplicas: 0 + availableReplicas: 1 diff --git a/e2e/linodevpc-controller/minimal-linodevpc/create-vpc.yaml b/e2e/test-resources/vpc.yaml similarity index 100% rename from e2e/linodevpc-controller/minimal-linodevpc/create-vpc.yaml rename to e2e/test-resources/vpc.yaml