diff --git a/docs/contributor/05-10-e2e_tests.md b/docs/contributor/05-10-e2e_tests.md index 0370baa48a..a9412fbcfc 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. 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. + +### 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: diff --git a/testing/e2e/skr/Makefile b/testing/e2e/skr/Makefile index 258c124515..769a83b714 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-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 + 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..e3a85f306f 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..31aca01f06 --- /dev/null +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -0,0 +1,52 @@ +const {gatherOptions} = require('../skr-test'); +const {initializeK8sClient} = require('../utils/index.js'); +const {getSecret} = require('../utils'); +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()); + +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; + + this.timeout(globalTimeout); + this.slow(slowTime); + + const options = gatherOptions(); // with default values + let kubeconfigFromBinding; + + before('Ensure SKR is provisioned', async function() { + this.timeout(provisioningTimeout); + await provisionSKRInstance(options, provisioningTimeout); + }); + + 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: kubeconfigFromBinding.credentials}); + }); + + it('Fetch sap-btp-manager secret', async function() { + await getSecret(secretName, ns); + }); + + after('Cleanup the resources', async function() { + this.timeout(deprovisioningTimeout); + if (process.env['SKIP_DEPROVISIONING'] != 'true') { + await deprovisionAndUnregisterSKR(options, deprovisioningTimeout, true); + } + }); +}); 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, };