diff --git a/.github/workflows/build_test_ci.yml b/.github/workflows/build_test_ci.yml index 269aa1536..d8ec43936 100644 --- a/.github/workflows/build_test_ci.yml +++ b/.github/workflows/build_test_ci.yml @@ -161,67 +161,6 @@ jobs: path: .logs/* overwrite: true - chainsaw-test: - needs: [go-build-test, docker-build] - runs-on: ubuntu-latest - steps: - - name: Harden Runner - uses: step-security/harden-runner@v2 - with: - disable-sudo: true - egress-policy: block - allowed-endpoints: > - api.linode.com:443 - api.github.com:443 - github.com:443 - gcr.io:443 - proxy.golang.org:443 - sum.golang.org:443 - *.githubusercontent.com:443 - docker.io:443 - registry-1.docker.io:443 - auth.docker.io:443 - production.cloudflare.docker.com:443 - storage.googleapis.com:443 - registry.k8s.io:443 - *.pkg.dev:443 - *.amazonaws.com:443 - *.blob.core.windows.net:443 - quay.io:443 - *.quay.io:443 - api.snapcraft.io:443 - cloud.tilt.dev:443 - - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - check-latest: true - - - name: Docker cache - uses: ScribeMD/docker-cache@0.3.7 - with: - key: docker-${{ runner.os }}-${{ hashFiles('go.sum') }}} - - - name: Chainsaw test - run: make chainsaw-test - env: - GITHUB_TOKEN: ${{ secrets.github_token }} - LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }} - - - name: Copy logs - if: ${{ always() }} - run: docker cp tilt-control-plane:/var/log .logs - - - uses: actions/upload-artifact@v4 - if: ${{ always() }} - with: - name: logs - path: .logs/* - overwrite: true - docker-build: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index 354c3b997..0e981e066 100644 --- a/Makefile +++ b/Makefile @@ -137,27 +137,18 @@ test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -race -timeout 60s ./... -coverprofile cover.out .PHONY: e2etest -e2etest: - make --no-print-directory _e2etest # Workaround to force the flag on Github Action +e2etest: manifests generate local-deploy chainsaw + $(CHAINSAW) test ./e2e -local-deploy: kind ctlptl tilt kuttl chainsaw kustomize clusterctl +local-deploy: kind ctlptl tilt kustomize clusterctl @echo -n "LINODE_TOKEN=$(LINODE_TOKEN)" > config/default/.env.linode $(CTLPTL) apply -f .tilt/ctlptl-config.yaml $(TILT) ci --timeout 240s -f Tiltfile -_e2etest: manifests generate local-deploy - ROOT_DIR="$(PWD)" $(KUTTL) test --config e2e/kuttl-config.yaml - -.PHONY: chainsaw-test -chainsaw-test: manifests generate local-deploy - $(CHAINSAW) test ./e2e/linodecluster-controller ./e2e/linodemachine-controller - ## -------------------------------------- ## Build ## -------------------------------------- -##@ Build: - .PHONY: build build: manifests generate fmt vet ## Build manager binary. go build -ldflags="-X github.com/linode/cluster-api-provider-linode/version.version=$(VERSION)" -o bin/manager cmd/main.go @@ -298,7 +289,6 @@ CLUSTERCTL ?= $(LOCALBIN)/clusterctl CONTROLLER_GEN ?= $(CACHE_BIN)/controller-gen TILT ?= $(LOCALBIN)/tilt KIND ?= $(LOCALBIN)/kind -KUTTL ?= $(LOCALBIN)/kubectl-kuttl CHAINSAW ?= $(CACHE_BIN)/chainsaw ENVTEST ?= $(CACHE_BIN)/setup-envtest HUSKY ?= $(LOCALBIN)/husky @@ -313,7 +303,6 @@ CLUSTERCTL_VERSION ?= v1.5.3 CONTROLLER_TOOLS_VERSION ?= v0.14.0 TILT_VERSION ?= 0.33.6 KIND_VERSION ?= 0.20.0 -KUTTL_VERSION ?= 0.15.0 CHAINSAW_VERSION ?= v0.1.7 HUSKY_VERSION ?= v0.2.16 NILAWAY_VERSION ?= latest @@ -321,7 +310,8 @@ GOVULNC_VERSION ?= v1.0.1 MOCKGEN_VERSION ?= v0.4.0 .PHONY: tools -tools: $(KUSTOMIZE) $(CTLPTL) $(CLUSTERCTL) $(CONTROLLER_GEN) $(TILT) $(KIND) $(KUTTL) $(CHAINSAW) $(ENVTEST) $(HUSKY) $(NILAWAY) $(GOVULNC) $(MOCKGEN) +tools: $(KUSTOMIZE) $(CTLPTL) $(CLUSTERCTL) $(CONTROLLER_GEN) $(TILT) $(KIND) $(CHAINSAW) $(ENVTEST) $(HUSKY) $(NILAWAY) $(GOVULNC) $(MOCKGEN) + .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -360,12 +350,6 @@ $(KIND): $(LOCALBIN) curl -Lso $(KIND) https://github.com/kubernetes-sigs/kind/releases/download/v$(KIND_VERSION)/kind-$(OS)-$(ARCH_SHORT) chmod +x $(KIND) -.PHONY: kuttl -kuttl: $(KUTTL) ## Download kuttl locally if necessary. -$(KUTTL): $(LOCALBIN) - curl -Lso $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_$(OS)_$(ARCH) - chmod +x $(KUTTL) - .PHONY: chainsaw chainsaw: $(CHAINSAW) ## Download chainsaw locally if necessary. $(CHAINSAW): $(CACHE_BIN) diff --git a/cloud/services/object_storage_buckets.go b/cloud/services/object_storage_buckets.go index 864ea5d4d..95a5f6c06 100644 --- a/cloud/services/object_storage_buckets.go +++ b/cloud/services/object_storage_buckets.go @@ -11,28 +11,22 @@ import ( utilerrors "k8s.io/apimachinery/pkg/util/errors" "github.com/linode/cluster-api-provider-linode/cloud/scope" - "github.com/linode/cluster-api-provider-linode/util" ) func EnsureObjectStorageBucket(ctx context.Context, bScope *scope.ObjectStorageBucketScope) (*linodego.ObjectStorageBucket, error) { - // Buckets do not have IDs so hardcode it to 0 - listFilter := util.Filter{ - ID: nil, - Label: *bScope.Bucket.Spec.Label, - Tags: nil, - } - buckets, err := bScope.LinodeClient.ListObjectStorageBucketsInCluster( + bucket, err := bScope.LinodeClient.GetObjectStorageBucket( ctx, - linodego.NewListOptions(1, listFilter.String()), bScope.Bucket.Spec.Cluster, + *bScope.Bucket.Spec.Label, ) - if err != nil { - return nil, fmt.Errorf("failed to list buckets in cluster %s: %w", bScope.Bucket.Spec.Cluster, err) + linodeErr := &linodego.Error{} + if errors.As(err, linodeErr) && linodeErr.StatusCode() != http.StatusNotFound { + return nil, fmt.Errorf("failed to get bucket from cluster %s: %w", bScope.Bucket.Spec.Cluster, err) } - if len(buckets) == 1 { + if bucket != nil { bScope.Logger.Info("Bucket exists") - return &buckets[0], nil + return bucket, nil } opts := linodego.ObjectStorageBucketCreateOptions{ @@ -41,7 +35,6 @@ func EnsureObjectStorageBucket(ctx context.Context, bScope *scope.ObjectStorageB ACL: linodego.ACLPrivate, } - var bucket *linodego.ObjectStorageBucket if bucket, err = bScope.LinodeClient.CreateObjectStorageBucket(ctx, opts); err != nil { return nil, fmt.Errorf("failed to create bucket: %w", err) } diff --git a/controller/linodeobjectstoragebucket_controller.go b/controller/linodeobjectstoragebucket_controller.go index f9c8fb5c1..0a059b443 100644 --- a/controller/linodeobjectstoragebucket_controller.go +++ b/controller/linodeobjectstoragebucket_controller.go @@ -54,9 +54,9 @@ type LinodeObjectStorageBucketReconciler struct { ReconcileTimeout time.Duration } -//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/finalizers,verbs=update +// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/finalizers,verbs=update // +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch // +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch;create;update;patch diff --git a/docs/src/developers/testing.md b/docs/src/developers/testing.md new file mode 100644 index 000000000..61d9badc9 --- /dev/null +++ b/docs/src/developers/testing.md @@ -0,0 +1,39 @@ +# CAPL Testing + +## Unit Tests +### Running Tests +In order to run the unit tests run the following command +```bash +make test +``` + +## E2E Tests +For e2e tests CAPL uses the [Chainsaw project](https://kyverno.github.io/chainsaw) which leverages `kind` and `tilt` to +spin up a cluster with the CAPL controllers installed and then uses `chainsaw-test.yaml` files to drive e2e testing. + +All test live in the e2e folder with a directory structure of `e2e/${CONTROLLER_NAME}/${TEST_NAME}` +### Running tests +In order to run e2e tests run the following command +```bash +make e2etest +``` +### Adding tests +1. Create a new directory under the controller you are testing with the naming scheme of `e2e/${CONTROLLER_NAME}/${TEST_NAME}` +2. Create a minimal `chainsaw-test.yaml` file in the new test dir + ```yaml + # 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: + name: $TEST_NAME + spec: + template: true # set to true if you are going to use any chainsaw templating + steps: + - name: step-01 + try: + - apply: + file: ${resource_name}.yaml + - assert: + file: 01-assert.yaml + ``` +3. Add any resources to create or assert on in the same directory \ No newline at end of file diff --git a/e2e/Makefile b/e2e/Makefile deleted file mode 100644 index 001c2a366..000000000 --- a/e2e/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -ROOT_DIR ?= $(shell git rev-parse --show-toplevel) -TARGET_API ?= api.linode.com -TARGET_API_VERSION ?= v4beta - -export PATH := $(ROOT_DIR)/bin:$(ROOT_DIR)/.devbox/nix/profile/default/bin:$(PATH) -runThisTest: - @echo "PLease execute make -C ($ROOT_DIR)/Makefile _e2etest-infra to spin up infrastructure" - make --no-print-directory _runThisTest - -_runThisTest: - @D="$$(mktemp -d)" ;\ - cp $(ROOT_DIR)/e2e/Makefile $$D ;\ - mkdir $$D/suite ;\ - cp -r $(PWD) $$D/suite ;\ - ROOT_DIR=$(ROOT_DIR) KUBECONFIG="$(ROOT_DIR)/kubeconfig" kubectl-kuttl test --timeout 300 --skip-delete "$$D/suite" - -callLinodeApiGet: - @curl -s -H "Authorization: Bearer $$LINODE_TOKEN" -H "X-Filter: $$FILTER" -H "Content-Type: application/json" "https://$(TARGET_API)/$(TARGET_API_VERSION)/$$URI" - -callLinodeApiPost: - @curl -s -H "Authorization: Bearer $$LINODE_TOKEN" -H "Content-Type: application/json" -d "$$BODY" -X POST "https://$(TARGET_API)/$(TARGET_API_VERSION)/$$URI" - -callLinodeApiDelete: - @curl -s -H "Authorization: Bearer $$LINODE_TOKEN" -X DELETE "https://$(TARGET_API)/$(TARGET_API_VERSION)/$$URI" diff --git a/e2e/README.MD b/e2e/README.MD deleted file mode 100644 index 9ab71aa1d..000000000 --- a/e2e/README.MD +++ /dev/null @@ -1,45 +0,0 @@ -# E2E Framework - -The E2E framework uses Kuttl under the hood. Kuttl is a simple and most importantly static tool that handles applying manifests for running assertions in a namespace it generates for each test. - - -Helper functions can be invoked in the scripts by creating a Makefile in each test folder that references `../../Makefile` (i.e. `e2e/Makefile`) in order to do custom validation. - -## Example TestStep - -```yaml -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="nodebalancers" FILTER="{\"label\":\"cluster-test-api-server\"}" make callLinodeApiGet | grep 'results": 1' -``` - -## Test Execution - -Note that test execution order is not guaranteed. If a test depends on another resource it is strongly suggested to create `assert` files to wait for an event. Almost every test depends on CAPI providers, so there is a good chance you have to create a `00-assert.yaml` in your test folder that asserts the following: - -```yaml -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 -``` - -## Executing individual tests - -```bash -make local-deploy # Only once per cluster! -(cd e2e/linodemachine-controller/minimal-linodemachine ; make runThisTest) -``` diff --git a/e2e/kind-config.yaml b/e2e/kind-config.yaml index 93bbb102a..f9cf64741 100644 --- a/e2e/kind-config.yaml +++ b/e2e/kind-config.yaml @@ -1,6 +1,6 @@ kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 -name: kuttl +name: e2e nodes: - role: control-plane image: kindest/node:v1.28.0 diff --git a/e2e/kuttl-config.yaml b/e2e/kuttl-config.yaml deleted file mode 100644 index 1cc493a93..000000000 --- a/e2e/kuttl-config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestSuite -testDirs: -- e2e/linodevpc-controller -- e2e/linodeobjectstoragebucket-controller -timeout: 300 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/00-ensure-no-bucket.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/00-ensure-no-bucket.yaml deleted file mode 100644 index ae0bf51a7..000000000 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/00-ensure-no-bucket.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="object-storage/buckets/us-sea-1/linodeobjectstoragebucket-sample" make callLinodeApiDelete || exit 0 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-assert.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-assert.yaml index c7c0bf831..10bb30144 100644 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-assert.yaml +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-assert.yaml @@ -1,11 +1,17 @@ +--- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeObjectStorageBucket metadata: - name: linodeobjectstoragebucket-sample + name: (join('-', [$namespace, 'backups'])) spec: cluster: us-sea-1 keyGeneration: 0 status: ready: true - keySecretName: linodeobjectstoragebucket-sample-access-keys + keySecretName: (join('-', [$namespace, 'backups-access-keys'])) lastKeyGeneration: 0 +--- +apiVersion: v1 +kind: Secret +metadata: + name: (join('-', [$namespace, 'backups-access-keys'])) diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-create-linodeobjectstoragebucket.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-create-linodeobjectstoragebucket.yaml index c070bdf20..786398a30 100644 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-create-linodeobjectstoragebucket.yaml +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/01-create-linodeobjectstoragebucket.yaml @@ -1,6 +1,6 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeObjectStorageBucket metadata: - name: linodeobjectstoragebucket-sample + name: (join('-', [$namespace, 'backups'])) spec: cluster: us-sea-1 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/02-verify-bucket-and-secret.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/02-verify-bucket-and-secret.yaml deleted file mode 100644 index d50521397..000000000 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/02-verify-bucket-and-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="object-storage/buckets/us-sea-1" FILTER="" make callLinodeApiGet | grep linodeobjectstoragebucket-sample.us-sea-1.linodeobjects.com - - script: |- - secret=$(kubectl -n $NAMESPACE get secret linodeobjectstoragebucket-sample-access-keys -oyaml) - echo $secret | grep read_write - echo $secret | grep read_only diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-assert.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-assert.yaml index f06e6bfb2..81cea04fe 100644 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-assert.yaml +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-assert.yaml @@ -1,11 +1,11 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeObjectStorageBucket metadata: - name: linodeobjectstoragebucket-sample + name: (join('-', [$namespace, 'backups'])) spec: cluster: us-sea-1 keyGeneration: 1 status: ready: true - keySecretName: linodeobjectstoragebucket-sample-access-keys + keySecretName: (join('-', [$namespace, 'backups-access-keys'])) lastKeyGeneration: 1 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-patch-bucket.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-patch-bucket.yaml index aee98b733..d319d99cb 100644 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-patch-bucket.yaml +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/03-patch-bucket.yaml @@ -1,7 +1,7 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeObjectStorageBucket metadata: - name: linodeobjectstoragebucket-sample + name: (join('-', [$namespace, 'backups'])) spec: cluster: us-sea-1 keyGeneration: 1 diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/04-delete-linodeobjectstoragebucket.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/04-delete-linodeobjectstoragebucket.yaml deleted file mode 100644 index f9d29aa42..000000000 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/04-delete-linodeobjectstoragebucket.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: -- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeObjectStorageBucket - name: linodeobjectstoragebucket-sample diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/05-errors.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/05-errors.yaml index 95cec6dce..79ffc7b5a 100644 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/05-errors.yaml +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/05-errors.yaml @@ -1,9 +1,11 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeObjectStorageBucket metadata: - name: linodeobjectstoragebucket-sample + name: (join('-', [$namespace, 'backups'])) + --- apiVersion: v1 kind: Secret metadata: - name: linodeobjectstoragebucket-sample-access-keys + name: (join('-', [$namespace, 'backups-access-keys'])) + diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/Makefile b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/Makefile deleted file mode 100644 index 3924bfdc1..000000000 --- a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/Makefile +++ /dev/null @@ -1 +0,0 @@ -include ../../Makefile diff --git a/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml new file mode 100755 index 000000000..0331924ae --- /dev/null +++ b/e2e/linodeobjectstoragebucket-controller/minimal-linodeobjectstoragebucket/chainsaw-test.yaml @@ -0,0 +1,51 @@ +# 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: + name: minimal-linodeobjectstoragebucket +spec: + template: true + steps: + - name: step-00 + try: + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-create-linodeobjectstoragebucket.yaml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - script: + env: + - name: NAMESPACE + value: ($namespace) + content: | + set -e + curl -s \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "Content-Type: application/json" \ + "https://api.linode.com/v4/object-storage/buckets/us-sea-1/$NAMESPACE-backups" + check: + ($error): ~ + (json_parse($stdout)): + label: (join('-', [($namespace), 'backups'])) + - name: step-03 + try: + - apply: + file: 03-patch-bucket.yaml + - assert: + file: 03-assert.yaml + - name: step-04 + try: + - delete: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeObjectStorageBucket + name: (join('-', [($namespace), 'backups'])) + - name: step-05 + try: + - error: + file: 05-errors.yaml diff --git a/e2e/linodevpc-controller/minimal-linodevpc/01-assert.yaml b/e2e/linodevpc-controller/minimal-linodevpc/01-assert.yaml index 2dc3d1a4f..f135fdffc 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/01-assert.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/01-assert.yaml @@ -1,7 +1,7 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeVPC metadata: - name: linodevpc-test + name: ($namespace) spec: region: us-sea status: diff --git a/e2e/linodevpc-controller/minimal-linodevpc/01-create-vpc.yaml b/e2e/linodevpc-controller/minimal-linodevpc/01-create-vpc.yaml index d4048a55b..12e653b10 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/01-create-vpc.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/01-create-vpc.yaml @@ -1,6 +1,6 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeVPC metadata: - name: linodevpc-test + name: ($namespace) spec: region: us-sea diff --git a/e2e/linodevpc-controller/minimal-linodevpc/02-verify-vpc.yaml b/e2e/linodevpc-controller/minimal-linodevpc/02-verify-vpc.yaml deleted file mode 100644 index 79be41c5a..000000000 --- a/e2e/linodevpc-controller/minimal-linodevpc/02-verify-vpc.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="vpcs" FILTER="{\"label\":\"linodevpc-test\"}" make callLinodeApiGet | grep 'results": 1' diff --git a/e2e/linodevpc-controller/minimal-linodevpc/03-delete-vpc.yaml b/e2e/linodevpc-controller/minimal-linodevpc/03-delete-vpc.yaml deleted file mode 100644 index ba268073f..000000000 --- a/e2e/linodevpc-controller/minimal-linodevpc/03-delete-vpc.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: -- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeVPC - name: linodevpc-test diff --git a/e2e/linodevpc-controller/minimal-linodevpc/03-error.yaml b/e2e/linodevpc-controller/minimal-linodevpc/03-error.yaml index d4048a55b..12e653b10 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/03-error.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/03-error.yaml @@ -1,6 +1,6 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeVPC metadata: - name: linodevpc-test + name: ($namespace) spec: region: us-sea diff --git a/e2e/linodevpc-controller/minimal-linodevpc/04-verify-no-vpc.yaml b/e2e/linodevpc-controller/minimal-linodevpc/04-verify-no-vpc.yaml deleted file mode 100644 index a089b10f5..000000000 --- a/e2e/linodevpc-controller/minimal-linodevpc/04-verify-no-vpc.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="vpcs" FILTER="{\"label\":\"linodevpc-test\"}" make callLinodeApiGet | grep 'results": 0' diff --git a/e2e/linodevpc-controller/minimal-linodevpc/Makefile b/e2e/linodevpc-controller/minimal-linodevpc/Makefile deleted file mode 100644 index 3924bfdc1..000000000 --- a/e2e/linodevpc-controller/minimal-linodevpc/Makefile +++ /dev/null @@ -1 +0,0 @@ -include ../../Makefile diff --git a/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml b/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml new file mode 100644 index 000000000..ea1463af9 --- /dev/null +++ b/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml @@ -0,0 +1,61 @@ +# 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: + name: minimal-linodevpc +spec: + template: true + steps: + - name: step-00 + try: + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-create-vpc.yaml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - script: + env: + - name: VPC_NAME + value: ($namespace) + content: | + set -e + curl -s\ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "X-Filter: {\"label\":\"$VPC_NAME\"}" \ + -H "Content-Type: application/json" \ + "https://api.linode.com/v4/vpcs" + check: + ($error): ~ + (json_parse($stdout)): + results: 1 + - name: step-03 + try: + - delete: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeVPC + name: ($namespace) + - error: + file: 03-error.yaml + - name: step-04 + try: + - script: + env: + - name: FILTER + value: '{"label":"($namespace)"}' + content: | + set -e + curl -s \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "X-Filter: $FILTER" \ + -H "Content-Type: application/json" \ + "https://api.linode.com/v4/nodebalancers" + check: + ($error): ~ + (json_parse($stdout)): + results: 0