Skip to content

Commit e458b6a

Browse files
committed
add schema generation for helm
1 parent a455640 commit e458b6a

File tree

6 files changed

+194
-28
lines changed

6 files changed

+194
-28
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ repos:
77
exclude: ^Charts/.*/templates
88
- id: check-merge-conflict
99
- id: end-of-file-fixer
10+
11+
- repo: https://github.com/losisin/helm-values-schema-json
12+
rev: v2.2.1
13+
hooks:
14+
- id: helm-schema
15+
args:
16+
- --config
17+
- Charts/dev-c7/.schema.config.yaml

Charts/dev-c7/.schema.config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# .schema.yaml
2+
3+
# Define input, output and source for $refs relative to repository root for pre-commit
4+
values:
5+
- Charts/dev-c7/values.yaml
6+
7+
output: Charts/dev-c7/values.schema.json
8+
9+
# bundle up references (don't do this as K8S refs are 500kb+)
10+
bundleRoot: Charts
11+
bundle: false
12+
13+
# Include comments for the helm-docs plugin into the schema, to allow e.g. documentation in VSCode
14+
useHelmDocs: false
15+
16+
# Allow additional properties for eg. initResources, different types of volumes/volumeMounts
17+
noAdditionalProperties: false
18+
19+
schemaRoot:
20+
title: dev-c7 Helm chart
21+
description: Helm chart for deploying a dev-c7 application
22+
# No additional properties in schema root for tighter protection:
23+
additionalProperties: false
24+
25+
k8sSchemaVersion: v1.33.3

Charts/dev-c7/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ spec:
3939
- "-c"
4040
- "sleep infinity"
4141
workingDir: /dls_sw/prod/R3.14.12.7/ioc/BL16I/BL16I-MO-IOC-12/21-2
42+
{{- with .Values.securityContext }}
43+
securityContext:
44+
{{- toYaml . | nindent 12 }}
45+
{{- end }}
4246
env:
4347
- name: HOME
4448
value: /home/{{ .Values.userName }}

Charts/dev-c7/values.schema.json

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "dev-c7 Helm chart",
4+
"description": "Helm chart for deploying a dev-c7 application",
5+
"type": "object",
6+
"properties": {
7+
"affinity": {
8+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/affinity.json",
9+
"type": "object"
10+
},
11+
"fullnameOverride": {
12+
"type": "string"
13+
},
14+
"global": {
15+
"description": "shared values for all services",
16+
"type": "object",
17+
"additionalProperties": true
18+
},
19+
"hostNetwork": {
20+
"description": "enable host networking for the pod",
21+
"type": "boolean"
22+
},
23+
"image": {
24+
"description": "container image URI",
25+
"type": "object",
26+
"properties": {
27+
"pullPolicy": {
28+
"type": "string"
29+
},
30+
"repository": {
31+
"type": "string"
32+
},
33+
"tag": {
34+
"type": "string"
35+
}
36+
}
37+
},
38+
"imagePullSecrets": {
39+
"type": "array"
40+
},
41+
"nameOverride": {
42+
"type": "string"
43+
},
44+
"nodeSelector": {
45+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/podspec.json#/properties/nodeSelector",
46+
"type": "object"
47+
},
48+
"podAnnotations": {
49+
"description": "Add annotations to the pod",
50+
"type": "object"
51+
},
52+
"podLabels": {
53+
"description": "Add labels to the pod",
54+
"type": "object"
55+
},
56+
"podSecurityContext": {
57+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/podspec.json#/properties/securityContext",
58+
"type": "object"
59+
},
60+
"replicaCount": {
61+
"description": "Set to 0 to stop the IOC, 1 to run the IOC",
62+
"type": "integer"
63+
},
64+
"resources": {
65+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/container.json#/properties/resources",
66+
"type": "object"
67+
},
68+
"securityContext": {
69+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/container.json#/properties/securityContext",
70+
"type": "object"
71+
},
72+
"tolerations": {
73+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/podspec.json#/properties/tolerations",
74+
"type": "array"
75+
},
76+
"userId": {
77+
"type": "integer"
78+
},
79+
"userName": {
80+
"type": "string"
81+
},
82+
"volumeMounts": {
83+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/container.json#/properties/volumeMounts",
84+
"type": "array",
85+
"items": {
86+
"type": "object",
87+
"properties": {
88+
"mountPath": {
89+
"type": "string"
90+
},
91+
"name": {
92+
"type": "string"
93+
},
94+
"readOnly": {
95+
"type": "boolean"
96+
}
97+
}
98+
}
99+
},
100+
"volumes": {
101+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.33.3/podspec.json#/properties/volumes",
102+
"type": "array",
103+
"items": {
104+
"type": "object",
105+
"properties": {
106+
"hostPath": {
107+
"type": "object",
108+
"properties": {
109+
"path": {
110+
"type": "string"
111+
}
112+
}
113+
},
114+
"name": {
115+
"type": "string"
116+
}
117+
}
118+
}
119+
}
120+
},
121+
"additionalProperties": false
122+
}

