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

fix(jsonschema): add app redirectFrom and autoscale #423

Merged
merged 8 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 6 additions & 34 deletions .github/workflows/tests-jsonschema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,18 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3

- uses: actions/setup-node@v3
- uses: actions/setup-python@v4
with:
node-version: 20
cache: "yarn"

python-version: "3.10"
- name: install
run: |
# fetch kube json-schema locally and add $id for schema resolution

sudo apt-get update -y

mkdir external-schemas
curl https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.24.0/_definitions.json | jq '. + {"$id": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.24.0/_definitions.json"}' > external-schemas/kube.json

curl https://raw.githubusercontent.com/socialgouv/helm-charts/v1/charts/cnpg-cluster/values.schema.json > external-schemas/cnpg-cluster.schema.json
curl https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/contrib/charts/app/kontinuous.values.schema.json > external-schemas/app.schema.json
curl https://raw.githubusercontent.com/socialgouv/helm-charts/v1/charts/pgweb/values.schema.json > external-schemas/pgweb.schema.json
curl https://raw.githubusercontent.com/socialgouv/helm-charts/v1/charts/maildev/values.schema.json > external-schemas/maildev.schema.json
curl https://raw.githubusercontent.com/SocialGouv/json-schemas/main/postgres/parameters.json > external-schemas/postgres-parameters.schema.json
curl https://raw.githubusercontent.com/SocialGouv/json-schemas/main/postgres/extensions.json > external-schemas/postgres-extensions.schema.json
curl https://raw.githubusercontent.com/SocialGouv/json-schemas/main/nginx/annotations.schema.json > external-schemas/nginx-annotations.schema.json
pip install pipx
pipx install check-jsonschema

- name: test valid schema
run: |
AJV_PARAMS='--spec draft7 --allow-union-types --strict=false --all-errors --errors=json --validate-formats=false -r "plugins/**/*.schema.json" -r "./external-schemas/**.json"'
echo "jsonschema-valid.yaml should have no error"
cat .github/jsonschema/jsonschema-valid.yml | yq -o=json > jsonschema-valid.json
RES=$(npx ajv-cli validate -s ./docs/values.schema.json -d jsonschema-valid.json $AJV_PARAMS)
if [ "$RES" == "jsonschema-valid.json valid" ]; then
echo "Valid schema"
else
echo "Invalid schema"
exit 1
fi
check-jsonschema .github/jsonschema/jsonschema-valid.yml --schemafile ./docs/values.schema.json

