Skip to content

Commit 0304239

Browse files
committed
add a check
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
1 parent 4d420cd commit 0304239

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

e2etests/bats-tests.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ get_value_from() {
6363
[[ "${message2}" =~ "Pod: resource is not valid:" ]]
6464
}
6565

66+
@test "builtin-schema-validation" {
67+
tmp="tests/checks/kubeconform.yml"
68+
cmd="${KUBE_LINTER_BIN} lint --config e2etests/testdata/schema-validation-config.yaml --do-not-auto-add-defaults --format json ${tmp}"
69+
run ${cmd}
70+
71+
print_info "${status}" "${output}" "${cmd}" "${tmp}"
72+
[ "$status" -eq 1 ]
73+
74+
message1=$(get_value_from "${lines[0]}" '.Reports[0].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[0].Diagnostic.Message')
75+
message2=$(get_value_from "${lines[0]}" '.Reports[1].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[1].Diagnostic.Message')
76+
count=$(get_value_from "${lines[0]}" '.Reports | length')
77+
78+
# Should find 2 validation errors using builtin schema-validation check
79+
[[ "${count}" == "2" ]]
80+
[[ "${message1}" =~ "DaemonSet: resource is not valid:" ]]
81+
[[ "${message2}" =~ "Pod: resource is not valid:" ]]
82+
}
83+
6684
@test "template-check-installed-bash-version" {
6785
run "bash --version"
6886
[[ "${BASH_VERSION:0:1}" -ge '4' ]] || false

pkg/command/lint/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func Command() *cobra.Command {
156156
c.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
157157
c.Flags().Var(format, "format", format.Usage())
158158
c.Flags().BoolVarP(&errorOnInvalidResource, "fail-on-invalid-resource", "", false, "Error out when we have an invalid resource")
159+
c.Flags().MarkDeprecated("fail-on-invalid-resource", "Use 'schema-validation' builtin check or kubeconform template for better schema validation.")
159160

160161
config.AddFlags(c, v)
161162
return c

0 commit comments

Comments
 (0)