Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
prometheus-operator: Add external_url
Browse files Browse the repository at this point in the history
This commit adds the feature removed sometime back called `external_url`
this allows the user to choose where(URL) the prometheus is exposed.

Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
  • Loading branch information
surajssd committed Sep 22, 2020
1 parent 5ba9d5c commit 861cadf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Example:
| `prometheus.ingress.host` | Ingress URL host to expose Prometheus over the internet. **NOTE:** When running on Packet, a DNS entry pointing at the ingress controller needs to be created. | - | string | true |
| `prometheus.ingress.class` | Ingress class to use for Prometheus ingress. | `contour` | string | false |
| `prometheus.ingress.certmanager_cluster_issuer` | `ClusterIssuer` to be used by cert-manager while issuing TLS certificates. Supported values: `letsencrypt-production`, `letsencrypt-staging`. | `letsencrypt-production` | string | false |
| `prometheus.external_url` | The URL on which Prometheus will be accessible on. If this is not provided then the URL is taken from `prometheus.ingress.host` with `https` as a scheme. | - | string | false |
| `alertmanager_retention` | Time duration Alertmanager shall retain data for. Must match the regular expression `[0-9]+(ms\|s\|m\|h)` (milliseconds, seconds, minutes and hours). | `120h` | string | false |
| `alertmanager_external_url` | The external URL the Alertmanager instances will be available under. This is necessary to generate correct URLs. This is necessary if Alertmanager is not served from root of a DNS name. | "" | string | false |
| `alertmanager_config` | Provide YAML file path to configure Alertmanager. See [https://prometheus.io/docs/alerting/configuration/#configuration-file](https://prometheus.io/docs/alerting/configuration/#configuration-file). | `{"global":{"resolve_timeout":"5m"},"route":{"group_by":["job"],"group_wait":"30s","group_interval":"5m","repeat_interval":"12h","receiver":"null","routes":[{"match":{"alertname":"Watchdog"},"receiver":"null"}]},"receivers":[{"name":"null"}]}` | string | false |
Expand Down
25 changes: 25 additions & 0 deletions pkg/components/prometheus-operator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package prometheus

import (
"fmt"
"net/url"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
Expand Down Expand Up @@ -63,6 +64,7 @@ type Prometheus struct {
WatchLabeledPrometheusRules bool `hcl:"watch_labeled_prometheus_rules,optional"`
Ingress *types.Ingress `hcl:"ingress,block"`
ExternalLabels map[string]string `hcl:"external_labels,optional"`
ExternalURL string `hcl:"external_url,optional"`
}

type component struct {
Expand Down Expand Up @@ -162,6 +164,29 @@ func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContex
c.Prometheus.Ingress.SetDefaults()
}

// If user has provided `ingress` block in prometheus and `externalURL` both then they should be
// same.
if c.Prometheus != nil && c.Prometheus.ExternalURL != "" && c.Prometheus.Ingress != nil {
exu, err := url.Parse(c.Prometheus.ExternalURL)
if err != nil {
return hcl.Diagnostics{
{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("'external_url' is invalid, got error: %v", err),
},
}
}

if exu.Host != c.Prometheus.Ingress.Host {
return hcl.Diagnostics{
{
Severity: hcl.DiagError,
Summary: "'external_url' and 'prometheus.ingress.host' does not match",
},
}
}
}

return nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/components/prometheus-operator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ prometheus:
secretName: {{ .Prometheus.Ingress.Host }}-tls
{{ end }}
prometheusSpec:
{{ if .Prometheus.Ingress }}
{{ if .Prometheus.ExternalURL }}
externalUrl: {{ .Prometheus.ExternalURL }}
{{ else if .Prometheus.Ingress }}
externalUrl: https://{{.Prometheus.Ingress.Host}}
{{ end }}
{{ if .Prometheus.NodeSelector }}
Expand Down

0 comments on commit 861cadf

Please sign in to comment.