diff --git a/bin/cap-op-plugin.js b/bin/cap-op-plugin.js index a9f526c..ef03353 100755 --- a/bin/cap-op-plugin.js +++ b/bin/cap-op-plugin.js @@ -5,6 +5,7 @@ const isCli = require.main === module const cds = require('@sap/cds-dk') const yaml = require('@sap/cds-foss').yaml const Mustache = require('mustache') +const { execSync } = require('child_process') const { ask, mergeObj, isCAPOperatorChart } = require('../lib/util') @@ -72,7 +73,7 @@ async function generateRuntimeValues(option, inputYamlPath) { const questions = [ ['Enter app name for deployment: ', appName, true], ['Enter CAP Operator subdomain (In kyma cluster it is "cap-op" by default): ', 'cap-op', true], - ['Enter your cluster shoot domain: ', '', true], + ['Enter your cluster shoot domain: ', getShootDomain(), true], ['Enter your global account ID: ', '', true], ['Enter your provider subdomain: ', '', true], ['Enter your provider tenant ID: ', '', true], @@ -157,6 +158,19 @@ function getAppDetails() { return { appName: segments[segments.length - 1], appDescription: description } } +function getShootDomain() { + let domain = '' + try { + const domainCmd = execSync(`kubectl config view --minify --output jsonpath="{.clusters[*].cluster.server}"`, { stdio: "pipe" }).toString() + const domainStartIndex = domainCmd.indexOf('api.') + if (domainStartIndex !== -1) { + domain = domainCmd.substring(domainStartIndex + 4) + } + } catch (error) {} + + return domain +} + if (isCli) { const [, , cmd, option, inputYamlPath] = process.argv; (async () => await capOperatorPlugin(cmd, option, inputYamlPath ?? undefined))()