- name: test invalid schema
run: |
AJV_PARAMS='--spec draft7 --allow-union-types --strict=false --all-errors --errors=json --validate-formats=false -r "plugins/**/*.schema.json" -r "./external-schemas/**.json"'
echo "jsonschema-invalid.yaml should have 23 errors"
cat .github/jsonschema/jsonschema-invalid.yml | yq -o=json > jsonschema-invalid.json
npx ajv-cli validate -s ./docs/values.schema.json $AJV_PARAMS -d jsonschema-invalid.json 2>&1 | tail --lines=+2 > invalid-result.json
cat invalid-result.json | jq -e "length == 10"
! check-jsonschema .github/jsonschema/jsonschema-invalid.yml --schemafile ./docs/values.schema.json
5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
GIT_SHA: "{{ $.Values.global.sha }}"
```

?> 💡 You can add live documentation and validation for kontinuous files in your editor with a JSON-schema validation plugin like [YAML by Red Hat for VSCode](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml). See [all supported editors](https://www.schemastore.org/json/#editors).

## kontinuous CLI

The CLI is fully documented, you can consult help using `npx kontinuous --help` to known all available commands. Consult help and availables options using `--help` on each command.
Expand Down Expand Up @@ -101,7 +103,8 @@ When no explicit env is provided, kontinuous use the GIT head to select the corr

### Persistent environment

Using branch named following the persistency convention you can have persistent environments (docker images will be named persist-*, janitor will be disabled). Here is the convention for branches naming:
Using branch named following the persistency convention you can have persistent environments (docker images will be named persist-\*, janitor will be disabled). Here is the convention for branches naming:

- `**/persist`
- `persist/**`
- `**/persist/**`
Expand Down
40 changes: 36 additions & 4 deletions docs/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@
"title": "schema for .kontinuous/values.yaml",
"type": "object",
"patternProperties": {
"pg-*": {
"$ref": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/fabrique/charts/pg/kontinuous.values.schema.json"
"pg-.*": {
"allOf": [
{
"$ref": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/fabrique/charts/pg/kontinuous.values.schema.json"
},
{
"properties": {
"~chart": {
"type": "string",
"const": "pg"
}
}
}
]
},
"app-*": {
"$ref": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/contrib/charts/app/kontinuous.values.schema.json"
"app-.*": {
"allOf": [
{
"$ref": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/contrib/charts/app/kontinuous.values.schema.json"
},
{
"properties": {
"~chart": {
"type": "string",
"const": "app"
}
}
}
]
}
},
"additionalProperties": {
Expand Down Expand Up @@ -180,6 +204,10 @@
"type": "string",
"default": "app",
"anyOf": [
{
"type": "string",
"markdownDescription": "Bring your own helm chart. \n\nYou should have an entry with the same name in your `./Chart.yaml`.\n\nSee https://socialgouv.github.io/kontinuous/#/./faq?id=add-a-custom-helm-chart"
},
{
"const": "app",
"markdownDescription": "The [app chart](https://github.com/SocialGouv/kontinuous/blob/master/plugins/contrib/charts/app) provides all the resources to deploy a kubernetes application\n\n💡 You can use the [meta `~tpl~` prefix](https://socialgouv.github.io/kontinuous/#/./advanced/build?id=meta-values-plugin-tpl) to make any property a [go template](https://docs.gofiber.io/template/html/TEMPLATES_CHEATSHEET/#template-variables)"
Expand Down Expand Up @@ -211,6 +239,10 @@
{
"const": "redis",
"markdownDescription": "The [redis chart](https://github.com/SocialGouv/kontinuous/blob/master/plugins/contrib/charts/redis) deploys an [redis](https://oauth2-proxy.github.io/redis/) instance"
},
{
"const": "jobs",
"markdownDescription": "The [jobs chart](https://github.com/SocialGouv/kontinuous/blob/master/plugins/contrib/charts/jobs) provides a way to define de define tasks in your deployment pipeline\n\n💡 See [the jobs documentations](https://socialgouv.github.io/kontinuous/#/./advanced/build?id=meta-values-plugin-needs)."
}
]
},
Expand Down
44 changes: 44 additions & 0 deletions plugins/contrib/charts/app/kontinuous.values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,50 @@
},
"examples": ["[uploads]"]
},
"redirectFrom": {
"description": "List of hostnames to redirect from",
"type": "array",
"items": {
"type": "string"
},
"examples": ["previous.url.com"]
},
"autoscale": {
"description": "Horizontal pod autoscaling configuration",
"type": "object",
"properties": {
"enabled": {
"description": "Enable Horizontal pod autoscaling",
"type": "boolean",
"default": false
},
"minReplicas": {
"description": "Minimum number of replicas",
"type": "number",
"default": 2
},
"maxReplicas": {
"description": "Minimum number of replicas",
"type": "number",
"default": 10
},
"averageUtilization": {
"description": "Autoscaling averageUtilization tuning",
"type": "object",
"properties": {
"cpu": {
"type": "number",
"default": 70
},
"memory": {
"type": "number",
"default": 70
}
}
}
}
},

"env": {
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.24.0/_definitions.json#/definitions/io.k8s.api.core.v1.Container/properties/env"
},
Expand Down
4 changes: 4 additions & 0 deletions plugins/contrib/charts/jobs/kontinuous.values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"additionalProperties": false,
"required": ["runs"],
"properties": {
"~chart": {
"type": "string",
"const": "jobs"
},
"runs": {
"type": "object",
"additionalProperties": {
Expand Down
6 changes: 5 additions & 1 deletion plugins/fabrique/charts/pg/kontinuous.values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"type": "object",
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/socialgouv/kontinuous/v1/plugins/fabrique/charts/pg/kontinuous.values.schema.json",
"title": "Kontinuous pg helm chart",
"title": "Kontinuous pg helm chart, see https://github.com/SocialGouv/kontinuous/blob/master/plugins/fabrique/charts/pg",
"markdownDescription": "The [pg chart](https://github.com/SocialGouv/kontinuous/blob/master/plugins/fabrique/charts/pg) is a wrapper around [cnpg-cluster helm chart](https://github.com/SocialGouv/kontinuous/blob/master/plugins/fabrique/charts/pg)",
"required": [],
"properties": {
"~chart": {
"type": "string",
"const": "pg"
},
"cnpg-cluster": {
"title": "Kontinuous cnpg-cluster helm-chart",
"markdownDescription": "The [cnpg-cluster helm chart](https://github.com/SocialGouv/helm-charts/tree/main/charts/cnpg-cluster) based on [https://cloudnative-pg.io](https://https://cloudnative-pg.io)\n\n💡 You can use the [meta `~tpl~` prefix](https://socialgouv.github.io/kontinuous/#/./advanced/build?id=meta-values-plugin-tpl) to make it a template",
Expand Down