prometheus-operator / kube-prometheus

Use Prometheus to monitor Kubernetes and applications running on Kubernetes
https://prometheus-operator.dev/
Apache License 2.0
6.68k stars 1.92k forks source link

Customizing alertmanager-main secret using examples/alertmanager-config-external.jsonnet generates wrong separated yaml files #989

Open malcolm061990 opened 3 years ago

malcolm061990 commented 3 years ago

What happened? Wrong output files are created after generating manifests using examples/alertmanager-config-external.jsonnet from the repo.

How to reproduce it (as minimally and precisely as possible): Just modify Makefile target to (changing examples/kustomize.jsonnet to examples/alertmanager-config-external.jsonnet; added PHONY):

.PHONY: manifests
manifests: examples/alertmanager-config-external.jsonnet $(GOJSONTOYAML_BIN) vendor build.sh
    ./build.sh $<

Run:

make manifests # generate manifests
ls -al manifests/ # show output (below)
apiVersion.yaml
kind.yaml
metadata.yaml
setup
stringData.yaml
type.yaml

For some reason it generates all yaml fields in separated yaml files that is useless for applying to k8s cluster. But the values in these files are correct.

Environment

master branch of this project

malcolm061990 commented 3 years ago

If someone is interested in solution I changed my alertmanager-config-external-my.jsonnet to:

local kp =
(import 'kube-prometheus/main.libsonnet') +
  {
    values+:: {
      alertmanager+: {
        config: importstr 'alertmanager-config-my.yaml',
        namespace: 'monitoring',
      },
    },
  };

{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) }

Now it generates the output correctly. But my question in this topic is still actual.

brancz commented 3 years ago

cc @paulfantom

paulfantom commented 3 years ago

Omission from my side, sorry for that.

@malcolm061990 your solution looks good to me, can you create a PR to fix the example?

malcolm061990 commented 3 years ago

Omission from my side, sorry for that.

@malcolm061990 your solution looks good to me, can you create a PR to fix the example?

Never created PRs in that project :) How can I create the PR?

paulfantom commented 3 years ago

If you ask generally how to create PR, then this should be good: https://opensource.com/article/19/7/create-pull-request-github

As for what needs to be done in that PR, I think swapping our current examples/alertmanager-config-external.jsonnet with what you proposed in https://github.com/prometheus-operator/kube-prometheus/issues/989#issuecomment-787730912 should be good. After swapping it, run make generate and push your changes :)