You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggestion: add the for keyword in the example and how to use it for additional kubernetes rules.
Example from examples/folder:
local kp = (import'kube-prometheus/main.libsonnet') + {
values+:: {
common+: {
namespace:'monitoring',
},
},
exampleApplication: {
prometheusRuleExample: {
apiVersion:'monitoring.coreos.com/v1',
kind:'PrometheusRule',
metadata: {
name:'my-prometheus-rule',
namespace: $.values.common.namespace,
},
spec: {
groups: [
{
name:'example-group',
rules: [
{
alert:'ExampleAlert',
expr:'vector(1)',
labels: {
severity:'warning',
},
annotations: {
description:'This is an example alert.',
},
},
],
},
],
},
},
},
};
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name instd.objectFields(kp.kubePrometheus) } +
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name instd.objectFields(kp.prometheusOperator) } +
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name instd.objectFields(kp.nodeExporter) } +
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name instd.objectFields(kp.kubeStateMetrics) } +
{ ['alertmanager-' + name]: kp.alertmanager[name] for name instd.objectFields(kp.alertmanager) } +
{ ['prometheus-' + name]: kp.prometheus[name] for name instd.objectFields(kp.prometheus) } +
{ ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name instd.objectFields(kp.prometheusAdapter) } +
{ ['grafana-' + name]: kp.grafana[name] for name instd.objectFields(kp.grafana) } +
{ ['example-application-' + name]: kp.exampleApplication[name] for name instd.objectFields(kp.exampleApplication) }
What I tried to do by add the for:
local kp = (import'kube-prometheus/main.libsonnet') + {
values+:: {
common+: {
namespace:'monitoring',
},
},
exampleApplication: {
prometheusRuleExample: {
apiVersion:'monitoring.coreos.com/v1',
kind:'PrometheusRule',
metadata: {
name:'my-prometheus-rule',
namespace: $.values.common.namespace,
},
spec: {
groups: [
{
name:'example-group',
rules: [
{
alert:'ExampleAlert',
expr:'vector(1)',
for:'5m',
labels: {
severity:'warning',
},
annotations: {
description:'This is an example alert.',
},
},
],
},
],
},
},
},
};
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name instd.objectFields(kp.kubePrometheus) } +
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name instd.objectFields(kp.prometheusOperator) } +
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name instd.objectFields(kp.nodeExporter) } +
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name instd.objectFields(kp.kubeStateMetrics) } +
{ ['alertmanager-' + name]: kp.alertmanager[name] for name instd.objectFields(kp.alertmanager) } +
{ ['prometheus-' + name]: kp.prometheus[name] for name instd.objectFields(kp.prometheus) } +
{ ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name instd.objectFields(kp.prometheusAdapter) } +
{ ['grafana-' + name]: kp.grafana[name] for name instd.objectFields(kp.grafana) } +
{ ['example-application-' + name]: kp.exampleApplication[name] for name instd.objectFields(kp.exampleApplication) }
Error: object comprehension can only have one field.
Reason: took me a few hours to realize what was going on and why the jsonnet was throwing errors when I attempted to add for keyword in the example below.
Solution: add quotes to the for keyword, so it is not interpreted in the function for name in std.objectFields... as a language keyword command.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Suggestion: add the
for
keyword in the example and how to use it for additional kubernetes rules.Example from
examples/
folder:What I tried to do by add the
for
:Error: object comprehension can only have one field.
Reason: took me a few hours to realize what was going on and why the jsonnet was throwing errors when I attempted to add
for
keyword in the example below.Solution: add quotes to the
for
keyword, so it is not interpreted in the functionfor name in std.objectFields...
as a language keyword command.Beta Was this translation helpful? Give feedback.
All reactions