From c8bbbf49de36019092b9c5af22066b629b8aacfc Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 09:18:49 +0200 Subject: [PATCH 01/12] Add skr binding test --- testing/e2e/skr/Makefile | 7 +++ .../e2e/skr/kyma-environment-broker/client.js | 17 +++++++ testing/e2e/skr/package.json | 4 +- testing/e2e/skr/skr-binding-test/index.js | 51 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 testing/e2e/skr/skr-binding-test/index.js diff --git a/testing/e2e/skr/Makefile b/testing/e2e/skr/Makefile index 258c124515..1ae5468103 100644 --- a/testing/e2e/skr/Makefile +++ b/testing/e2e/skr/Makefile @@ -40,3 +40,10 @@ skr-trial-suspension: chmod +x /usr/local/bin/kcp npm install npm run skr-trial-suspension-test + +.PHONY: skr-binding +skr-networking: + curl -fLSs -o /usr/local/bin/kcp https://storage.googleapis.com/kyma-development-artifacts/kcp/master/kcp-linux + chmod +x /usr/local/bin/kcp + npm install + npm run skr-binding-test \ No newline at end of file diff --git a/testing/e2e/skr/kyma-environment-broker/client.js b/testing/e2e/skr/kyma-environment-broker/client.js index 586cf830c4..cdb864f7d6 100644 --- a/testing/e2e/skr/kyma-environment-broker/client.js +++ b/testing/e2e/skr/kyma-environment-broker/client.js @@ -272,6 +272,23 @@ class KEBClient { }); } + async createBinding(instanceID) { + const payload = { + service_id: KYMA_SERVICE_ID, + plan_id: this.planID, + parameters: { + token_request: true + } + }; + const bindingID = Math.random().toString(36).substring(2, 18); + const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}?accepts_incomplete=true`; + try { + return await this.callKEB(payload, endpoint, 'put'); + } catch (err) { + throw new Error(`error while creating binding: ${err.toString()}`); + } + } + getPlatformRegion() { if (this.platformRegion && this.platformRegion != '') { return `${this.platformRegion}/`; diff --git a/testing/e2e/skr/package.json b/testing/e2e/skr/package.json index 10f5708610..3a461738f6 100644 --- a/testing/e2e/skr/package.json +++ b/testing/e2e/skr/package.json @@ -14,7 +14,9 @@ "skr-test": "DEBUG=true mocha --timeout 15000 --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-test/test.js", "skr-aws-upgrade-integration-test": "mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-aws-upgrade-integration/index.js", "skr-networking-test": "mocha --inline-difs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-networking-test/index.js", - "skr-trial-suspension-test": "DEBUG=true mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json --bail ./trial-suspension-test/test.js" + "skr-trial-suspension-test": "DEBUG=true mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json --bail ./trial-suspension-test/test.js", + "skr-binding-test": "mocha --inline-difs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-binding-test/index.js" + }, "license": "Apache-2.0", "devDependencies": { diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js new file mode 100644 index 0000000000..068a86f27e --- /dev/null +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -0,0 +1,51 @@ +const { + gatherOptions, +} = require('../skr-test'); +const { + initializeK8sClient, +} = require('../utils/index.js'); +const {provisionSKRAndInitK8sConfig} = require('../skr-test/provision/provision-skr'); +const {deprovisionAndUnregisterSKR} = require('../skr-test/provision/deprovision-skr'); +const {KEBClient, KEBConfig} = require('../kyma-environment-broker'); +const keb = new KEBClient(KEBConfig.fromEnv()); + +const provisioningTimeout = 1000 * 60 * 30; // 30m +const deprovisioningTimeout = 1000 * 60 * 95; // 95m +let globalTimeout = 1000 * 60 * 70; // 70m +const slowTime = 5000; + +describe('SKR test', function() { + globalTimeout += provisioningTimeout + deprovisioningTimeout; + + this.timeout(globalTimeout); + this.slow(slowTime); + + let options = gatherOptions(); // with default values + let skr; + let kubeconfigFromBinding; + + before('Ensure SKR is provisioned', async function() { + this.timeout(provisioningTimeout); + skr = await provisionSKRAndInitK8sConfig(options, provisioningTimeout); + options = skr.options; + }); + + it('Create SKR binding', async function() { + try { + kubeconfigFromBinding = await keb.createBinding(options.instanceID) + } catch (err) { + console.log(err); + } + }); + + it('Initiate K8s client with kubeconfig from binding', async function() { + await initializeK8sClient({kubeconfig: kubeconfig}); + }); + + after('Cleanup the resources', async function() { + this.timeout(deprovisioningTimeout); + if (process.env['SKIP_DEPROVISIONING'] != 'true') { + await deprovisionAndUnregisterSKR(options, deprovisioningTimeout, true); + } + }); +}); From 558fef68986789a386efc9714720a46b578f42fb Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 09:22:34 +0200 Subject: [PATCH 02/12] Lint --- testing/e2e/skr/kyma-environment-broker/client.js | 4 ++-- testing/e2e/skr/skr-binding-test/index.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/testing/e2e/skr/kyma-environment-broker/client.js b/testing/e2e/skr/kyma-environment-broker/client.js index cdb864f7d6..e3a85f306f 100644 --- a/testing/e2e/skr/kyma-environment-broker/client.js +++ b/testing/e2e/skr/kyma-environment-broker/client.js @@ -277,8 +277,8 @@ class KEBClient { service_id: KYMA_SERVICE_ID, plan_id: this.planID, parameters: { - token_request: true - } + token_request: true, + }, }; const bindingID = Math.random().toString(36).substring(2, 18); const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}?accepts_incomplete=true`; diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index 068a86f27e..27d9cd1b0d 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -32,16 +32,16 @@ describe('SKR test', function() { it('Create SKR binding', async function() { try { - kubeconfigFromBinding = await keb.createBinding(options.instanceID) + kubeconfigFromBinding = await keb.createBinding(options.instanceID); } catch (err) { console.log(err); } }); it('Initiate K8s client with kubeconfig from binding', async function() { - await initializeK8sClient({kubeconfig: kubeconfig}); + await initializeK8sClient({kubeconfig: kubeconfigFromBinding}); }); - + after('Cleanup the resources', async function() { this.timeout(deprovisioningTimeout); if (process.env['SKIP_DEPROVISIONING'] != 'true') { From 1d22146db7c7143c26eb067e42467ad94e621067 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 12:24:07 +0200 Subject: [PATCH 03/12] More tests --- testing/e2e/skr/skr-binding-test/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index 27d9cd1b0d..e81d2a9862 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -1,9 +1,6 @@ -const { - gatherOptions, -} = require('../skr-test'); -const { - initializeK8sClient, -} = require('../utils/index.js'); +const {gatherOptions} = require('../skr-test'); +const {initializeK8sClient} = require('../utils/index.js'); +const {getSecret} = require('../utils'); const {provisionSKRAndInitK8sConfig} = require('../skr-test/provision/provision-skr'); const {deprovisionAndUnregisterSKR} = require('../skr-test/provision/deprovision-skr'); const {KEBClient, KEBConfig} = require('../kyma-environment-broker'); @@ -14,7 +11,7 @@ const deprovisioningTimeout = 1000 * 60 * 95; // 95m let globalTimeout = 1000 * 60 * 70; // 70m const slowTime = 5000; -describe('SKR test', function() { +describe('SKR Binding test', function() { globalTimeout += provisioningTimeout + deprovisioningTimeout; this.timeout(globalTimeout); @@ -42,6 +39,10 @@ describe('SKR test', function() { await initializeK8sClient({kubeconfig: kubeconfigFromBinding}); }); + it('Fetch sap-btp-service-operator secret', async function() { + await getSecret(secretName, ns); + }); + after('Cleanup the resources', async function() { this.timeout(deprovisioningTimeout); if (process.env['SKIP_DEPROVISIONING'] != 'true') { From e6e25b95f263c27c7bea93ebe8bab9c80ad74ead Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 12:28:11 +0200 Subject: [PATCH 04/12] Add missing variables --- testing/e2e/skr/skr-binding-test/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index e81d2a9862..a1fc10733d 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -10,6 +10,8 @@ const provisioningTimeout = 1000 * 60 * 30; // 30m const deprovisioningTimeout = 1000 * 60 * 95; // 95m let globalTimeout = 1000 * 60 * 70; // 70m const slowTime = 5000; +const secretName = 'sap-btp-manager'; +const ns = 'kyma-system'; describe('SKR Binding test', function() { globalTimeout += provisioningTimeout + deprovisioningTimeout; From bdc962d946c1f2dc91a39aa3efd61d9993ed19ef Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 12:28:54 +0200 Subject: [PATCH 05/12] Add missing variables --- testing/e2e/skr/skr-binding-test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index a1fc10733d..f86777c845 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -41,7 +41,7 @@ describe('SKR Binding test', function() { await initializeK8sClient({kubeconfig: kubeconfigFromBinding}); }); - it('Fetch sap-btp-service-operator secret', async function() { + it('Fetch sap-btp-manager secret', async function() { await getSecret(secretName, ns); }); From cc0e2fda58ceeb29597b542d743a22c5635c418d Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 12:40:20 +0200 Subject: [PATCH 06/12] Update docs --- docs/contributor/05-10-e2e_tests.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/contributor/05-10-e2e_tests.md b/docs/contributor/05-10-e2e_tests.md index 0370baa48a..61a5ac189b 100644 --- a/docs/contributor/05-10-e2e_tests.md +++ b/docs/contributor/05-10-e2e_tests.md @@ -126,6 +126,31 @@ The test executes the following steps: make skr-networking-test ``` +## Binding Tests + +### Usage + +The test executes the following steps: +1. Provisions a Kyma runtime cluster. +2. Creates a binding and saves the returned kubeconfig. +3. Inits a k8s client with the returned kubeconfig. +4. Tries to fetch a secret. +5. Deprovisions the Kyma runtime instance and cleans up the resources. + +### Test Execution + +1. Before you run the test, prepare the `.env` file based on this [`.env.template`](/testing/e2e/skr/skr-test/.env.template). +2. To set up the environment variables in your system, run: + + ```bash + export $(xargs < .env) + ``` + +3. Run the test scenario: + ```bash + make skr-binding-test + ``` + ## CI Pipelines The tests are run once per day at 01:05 by the given ProwJobs: From 27886c418f0513a2d75d18b371b6cb69fe738b55 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 13:52:06 +0200 Subject: [PATCH 07/12] Fix makefile --- testing/e2e/skr/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/e2e/skr/Makefile b/testing/e2e/skr/Makefile index 1ae5468103..769a83b714 100644 --- a/testing/e2e/skr/Makefile +++ b/testing/e2e/skr/Makefile @@ -42,7 +42,7 @@ skr-trial-suspension: npm run skr-trial-suspension-test .PHONY: skr-binding -skr-networking: +skr-binding: curl -fLSs -o /usr/local/bin/kcp https://storage.googleapis.com/kyma-development-artifacts/kcp/master/kcp-linux chmod +x /usr/local/bin/kcp npm install From 9880e2ddaec7045f89c2f0831d06032890e1b51c Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 14:13:02 +0200 Subject: [PATCH 08/12] Fix field --- testing/e2e/skr/skr-binding-test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index f86777c845..a49249bf14 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -38,7 +38,7 @@ describe('SKR Binding test', function() { }); it('Initiate K8s client with kubeconfig from binding', async function() { - await initializeK8sClient({kubeconfig: kubeconfigFromBinding}); + await initializeK8sClient({kubeconfig: kubeconfigFromBinding.credentials}); }); it('Fetch sap-btp-manager secret', async function() { From 0231eaaa549b296a0a0f63fd3730990ecc59d309 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 15:08:49 +0200 Subject: [PATCH 09/12] Provision without init --- testing/e2e/skr/skr-binding-test/index.js | 5 ++--- testing/e2e/skr/skr-test/provision/provision-skr.js | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index a49249bf14..561b82324f 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -1,7 +1,7 @@ const {gatherOptions} = require('../skr-test'); const {initializeK8sClient} = require('../utils/index.js'); const {getSecret} = require('../utils'); -const {provisionSKRAndInitK8sConfig} = require('../skr-test/provision/provision-skr'); +const {provisionSKRInstance} = require('../skr-test/provision/provision-skr'); const {deprovisionAndUnregisterSKR} = require('../skr-test/provision/deprovision-skr'); const {KEBClient, KEBConfig} = require('../kyma-environment-broker'); const keb = new KEBClient(KEBConfig.fromEnv()); @@ -25,8 +25,7 @@ describe('SKR Binding test', function() { before('Ensure SKR is provisioned', async function() { this.timeout(provisioningTimeout); - skr = await provisionSKRAndInitK8sConfig(options, provisioningTimeout); - options = skr.options; + await provisionSKRInstance(options, provisioningTimeout); }); it('Create SKR binding', async function() { diff --git a/testing/e2e/skr/skr-test/provision/provision-skr.js b/testing/e2e/skr/skr-test/provision/provision-skr.js index 52d7f72c1b..7c38e79606 100644 --- a/testing/e2e/skr/skr-test/provision/provision-skr.js +++ b/testing/e2e/skr/skr-test/provision/provision-skr.js @@ -88,5 +88,6 @@ async function getSKRKymaVersion(instanceID) { module.exports = { provisionSKRAndInitK8sConfig, getSKRKymaVersion, + provisionSKRInstance, }; From 0fea4dd505f0d41ad0c3bdc3c72a912d9c8a3dd6 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 15:10:18 +0200 Subject: [PATCH 10/12] Review --- docs/contributor/05-10-e2e_tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributor/05-10-e2e_tests.md b/docs/contributor/05-10-e2e_tests.md index 61a5ac189b..a9412fbcfc 100644 --- a/docs/contributor/05-10-e2e_tests.md +++ b/docs/contributor/05-10-e2e_tests.md @@ -133,7 +133,7 @@ The test executes the following steps: The test executes the following steps: 1. Provisions a Kyma runtime cluster. 2. Creates a binding and saves the returned kubeconfig. -3. Inits a k8s client with the returned kubeconfig. +3. Initializes a Kubernetes client with the returned kubeconfig. 4. Tries to fetch a secret. 5. Deprovisions the Kyma runtime instance and cleans up the resources. From 4de48401a27d6648e50fa80a3c07209773c3d350 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 15:32:13 +0200 Subject: [PATCH 11/12] Lint --- testing/e2e/skr/skr-binding-test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index 561b82324f..06855215f9 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -19,7 +19,7 @@ describe('SKR Binding test', function() { this.timeout(globalTimeout); this.slow(slowTime); - let options = gatherOptions(); // with default values + const options = gatherOptions(); // with default values let skr; let kubeconfigFromBinding; From dc761cfd5957229969cf67aadb8d86c2ef2ff233 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 25 Sep 2024 15:38:15 +0200 Subject: [PATCH 12/12] Lint --- testing/e2e/skr/skr-binding-test/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index 06855215f9..31aca01f06 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -20,7 +20,6 @@ describe('SKR Binding test', function() { this.slow(slowTime); const options = gatherOptions(); // with default values - let skr; let kubeconfigFromBinding; before('Ensure SKR is provisioned', async function() {