Skip to content

Commit

Permalink
Add SKR binding test (#1184)
Browse files Browse the repository at this point in the history
* Add skr binding test

* Lint

* More tests

* Add missing variables

* Add missing variables

* Update docs

* Fix makefile

* Fix field

* Provision without init

* Review

* Lint

* Lint
  • Loading branch information
MarekMichali authored Sep 25, 2024
1 parent fba6247 commit 2859e9b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
25 changes: 25 additions & 0 deletions docs/contributor/05-10-e2e_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions testing/e2e/skr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions testing/e2e/skr/kyma-environment-broker/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}/`;
Expand Down
4 changes: 3 additions & 1 deletion testing/e2e/skr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
52 changes: 52 additions & 0 deletions testing/e2e/skr/skr-binding-test/index.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
1 change: 1 addition & 0 deletions testing/e2e/skr/skr-test/provision/provision-skr.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ async function getSKRKymaVersion(instanceID) {
module.exports = {
provisionSKRAndInitK8sConfig,
getSKRKymaVersion,
provisionSKRInstance,
};

0 comments on commit 2859e9b

Please sign in to comment.