Charts/dev-c7/values.yaml

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
# Default values for dls-k8s-c7.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
1+
# yaml-language-server: $schema=values.schema.json
42

5-
# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/
3+
# NOTE: the $k8s schema references come from
4+
# https://github.com/yannh/kubernetes-json-schema/tree/master/v1.33.1
5+
# with the version set in .fastcs.schema.config.yaml (k8sSchemaVersion)
6+
7+
# Default values for dev-c7 chart.
8+
# With annotations for building the schema using:
9+
# https://github.com/losisin/helm-values-schema-json.git
10+
11+
# @schema description: shared values for all services
12+
# @schema additionalProperties: true
13+
global: {}
14+
15+
# @schema description: Set to 0 to stop the IOC, 1 to run the IOC
616
replicaCount: 1
717

8-
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
18+
# @schema description: container image URI
919
image:
1020
repository: ghcr.io/diamondlightsource/dev-c7
1121
# This sets the pull policy for images.
@@ -17,7 +27,7 @@ image:
1727
userId: 1200288
1828
userName: hgv27681
1929

20-
# set to true for Channel access to be served on the locl subnet.
30+
# @schema description: enable host networking for the pod
2131
hostNetwork: false
2232

2333
# This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
@@ -26,31 +36,23 @@ imagePullSecrets: []
2636
nameOverride: ""
2737
fullnameOverride: ""
2838

29-
# This is for setting Kubernetes Annotations to a Pod.
30-
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
39+
# @schema description: Add annotations to the pod
3140
podAnnotations: {}
32-
# This is for setting Kubernetes Labels to a Pod.
33-
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
41+
42+
# @schema description: Add labels to the pod
3443
podLabels: {}
3544

36-
podSecurityContext:
37-
{}
38-
# fsGroup: 2000
39-
40-
resources:
41-
{}
42-
# We usually recommend not to specify default resources and to leave this as a conscious
43-
# choice for the user. This also increases chances charts run on environments with little
44-
# resources, such as Minikube. If you do want to specify resources, uncomment the following
45-
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
46-
# limits:
47-
# cpu: 100m
48-
# memory: 128Mi
49-
# requests:
50-
# cpu: 100m
51-
# memory: 128Mi
45+
# @schema $ref: $k8s/podspec.json#/properties/securityContext
46+
podSecurityContext: {}
47+
48+
# @schema $ref:$k8s/container.json#/properties/securityContext
49+
securityContext: {}
50+
51+
# @schema $ref: $k8s/container.json#/properties/resources
52+
resources: {}
5253

5354
# volumes for the Deployment.
55+
# @schema $ref: $k8s/podspec.json#/properties/volumes
5456
volumes:
5557
- name: work
5658
hostPath:
@@ -75,6 +77,7 @@ volumes:
7577
path: /home/hgv27681
7678

7779
# volumeMounts for the Deployment.
80+
# @schema $ref: $k8s/container.json#/properties/volumeMounts
7881
volumeMounts:
7982
- name: work
8083
mountPath: /dls_sw/work
@@ -97,8 +100,11 @@ volumeMounts:
97100
- name: home
98101
mountPath: /home/hgv27681
99102

100-
nodeSelector: {}
101-
103+
# @schema $ref: $k8s/podspec.json#/properties/tolerations
102104
tolerations: []
103105

106+
# @schema $ref: $k8s/podspec.json#/properties/nodeSelector
107+
nodeSelector: {}
108+
109+
# @schema $ref: $k8s/affinity.json
104110
affinity: {}

schema/dev-c7.values.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Charts/dev-c7/values.schema.json

0 commit comments

Comments
 (0)