github.com/kyma-project/kyma-environment-broker@v0.0.1/testing/e2e/skr/skr-test/provision/provision-skr.js (about)

     1  const {
     2    getSKRConfig,
     3    withSuffix,
     4    withInstanceID,
     5    gatherOptions,
     6    getEnvOrThrow,
     7    genRandom,
     8    debug,
     9    kcp,
    10    gardener,
    11    keb,
    12    initK8sConfig,
    13    getSKRRuntimeStatus,
    14  } = require('../helpers');
    15  
    16  const {provisionSKR}= require('../../kyma-environment-broker');
    17  const {BTPOperatorCreds} = require('../../smctl/helpers');
    18  
    19  async function getOrProvisionSKR(options, skipProvisioning, provisioningTimeout) {
    20    let shoot;
    21    if (skipProvisioning) {
    22      console.log('Gather information from externally provisioned SKR and prepare resources');
    23      const instanceID = getEnvOrThrow('INSTANCE_ID');
    24      console.log(`SKR Instance Id: ${instanceID}`);
    25      let suffix = process.env.TEST_SUFFIX;
    26      if (suffix === undefined) {
    27        suffix = genRandom(4);
    28      }
    29      options = gatherOptions(
    30          withInstanceID(instanceID),
    31          withSuffix(suffix),
    32      );
    33      shoot = await getSKRConfig(instanceID);
    34    } else {
    35      console.log('Provisioning new SKR instance...');
    36      shoot = await provisionSKRInstance(options, provisioningTimeout);
    37    }
    38  
    39    console.log('Initiating K8s config...');
    40    await initK8sConfig(shoot);
    41    console.log('Initialization of K8s finished...');
    42  
    43    return {
    44      options,
    45      shoot,
    46    };
    47  }
    48  
    49  async function provisionSKRInstance(options, timeout) {
    50    try {
    51      const btpOperatorCreds = BTPOperatorCreds.dummy();
    52  
    53      console.log(`\nInstanceID ${options.instanceID}`,
    54          `Runtime ${options.runtimeName}`, `Application ${options.appName}`, `Suffix ${options.suffix}`);
    55  
    56      const skr = await provisionSKR(keb,
    57          kcp, gardener,
    58          options.instanceID,
    59          options.runtimeName,
    60          null,
    61          btpOperatorCreds,
    62          options.customParams,
    63          timeout);
    64  
    65      debug('SKR is provisioned!');
    66      return skr.shoot;
    67    } catch (e) {
    68      throw new Error(`Provisioning failed: ${e.toString(), e.stack}`);
    69    } finally {
    70      debug('Fetching runtime status...');
    71      const runtimeStatus = await kcp.getRuntimeStatusOperations(options.instanceID);
    72      const events = await kcp.getRuntimeEvents(options.instanceID);
    73      console.log(`\nRuntime status after provisioning: ${runtimeStatus}\nEvents:\n${events}`);
    74      await kcp.reconcileInformationLog(runtimeStatus);
    75    }
    76  }
    77  
    78  async function getSKRKymaVersion(instanceID) {
    79    const runtimeStatus = await getSKRRuntimeStatus(instanceID);
    80    if (runtimeStatus && runtimeStatus.data) {
    81      return runtimeStatus.data[0].kymaVersion;
    82    }
    83    return '';
    84  }
    85  
    86  module.exports = {
    87    getOrProvisionSKR,
    88    getSKRKymaVersion,
    89  };
    90