Config Structural Validation Schema Part 1: Commons, HNC, CAPI, Harbor, Storage#2063
Config Structural Validation Schema Part 1: Commons, HNC, CAPI, Harbor, Storage#2063
Conversation
089dffc to
777f75f
Compare
c04f818 to
f5ba5cd
Compare
f5ba5cd to
67a2a80
Compare
608c589 to
e523d22
Compare
Xartos
left a comment
There was a problem hiding this comment.
I'm not familiar with this schema format. Do you have any good link to where I can read about it? Or maybe just the name of it so I can search for it
|
See https://github.com/elastisys/compliantkubernetes-apps/blob/main/config/schemas/README.md It's also closely related to the OpenAPI format used in CRDs. |
e30f226 to
f73acdf
Compare
Xartos
left a comment
There was a problem hiding this comment.
Some minor things but overall it looks good 👍
ad37254 to
c8c9100
Compare
config/schemas/config.yaml
Outdated
| kubernetesAffinity: | ||
| $comment: Real k8s resources might have existing schemas that could be reused as-is | ||
| properties: | ||
| nodeAffinity: | ||
| type: object | ||
| podAffinity: | ||
| type: object | ||
| podAntiAffinity: | ||
| type: object | ||
| additionalProperties: false | ||
| examples: | ||
| - nodeAffinity: | ||
| requiredDuringSchedulingIgnoredDuringExecution: | ||
| nodeSelectorTerms: | ||
| - matchExpressions: | ||
| - key: node-role.kubernetes.io/control-plane | ||
| operator: Exists | ||
| title: Kubernetes Affinity | ||
| type: object |
There was a problem hiding this comment.
You should be able to source from the upstream OpenAPI spec, though it don't know how well it matches.
The bulk of common definitions are in api_openapi.json and basically everything are refs.
There was a problem hiding this comment.
diff --git a/config/schemas/config.yaml b/config/schemas/config.yaml
index b10d2a9f..9c3fe3f9 100644
--- a/config/schemas/config.yaml
+++ b/config/schemas/config.yaml
@@ -8,7 +8,6 @@ description: |
file will contain different settings.
$defs:
kubernetesAffinity:
- $comment: Real k8s resources might have existing schemas that could be reused as-is
properties:
nodeAffinity:
type: object
@@ -19,11 +18,7 @@ $defs:
additionalProperties: false
examples:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: node-role.kubernetes.io/control-plane
- operator: Exists
+ $ref: https://github.com/kubernetes/kubernetes/raw/master/api/openapi-spec/v3/api__v1_openapi.json#/components/schemas/io.k8s.api.core.v1.NodeAffinity
title: Kubernetes Affinity
type: object
component:🤔
There was a problem hiding this comment.
Heh, accidentally put the $ref under examples. Now fixed.
I'm a bit uneasy about referencing remote files tho, and not sure if licensing allows copying subsets.
There was a problem hiding this comment.
Should be fine to copy the subset with proper attribution given that the upstream spec is Apache-2.0, so if you add a comment in the spec where you include it and a notice in the readme then it should be OK.
There was a problem hiding this comment.
Those affinity settings contain further $references which point to things with even more references, turning this into a recursive chase that may need further though or some scripting.
There was a problem hiding this comment.
Hooray for loops!
[ck8s] Failed schema validation:
wc-config.yaml: hnc.manager.nodeSelector: nodeSelectorTerms is required
wc-config.yaml: velero.nodeSelector: nodeSelectorTerms is required
What to do with these? This could be due to importing definitions from latest k8s git. I haven't investigated yet.
There was a problem hiding this comment.
Oh no, NodeSelector and nodeSelector are different things.
There was a problem hiding this comment.
I've made it so that .$defs.kubernetesThing are kubernetes properties where we wrote the schema, while those imported from the kubernetes API spec files have names like .$defs["io.k8s.api.core.v1.Affinity"].
robinAwallace
left a comment
There was a problem hiding this comment.
I think it LGTM 🙂 Found one question mark.
|
Incoming rebase onto latest |
2eb9e72 to
3f7fcba
Compare
|
I've prepared a squashed commit, aiming to push and merge on Monday. |
This adds:
- common reusable things under $defs
- clusterApi
- harbor
- hnc
- objectStorage
- rookCeph
- storageClasses
- user
- velero
Common objects defined by the Kubernetes project are either prefixed
with 'kubernetes' when authored by us, using an 'io.k8s' prefix when
imported directly from the Kubernetes API definitions.
They can be found in the file kubernetes/spec/api/openapi-spec/v3/api__v1_openapi.json
The following script was used to find all referenced objects that were needed.
```bash
set -euxo pipefail
yq4 -i -P 'del(.$defs.kubernetesAffinity)' config/schemas/config.yaml
c="io.k8s.api.core.v1.Affinity" yq4 -i -P '.$defs[env(c)] = load(".../kubernetes/api/openapi-spec/v3/api__v1_openapi.json").components.schemas[env(c)]' config/schemas/config.yaml
c="io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelectorRequirement" yq4 -i -P '.$defs[env(c)] = load(".../kubernetes/api/openapi-spec/v3/api__v1_openapi.json").components.schemas[env(c)]' config/schemas/config.yaml
while grep -qF '#/components/schemas/' config/schemas/config.yaml; do
for component in $(grep -oP "#/components/schemas/[^'\"]*" config/schemas/config.yaml | cut -d/ -f4); do
c="${component}" yq4 -i -P '.$defs[env(c)] = load(".../kubernetes/api/openapi-spec/v3/api__v1_openapi.json").components.schemas[env(c)]' config/schemas/config.yaml
sed -i "s|#/components/schemas/${component}|#/\$defs/${component}|" config/schemas/config.yaml
done
done
```
Co-authored-by: André Arnqvist <58822152+aarnq@users.noreply.github.com>
Co-authored-by: Fredrik Liv <fredrik.liv@elastisys.com>
Warning
This is a public repository, ensure not to disclose:
What kind of PR is this?
Required: Mark one of the following that is applicable:
Optional: Mark one or more of the following that are applicable:
Important
Breaking changes should be marked
kind/admin-changeorkind/dev-changedepending on typeCritical security fixes should be marked with
kind/securityWhat does this PR do / why do we need this PR?
This adds structural validation for the following top-level config sections:
For more context including the required scripts and see #1862
Part of issue #1427
Information to reviewers
ck8s validateshould now perform validation of the above sections.While the CI is failing:
Please help determine whether it is the schema that is lacking or whether it detected a config mistake.
Suggestions and improvements very welcome!
Also see the README for brief information about the schema format
Checklist
NetworkPolicy Dashboard