Use this rule to control that the YAML documents do contain a required key (parameter required-key-name). Parameters can be defined as a regular expression.
Because not all documents are certainly expected to contain the indicated key, an initial "filter" key/value (the parameters parent-key-name and parent-key-value) is used to identify the documents that must be checked. Use the parameter parent-key-name-root to tell where this so-called parent key must be located in the document. The location of the key can also be defined with two ancestor regular expressions.
yescode>),
if it must not be located at the root level of the document (not) or if it can be located anywhere
in the document (anywhere):) and always start with an implicit <root> parent.
So, the ancestor string for a connectionTimeout key could be: <root>:spring:datasource:hikari.
If the includedAncestors regex matches the ancestor string of the key, the key is checked.
The start and end line markers ^ and $ are implicit, just like the key regex.
Leave empty for no included ancestor matching.^ and $ are implicit, just like the key regex.
Leave empty for no excluded ancestor matching.With parent-key-name = kind and parent-key-value = Pod and parent-key-name-root = yes and required-key-name = readinessProbe
the following code snippet would PASS:
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-http
spec:
containers:
- name: liveness
image: k8s.gcr.io/liveness
args:
- /server
readinessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
the following code snippets would FAIL:
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-http
spec:
containers:
- name: liveness
image: k8s.gcr.io/liveness
args:
- /server
initialDelaySeconds: 3
periodSeconds: 3
With:
required-key-name = required.*
parentKeyName =
parentKeyValue =
isParentKeyAtRoot =
included-ancestors = .*:nesting\d
excluded-ancestors = .*:nesting2:nesting3
the following code snippet would PASS:
other1:
notRequired1: valueNot1
nesting8: # has required key
required8: value
the following code snippet would FAIL:
nesting1: # has no required.* key, violation
first2: valueF2
#required1: value1
nesting2:
#requiredYes: valueYes
nesting3:
required3Not: valueNot3
With:
required-key-name = waitDurationInOpenState.*|wait-duration-in-open-state.*
parentKeyName =
parentKeyValue =
isParentKeyAtRoot =
included-ancestors = .*:circuitbreaker
excluded-ancestors =
the following code snippet would PASS:
iov:
circuitbreaker:
failure-rate-threshold-percentage: 70
wait-duration-in-open-state-millis: 1500
resilience4j:
circuitbreaker:
failureRateThreshold: 50
waitDurationInOpenStateInSeconds: 60
the following code snippet would FAIL for two places:
iov:
circuitbreaker:
failure-rate-threshold-percentage: 70
#wait-duration-in-open-state-millis: 1500
resilience4j:
circuitbreaker:
failureRateThreshold: 50