Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #154 from tumido/fix-ocm-form-defaults
Browse files Browse the repository at this point in the history
fix: enforce defaults in OCP form view
  • Loading branch information
kadel committed Nov 24, 2023
2 parents 4806583 + 70ac2af commit addbde9
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 29 deletions.
33 changes: 26 additions & 7 deletions .pre-commit/jsonschema-dereference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

JSONSCHEMA_TEMPLATE_NAME = "values.schema.tmpl.json"
JSONSCHEMA_NAME = "values.schema.json"
VALUES_FILE = "values.yaml"
CHART_LOCK = "Chart.lock"

def parse_chart_lock(chart_dir: Path):
def read_yaml(file_path: Path):
"""Open and load Chart.yaml file."""
with open(chart_dir / CHART_LOCK, "r") as f:
with open(file_path, "r") as f:
return yaml.load(f, Loader=Loader)

def template_schema(chart_dir: Path, lock: Dict[str, Any]):
Expand All @@ -26,7 +27,7 @@ def template_schema(chart_dir: Path, lock: Dict[str, Any]):

return json.loads(schema_template.render(lock))

def tidy_schema(schema: Any):
def tidy_schema(schema: Any, values: Any):
"""Hack to support OCP Form view.
https://issues.redhat.com/browse/OCPBUGS-14874
Expand All @@ -41,8 +42,25 @@ def tidy_schema(schema: Any):
del schema["format"]
except:
pass
for v in schema.values():
tidy_schema(v)

# Override existing defaults so OCP form view
# doesn't try to override our defaults
if schema.get("default") is not None and values is not None:
schema["default"] = values

# Tidy up properties for type: object
properties: Dict[str, Any] = schema.get("properties", {})
for k, v in properties.items():
if isinstance(values, dict):
new_values = values.get(k, None)
else:
new_values = None
tidy_schema(v, new_values)

# Tidy up properties for type: array
items: Dict[str, Any] = schema.get("items", {})
if items:
tidy_schema(items, values)
return schema

def save(chart_dir: Path, schema: Any):
Expand All @@ -56,10 +74,11 @@ def save(chart_dir: Path, schema: Any):
errors: List[BaseException] = []
for chart in charts:
try:
lock = parse_chart_lock(chart)
lock = read_yaml(chart / CHART_LOCK)
values = read_yaml(chart / VALUES_FILE)
schema_template = template_schema(chart, lock)
schema = jsonref.replace_refs(schema_template)
schema = tidy_schema(schema)
schema = tidy_schema(schema, values)

save(chart, schema)
except BaseException as e:
Expand Down
2 changes: 1 addition & 1 deletion charts/backstage/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ sources:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.10.4
version: 2.10.5
2 changes: 1 addition & 1 deletion charts/backstage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Janus-IDP Backstage Helm Chart

[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/janus-idp&style=flat-square)](https://artifacthub.io/packages/search?repo=janus-idp)
![Version: 2.10.4](https://img.shields.io/badge/Version-2.10.4-informational?style=flat-square)
![Version: 2.10.5](https://img.shields.io/badge/Version-2.10.5-informational?style=flat-square)
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

A Helm chart for deploying a Backstage application
Expand Down
160 changes: 140 additions & 20 deletions charts/backstage/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"additionalProperties": false,
"properties": {
"includes": {
"default": [],
"default": [
"dynamic-plugins.default.yaml"
],
"items": {
"type": "string"
},
Expand Down Expand Up @@ -98,12 +100,12 @@
"type": "object"
},
"enabled": {
"default": false,
"default": true,
"title": "Enable the creation of the route resource.",
"type": "boolean"
},
"host": {
"default": "",
"default": "{{ .Values.global.host }}",
"examples": [
"https://bakstage.example.com"
],
Expand Down Expand Up @@ -134,7 +136,7 @@
"type": "string"
},
"enabled": {
"default": false,
"default": true,
"title": "Enable TLS configuration for the host defined at `route.host` parameter.",
"type": "boolean"
},
Expand Down Expand Up @@ -194,7 +196,30 @@
"type": "object"
},
"appConfig": {
"default": {},
"default": {
"app": {
"baseUrl": "https://{{- include \"janus-idp.hostname\" . }}"
},
"backend": {
"auth": {
"keys": [
{
"secret": "${BACKEND_SECRET}"
}
]
},
"baseUrl": "https://{{- include \"janus-idp.hostname\" . }}",
"cors": {
"origin": "https://{{- include \"janus-idp.hostname\" . }}"
},
"database": {
"connection": {
"password": "${POSTGRESQL_ADMIN_PASSWORD}",
"user": "postgres"
}
}
}
},
"examples": [
{
"app": {
Expand All @@ -209,18 +234,18 @@
]
},
"args": {
"default": [],
"default": [
"--config",
"dynamic-plugins-root/app-config.dynamic-plugins.yaml"
],
"items": {
"type": "string"
},
"title": "Backstage container command arguments",
"type": "array"
},
"command": {
"default": [
"node",
"packages/backend"
],
"default": [],
"items": {
"type": "string"
},
Expand Down Expand Up @@ -1541,7 +1566,26 @@
"type": "array"
},
"extraEnvVars": {
"default": [],
"default": [
{
"name": "BACKEND_SECRET",
"valueFrom": {
"secretKeyRef": {
"key": "backend-secret",
"name": "{{ include \"janus-idp.backend-secret-name\" $ }}"
}
}
},
{
"name": "POSTGRESQL_ADMIN_PASSWORD",
"valueFrom": {
"secretKeyRef": {
"key": "postgres-password",
"name": "{{ .Release.Name }}-postgresql"
}
}
}
],
"examples": [
[
{
Expand Down Expand Up @@ -1681,7 +1725,12 @@
"type": "array"
},
"extraVolumeMounts": {
"default": [],
"default": [
{
"mountPath": "/opt/app-root/src/dynamic-plugins-root",
"name": "dynamic-plugins-root"
}
],
"items": {
"description": "VolumeMount describes a mounting of a Volume within a container.",
"properties": {
Expand Down Expand Up @@ -1720,7 +1769,41 @@
"type": "array"
},
"extraVolumes": {
"default": [],
"default": [
{
"ephemeral": {
"volumeClaimTemplate": {
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "1Gi"
}
}
}
}
},
"name": "dynamic-plugins-root"
},
{
"configMap": {
"defaultMode": 420,
"name": "dynamic-plugins",
"optional": true
},
"name": "dynamic-plugins"
},
{
"name": "dynamic-plugins-npmrc",
"secret": {
"defaultMode": 420,
"optional": true,
"secretName": "dynamic-plugins-npmrc"
}
}
],
"items": {
"description": "Volume represents a named volume in a pod that may be accessed by any container in the pod.",
"properties": {
Expand Down Expand Up @@ -3242,7 +3325,7 @@
"type": "array"
},
"registry": {
"default": "ghcr.io",
"default": "quay.io",
"examples": [
"ghcr.io",
"quay.io",
Expand All @@ -3252,7 +3335,7 @@
"type": "string"
},
"repository": {
"default": "backstage/backstage",
"default": "janus-idp/backstage-showcase",
"title": "Backstage image repository",
"type": "string"
},
Expand All @@ -3267,7 +3350,42 @@
"type": "object"
},
"initContainers": {
"default": [],
"default": [
{
"command": [
"./install-dynamic-plugins.sh",
"/dynamic-plugins-root"
],
"env": [
{
"name": "NPM_CONFIG_USERCONFIG",
"value": "/opt/app-root/src/.npmrc.dynamic-plugins"
}
],
"image": "{{ include \"backstage.image\" . }}",
"imagePullPolicy": "Always",
"name": "install-dynamic-plugins",
"volumeMounts": [
{
"mountPath": "/dynamic-plugins-root",
"name": "dynamic-plugins-root"
},
{
"mountPath": "/opt/app-root/src/dynamic-plugins.yaml",
"name": "dynamic-plugins",
"readOnly": true,
"subPath": "dynamic-plugins.yaml"
},
{
"mountPath": "/opt/app-root/src/.npmrc.dynamic-plugins",
"name": "dynamic-plugins-npmrc",
"readOnly": true,
"subPath": ".npmrc"
}
],
"workingDir": "/opt/app-root/src"
}
],
"items": {
"description": "A single application container that you want to run within a pod.",
"properties": {
Expand Down Expand Up @@ -4428,7 +4546,7 @@
"type": "array"
},
"installDir": {
"default": "/app",
"default": "/opt/app-root/src",
"title": "Directory containing the backstage installation",
"type": "string"
},
Expand Down Expand Up @@ -4580,7 +4698,9 @@
"additionalProperties": {
"type": "string"
},
"default": {},
"default": {
"checksum/dynamic-plugins": "{{- include \"common.tplvalues.render\" ( dict \"value\" .Values.global.dynamic \"context\" $) | sha256sum }}"
},
"title": "Annotations to add to the backend deployment pods",
"type": "object"
},
Expand Down Expand Up @@ -5209,7 +5329,7 @@
"type": "boolean"
},
"host": {
"default": "",
"default": "{{ .Values.global.host }}",
"examples": [
"backstage.10.0.0.1.nip.io"
],
Expand Down Expand Up @@ -5296,7 +5416,7 @@
"type": "object"
},
"nameOverride": {
"default": "",
"default": "backstage",
"title": "String to partially override common.names.fullname",
"type": "string"
},
Expand Down

0 comments on commit addbde9

Please sign in to comment.