Skip to content

Commit

Permalink
code review tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Henrique Medeiros committed Feb 26, 2025
1 parent 5aff97a commit ac26590
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/generated/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ key: owner
**Enabled by default**: No
**Description**: Indicates when a object deployment's like doesn't use a restart policy
**Description**: Indicates when a deployment-like object does not use a restart policy
**Remediation**: Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.
Expand Down
28 changes: 14 additions & 14 deletions e2etests/bats-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -790,22 +790,22 @@ get_value_from() {
cmd="${KUBE_LINTER_BIN} lint --include restart-policy --do-not-auto-add-defaults --format json ${tmp}"
run ${cmd}

message1=$(get_value_from "${lines[0]}" '.Reports[0].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[0].Diagnostic.Message')
message2=$(get_value_from "${lines[0]}" '.Reports[1].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[1].Diagnostic.Message')
message3=$(get_value_from "${lines[0]}" '.Reports[2].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[2].Diagnostic.Message')
message4=$(get_value_from "${lines[0]}" '.Reports[3].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[3].Diagnostic.Message')
message5=$(get_value_from "${lines[0]}" '.Reports[4].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[4].Diagnostic.Message')
message6=$(get_value_from "${lines[0]}" '.Reports[5].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[5].Diagnostic.Message')
message7=$(get_value_from "${lines[0]}" '.Reports[6].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[6].Diagnostic.Message')
message1=$(get_value_from "${lines[0]}" '.Reports[0] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
message2=$(get_value_from "${lines[0]}" '.Reports[1] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
message3=$(get_value_from "${lines[0]}" '.Reports[2] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
message4=$(get_value_from "${lines[0]}" '.Reports[3] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
message5=$(get_value_from "${lines[0]}" '.Reports[4] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
message6=$(get_value_from "${lines[0]}" '.Reports[5] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
message7=$(get_value_from "${lines[0]}" '.Reports[6] | .Object.K8sObject.GroupVersionKind.Kind + " " + .Object.K8sObject.Name + ": " + .Diagnostic.Message')
count=$(get_value_from "${lines[0]}" '.Reports | length')

[[ "${message1}" == "Deployment: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message2}" == "Pod: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message3}" == "DaemonSet: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message4}" == "ReplicaSet: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message5}" == "ReplicationController: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message6}" == "Job: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message7}" == "CronJob: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message1}" == "Deployment fire-deployment-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message2}" == "Pod fire-pod-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message3}" == "DaemonSet fire-daemonset-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message4}" == "ReplicaSet fire-replicaset-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message5}" == "ReplicationController fire-replicationcontroller-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message6}" == "Job fire-job-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${message7}" == "CronJob fire-cronjob-never: object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'" ]]
[[ "${count}" == "7" ]]
}

Expand Down
1 change: 1 addition & 0 deletions e2etests/linter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Checks":[{"name":"restart-policy","description":"Indicates when a deployment-like object does not use a restart policy","remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","scope":{"objectKinds":["DeploymentLike"]},"template":"restart-policy"}],"Reports":[{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-deployment-never","GroupVersionKind":{"Group":"apps","Version":"v1","Kind":"Deployment"}}}},{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-pod-never","GroupVersionKind":{"Group":"","Version":"v1","Kind":"Pod"}}}},{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-daemonset-never","GroupVersionKind":{"Group":"apps","Version":"v1","Kind":"DaemonSet"}}}},{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-replicaset-never","GroupVersionKind":{"Group":"apps","Version":"v1","Kind":"ReplicaSet"}}}},{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-replicationcontroller-never","GroupVersionKind":{"Group":"","Version":"v1","Kind":"ReplicationController"}}}},{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-job-never","GroupVersionKind":{"Group":"batch","Version":"v1","Kind":"Job"}}}},{"Diagnostic":{"Message":"object has a restart policy defined with 'Never' but the only accepted restart policies are '[Always OnFailure]'"},"Check":"restart-policy","Remediation":"Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.","Object":{"Metadata":{"FilePath":"/Users/jonathanhenrique/Documents/Git/kube-linter/tests/checks/restart-policy.yaml"},"K8sObject":{"Namespace":"","Name":"fire-cronjob-never","GroupVersionKind":{"Group":"batch","Version":"v1","Kind":"CronJob"}}}}],"Summary":{"ChecksStatus":"Failed","CheckEndTime":"2025-02-26T15:11:16.725109Z","KubeLinterVersion":"0.6.7-SNAPSHOT-5aff97a"}}
2 changes: 1 addition & 1 deletion pkg/builtinchecks/yamls/restart-policy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "restart-policy"
description: "Indicates when a object deployment's like doesn't use a restart policy"
description: "Indicates when a deployment-like object does not use a restart policy"
remediation: >-
Set up the restart policy for your object to 'Always' or 'OnFailure' to increase the fault tolerance.
scope:
Expand Down

0 comments on commit ac26590

Please sign in to comment.