Skip to content

Commit

Permalink
Merge branch 'main' into cdsV8Update
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhprasad-sap authored Jul 29, 2024
2 parents 070692c + da3cc25 commit 6490ac9
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 32 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.1.0 - 25-July-2024

### Added

- New CLI to generate runtime values file `npx cap-op-plugin generate-runtime-values`
- Updated `values.schema.json` to the latest version of CAP Operator(v0.6.0) and BTP Service Operator(v0.6.5)
- Adds the `$XSAPPNAME.Callback` and `$XSAPPNAME.mtcallback` scopes to `xs-security.json` if they are not already present
- Switched helm chart to v2 apiVersion

## Version 0.0.2 - 13-May-2024

### Added
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ The CAP Operator Plugin offers a simple method for generating [CAP Operator](htt

## Before You Start

The CAP Operator plugin requires `@sap/cds-dk: ">=7.9.5"`. If you've installed @sap/cds-dk globally, ensure that the installed version is `7.9.5` or higher.
The CAP Operator plugin requires `@sap/cds-dk: "~7.9.5"`. If you've installed @sap/cds-dk globally, ensure that the installed version is `7.9.5` or higher, but below `8`.

> `@sap/cds-dk: "~8"` is not supported yet.
## Set Up the Plugin

To integrate the CAP Operator Plugin into your project, follow these steps:
To integrate the CAP Operator Plugin into your project, follow these steps:

1. Add the plugin package to your project as a dev dependency:

Expand All @@ -24,8 +26,8 @@ To integrate the CAP Operator Plugin into your project, follow these steps:
```
![](.images/cds-add-cap-operator.gif)

This creates a `chart` folder in your directory with three files: `Chart.yaml`, `values.schema.json`, and `values.yaml`.
This creates a `chart` folder in your directory with three files: `Chart.yaml`, `values.schema.json`, and `values.yaml`.

You might notice that the `templates` folder is missing. This is intentional. The idea is to push only these three files into your GitHub repository. When you deploy your application, you can call `cds build`, and during the build, the plugin generates the final Helm chart in your project's `gen` directory, which includes the predefined `templates` folder.
**Available Options**
Expand Down Expand Up @@ -98,8 +100,8 @@ The generated `chart/values.yaml` contains two types of information:
- [imagePullSecrets](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) - Kubernetes secret used to pull the application docker images from a private container image registry or repository.
- env information inside workloads

As a developer, you must fill in the design-time deployment information in the `values.yaml` file, which can then be pushed to your GitHub repository. The plugin auto-populates some values based on your project configuration, but verifying them and manually filling in any missing information is essential. You can refer to `values.schema.json` file for the structure of the `values.yaml` file.
As a developer, you must fill in the design-time deployment information in the `values.yaml` file, which can then be pushed to your GitHub repository. The plugin auto-populates some values based on your project configuration, but verifying them and manually filling in any missing information is essential. You can refer to `values.schema.json` file for the structure of the `values.yaml` file.

**Please fill the `values.yaml` according to the schema as it is tightly coupled to the predefined templates.** You can use a YAML schema validation extension such as [YAML](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) or run the following command to validate your `values.yaml` file. You can ignore the errors from runtime values as they are not filled in yet.

```sh
Expand Down Expand Up @@ -160,8 +162,7 @@ The generated `chart/values.yaml` contains two types of information:
imagePullSecret: regcred
```
Similar to the interactive mode, `appName`, `capOperatorSubdomain`, `clusterDomain`, `globalAccountId`, `providerSubdomain`, and `tenantId` are mandatory fields. If they're not provided in the input YAML, the plugin throws an error.

Similar to the interactive mode, `appName`, `capOperatorSubdomain`, `clusterDomain`, `globalAccountId`, `providerSubdomain`, and `tenantId` are mandatory fields. If they're not provided in the input YAML, the plugin throws an error.
After execution, the `runtime-values.yaml` file is created in the chart folder of your project directory.

7. Now, you can deploy the application using the following command:
Expand All @@ -176,7 +177,7 @@ The generated `chart/values.yaml` contains two types of information:
helm upgrade -i -n <namespace> <release-name> <project-path>/gen/chart --set-file serviceInstances.xsuaa.jsonParameters=<project-path>/xs-security.json -f <project-path>/chart/runtime-values.yaml
```

## Example
## Example

As a reference, check out the [CAP Operator Helm chart](https://github.com/cap-js/incidents-app/tree/cap-operator-plugin/chart) in the sample incident app. Also, take a look at the corresponding [runtime-values.yaml](https://github.com/cap-js/incidents-app/blob/cap-operator-plugin/chart/runtime-values.yaml) file.

Expand Down
25 changes: 24 additions & 1 deletion bin/cap-op-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { spawn } = require('child_process')

const { ask, mergeObj, isCAPOperatorChart } = require('../lib/util')

Expand Down Expand Up @@ -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: ', await getShootDomain(), true],
['Enter your global account ID: ', '', true],
['Enter your provider subdomain: ', '', true],
['Enter your provider tenant ID: ', '', true],
Expand Down Expand Up @@ -157,6 +158,28 @@ function getAppDetails() {
return { appName: segments[segments.length - 1], appDescription: description }
}

async function getShootDomain() {
let domain = ''
try {
const kubectl = spawn('kubectl', ['config', 'view', '--minify', '--output', 'jsonpath={.clusters[*].cluster.server}'], { shell: false })

await new Promise((resolve, reject) => {
kubectl.stdout.on('data', (data) => {
const domainStartIndex = data.indexOf('api.')
if (domainStartIndex !== -1) {
domain = data.toString().substring(domainStartIndex + 4)
}
})

kubectl.stderr.on('data', () => { reject() })

kubectl.on('close', () => { resolve() })
})
} catch (error) {}

return domain
}

if (isCli) {
const [, , cmd, option, inputYamlPath] = process.argv;
(async () => await capOperatorPlugin(cmd, option, inputYamlPath ?? undefined))()
Expand Down
6 changes: 0 additions & 6 deletions files/workloads.yaml.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ workloads:
- {{appName}}-service-manager-bind
{{/hasMultitenancy}}
deploymentDefinition:
env:
- name: CDS_CONFIG
value:
type: CAP
image:

Expand Down Expand Up @@ -49,8 +46,5 @@ workloads:
- {{appName}}-service-manager-bind
{{/hasMultitenancy}}
jobDefinition:
env:
- name: CDS_CONFIG
value:
type: TenantOperation
image:
18 changes: 18 additions & 0 deletions files/xs-security.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"scopes": [
{
"name": "$XSAPPNAME.Callback",
"description": "Subscription via SaaS Registry for CAP Operator",
"grant-as-authority-to-apps": [
"$XSAPPNAME(application,sap-provisioning,tenant-onboarding)"
]
},
{
"name": "$XSAPPNAME.mtcallback",
"description": "Subscription via SaaS Registry",
"grant-as-authority-to-apps": [
"$XSAPPNAME(application,sap-provisioning,tenant-onboarding)"
]
}
]
}
6 changes: 6 additions & 0 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin {
if (hasXsuaa) {
const xsuaaaYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/xsuaa.yaml.hbs')), project))
await cds.add.merge(xsuaaaYaml).into(valuesYaml)

await cds.add.merge(__dirname, '../files/xs-security.json.hbs').into('xs-security.json', {
project,
additions: [{ in: 'scopes', where: { name: '$XSAPPNAME.Callback' }},
{ in: 'scopes', where: { name: '$XSAPPNAME.mtcallback' }}]
})
}

if (hasApprouter || exists('approuter')) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cap-js/cap-operator-plugin",
"version": "0.0.2",
"version": "0.1.0",
"description": "Add/Build Plugin for CAP Operator",
"homepage": "https://github.com/cap-js/cap-operator-plugin/blob/main/README.md",
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions test/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe('cds add cap-operator', () => {
expect(getFileHash(join(__dirname,'files/expectedChart/Chart.yaml'))).to.equal(getFileHash(join(bookshop, 'chart/Chart.yaml')))
expect(getFileHash(join(__dirname,'files/expectedChart/values.schema.json'))).to.equal(getFileHash(join(bookshop, 'chart/values.schema.json')))
expect(getFileHash(join(__dirname,'files/expectedChart/values.yaml'))).to.equal(getFileHash(join(bookshop, 'chart/values.yaml')))

// Check changes to xs-security.json
expect(getFileHash(join(__dirname,'files/xs-security.json'))).to.equal(getFileHash(join(bookshop, 'xs-security.json')))
})

it('Add cap-operator chart with force', async () => {
Expand Down
6 changes: 0 additions & 6 deletions test/files/expectedChart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ workloads:
- bookshop-saas-registry-bind
- bookshop-service-manager-bind
deploymentDefinition:
env:
- name: CDS_CONFIG
value: null
type: CAP
image: null
content-deploy:
Expand All @@ -146,8 +143,5 @@ workloads:
- bookshop-saas-registry-bind
- bookshop-service-manager-bind
jobDefinition:
env:
- name: CDS_CONFIG
value: null
type: TenantOperation
image: null
6 changes: 0 additions & 6 deletions test/files/expectedChart/valuesWithDestination.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ workloads:
- bookshop-saas-registry-bind
- bookshop-service-manager-bind
deploymentDefinition:
env:
- name: CDS_CONFIG
value: null
type: CAP
image: null
content-deploy:
Expand All @@ -146,8 +143,5 @@ workloads:
- bookshop-saas-registry-bind
- bookshop-service-manager-bind
jobDefinition:
env:
- name: CDS_CONFIG
value: null
type: TenantOperation
image: null
21 changes: 21 additions & 0 deletions test/files/xs-security.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"scopes": [
{
"name": "$XSAPPNAME.mtcallback",
"description": "Subscription via SaaS Registry",
"grant-as-authority-to-apps": [
"$XSAPPNAME(application,sap-provisioning,tenant-onboarding)"
]
},
{
"name": "$XSAPPNAME.Callback",
"description": "Subscription via SaaS Registry for CAP Operator",
"grant-as-authority-to-apps": [
"$XSAPPNAME(application,sap-provisioning,tenant-onboarding)"
]
}
],
"attributes": [],
"role-templates": [],
"authorities-inheritance": false
}

0 comments on commit 6490ac9

Please sign in to comment.