Skip to content

Commit

Permalink
add [] to fixpath
Browse files Browse the repository at this point in the history
Signed-off-by: YiscahLevySilas1 <[email protected]>
  • Loading branch information
YiscahLevySilas1 committed Oct 12, 2023
1 parent 5629bb3 commit 5bba7c2
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions rules/k8s-common-labels-usage/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ no_K8s_label_usage(wl, podSpec, beggining_of_pod_path) = path{
no_K8s_label_or_no_K8s_label_usage(wl, start_of_path) = path{
not wl.metadata.labels
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_K8s_label_or_no_K8s_label_usage(wl, start_of_path) = path{
metadata := wl.metadata
not metadata.labels
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_K8s_label_or_no_K8s_label_usage(wl, start_of_path) = path{
labels := wl.metadata.labels
not all_kubernetes_labels(labels)
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

all_kubernetes_labels(labels){
Expand Down
2 changes: 1 addition & 1 deletion rules/k8s-common-labels-usage/test/cronjob/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "the following cronjobs the kubernetes common labels are not defined: hello",
"failedPaths": [],
"fixPaths": [{
"path": "spec.jobTemplate.spec.template.metadata.labels.app.kubernetes.io/name",
"path": "spec.jobTemplate.spec.template.metadata.labels[app.kubernetes.io/name]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
2 changes: 1 addition & 1 deletion rules/k8s-common-labels-usage/test/pod/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "in the following pod the kubernetes common labels are not defined: command-demo",
"failedPaths": [],
"fixPaths": [{
"path": "metadata.labels.YOUR_LABEL",
"path": "metadata.labels[YOUR_LABEL]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "Deployment: kubernetes-dashboard the kubernetes common labels are is not defined:",
"failedPaths": [],
"fixPaths": [{
"path": "spec.template.metadata.labels.app.kubernetes.io/name",
"path": "spec.template.metadata.labels[app.kubernetes.io/name]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
6 changes: 3 additions & 3 deletions rules/label-usage-for-resources/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ no_label_usage(wl, podSpec, beggining_of_pod_path) = path{
no_label_or_no_label_usage(wl, start_of_path) = path{
not wl.metadata
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_label_or_no_label_usage(wl, start_of_path) = path{
metadata := wl.metadata
not metadata.labels
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_label_or_no_label_usage(wl, start_of_path) = path{
labels := wl.metadata.labels
not is_desired_label(labels)
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

is_desired_label(labels) {
Expand Down
2 changes: 1 addition & 1 deletion rules/label-usage-for-resources/test/cronjob/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"path": "metadata.labels.YOUR_LABEL",
"value": "YOUR_VALUE"
}, {
"path": "spec.jobTemplate.spec.template.metadata.labels.YOUR_LABEL",
"path": "spec.jobTemplate.spec.template.metadata.labels[YOUR_LABEL]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "Deployment: kubernetes-dashboard a certain set of labels is not defined:",
"failedPaths": [],
"fixPaths": [{
"path": "spec.template.metadata.labels.app",
"path": "spec.template.metadata.labels[app]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down

0 comments on commit 5bba7c2

Please sign in to comment.