Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SKR binding test #1184

Merged
merged 12 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether it should be service binding here and in line 135? If just binding is sufficient, please ignore this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave it as it is. It's documentation for the tests, so I think that's sufficient.


### 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
53 changes: 53 additions & 0 deletions testing/e2e/skr/skr-binding-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 skr;
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});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add an assertion that where you cannot access cluster before initialization is done? I am afraid that it might swallow errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it to not provision and init in the first step.

});

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,
};

Loading