Skip to content

Commit

Permalink
Upgraded @sap/cds-dk to 7.8.1
Browse files Browse the repository at this point in the history
Switched to new option feature
  • Loading branch information
anirudhprasad-sap committed Apr 5, 2024
1 parent d5ffffe commit d62f7e7
Show file tree
Hide file tree
Showing 5 changed files with 1,624 additions and 301 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ To integrate the CAP Operator Plugin into your project, follow these steps:

* To add a chart folder with templates included, use:
```sh
cds add cap-operator --add-with-templates
cds add cap-operator --with-templates
```
> During `cds build`, the plugin will copy the templates folder into the final chart.

> ### ⚠️ Experimental
> To add a chart folder with the values.yaml prefilled with the design-time deployment details from the mta and mta extensions, use:
>```sh
> cds add cap-operator --add-with-mta <mta-yaml-file-path> --add-with-mta-extensions <mta-ext-yaml-file-path>
> cds add cap-operator --with-mta <mta-yaml-file-path> --with-mta-extensions <mta-ext-yaml-file-path>
>```
> If you have multiple mta extensions, you can pass them as a comma-separated string in order to merge them.

Expand Down Expand Up @@ -73,7 +73,7 @@ To integrate the CAP Operator Plugin into your project, follow these steps:
## ❗Things to Note
* If you are adding the basic chart folder using the `cds add cap-operator` command, do not modify the `values.schema.json` file. The templates injected automatically during `cds build` are tightly coupled with the structure in `values.schema.json`. If schema changes are needed, use option `--add-with-templates` to add the templates folder and adjust them accordingly.
* If you are adding the basic chart folder using the `cds add cap-operator` command, do not modify the `values.schema.json` file. The templates injected automatically during `cds build` are tightly coupled with the structure in `values.schema.json`. If schema changes are needed, use option `--with-templates` to add the templates folder and adjust them accordingly.
* When defining environment variables for workloads in the `values.yaml` file, it's important to mirror these definitions in the `runtime-values.yaml` file. This ensures consistency and avoids potential conflicts, as Helm does not merge arrays. If you're introducing new environment variables in `runtime-values.yaml` for a workload, remember to include existing variables from `values.yaml` to maintain coherence.
Expand Down
33 changes: 25 additions & 8 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ const { isCAPOperatorChart } = require('./util')

module.exports = class CapOperatorAddPlugin extends cds.add.Plugin {

options() {
return {
'with-templates': {
type: 'boolean',
help: 'To add the templates folder to the chart folder.'
},
'with-mta': {
type: 'string',
//help: 'Path to the mta.yaml file.'
},
'with-mta-extensions': {
type: 'string',
//help: 'Comma separated list of mta extensions to be applied to the mta.yaml file. Can be used only with --with-mta option.'
}
}
}

async canRun() {
const { hasMultitenancy, hasApprouter, hasXsuaa } = cds.add.readProject()
if (!hasXsuaa) {
Expand Down Expand Up @@ -46,7 +63,7 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin {
else if (exists('chart')) {
let isCAPOpChart = isCAPOperatorChart('chart')

if(isCAPOpChart && !exists('chart/templates') && cds.cli.options['add-with-templates']){
if(isCAPOpChart && !exists('chart/templates') && cds.cli.options['with-templates']){
await copy(join(__dirname, '../files/chart/templates')).to('chart/templates')
console.log("Added 'templates' folder to the 'chart' folder.")
}
Expand All @@ -64,19 +81,19 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin {
await copy(join(__dirname, '../files/chart/values.yaml')).to('chart/values.yaml')
await copy(join(__dirname, '../files/chart/values.schema.json')).to('chart/values.schema.json')

if (cds.cli.options['add-with-templates'])
if (cds.cli.options['with-templates'])
await copy(join(__dirname, '../files/chart/templates')).to('chart/templates')

console.log("`chart` folder generated.")

if (!cds.cli.options['add-with-mta'] && cds.cli.options['add-with-mta-extensions'])
throw new Error(`mta YAML not provided. Please pass the mta YAML via option '--add-with-mta'.`)
if (!cds.cli.options['with-mta'] && cds.cli.options['with-mta-extensions'])
throw new Error(`mta YAML not provided. Please pass the mta YAML via option '--with-mta'.`)

if (cds.cli.options['add-with-mta']) {
if (cds.cli.options['with-mta']) {
const { hasMta } = project
if (!hasMta) throw new Error(`mta is not added to this project. Run 'cds add mta'.`)

const mtaTransformer = new MtaTransformer(cds.cli.options['add-with-mta'], cds.cli.options['add-with-mta-extensions'] ? cds.cli.options['add-with-mta-extensions'].split(',') : [])
const mtaTransformer = new MtaTransformer(cds.cli.options['with-mta'], cds.cli.options['with-mta-extensions'] ? cds.cli.options['with-mta-extensions'].split(',') : [])

console.log("⚠️ Deriving values.yaml from mta.yaml cannot be done one to one. It's a best guess, so some information might be missing and needs to be reviewed and corrected by the application developer.")

Expand All @@ -93,8 +110,8 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin {

async combine() {

// In case of 'cds add cap-operator --add-with-mta', service instances, service bindings and workloads are derived from mta.yaml. No need to add them again.
if (cds.cli.options['add-with-mta']) return
// In case of 'cds add cap-operator --with-mta', service instances, service bindings and workloads are derived from mta.yaml. No need to add them again.
if (cds.cli.options['with-mta']) return

const project = cds.add.readProject()
const { hasDestination, hasHtml5Repo, hasXsuaa, hasApprouter, hasMultitenancy } = project
Expand Down
Loading

0 comments on commit d62f7e7

Please sign in to comment.