Skip to content

Commit

Permalink
Allow user to configure hostAliases for Alertmanager, Prometheus and
Browse files Browse the repository at this point in the history
Thanos Pods.

Signed-off-by: heylongdacoder <heylongdacoder@gmail.com>
  • Loading branch information
heylongdacoder committed May 31, 2022
1 parent 4d3e02c commit df59cb0
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Documentation/api.md
Expand Up @@ -31,6 +31,7 @@ This Document documents the types introduced by the Prometheus Operator to be co
* [EmbeddedObjectMetadata](#embeddedobjectmetadata)
* [EmbeddedPersistentVolumeClaim](#embeddedpersistentvolumeclaim)
* [Endpoint](#endpoint)
* [HostAlias](#hostalias)
* [MetadataConfig](#metadataconfig)
* [NamespaceSelector](#namespaceselector)
* [OAuth2](#oauth2)
Expand Down Expand Up @@ -253,6 +254,7 @@ AlertmanagerSpec is a specification of the desired behavior of the Alertmanager
| alertmanagerConfigSelector | AlertmanagerConfigs to be selected for to merge and configure Alertmanager with. | *[metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#labelselector-v1-meta) | false |
| alertmanagerConfigNamespaceSelector | Namespaces to be selected for AlertmanagerConfig discovery. If nil, only check own namespace. | *[metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#labelselector-v1-meta) | false |
| minReadySeconds | Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready) This is an alpha field and requires enabling StatefulSetMinReadySeconds feature gate. | *uint32 | false |
| hostAliases | Pods' hostAliases configuration | [][HostAlias](#hostalias) | false |
| alertmanagerConfiguration | EXPERIMENTAL: alertmanagerConfiguration specifies the global Alertmanager configuration. If defined, it takes precedence over the `configSecret` field. This field may change in future releases. | *[AlertmanagerConfiguration](#alertmanagerconfiguration) | false |

[Back to TOC](#table-of-contents)
Expand Down Expand Up @@ -377,6 +379,20 @@ Endpoint defines a scrapeable endpoint serving Prometheus metrics.

[Back to TOC](#table-of-contents)

## HostAlias

HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file.


<em>appears in: [AlertmanagerSpec](#alertmanagerspec), [PrometheusSpec](#prometheusspec), [ThanosRulerSpec](#thanosrulerspec)</em>

| Field | Description | Scheme | Required |
| ----- | ----------- | ------ | -------- |
| ip | IP address of the host file entry. | string | true |
| hostnames | Hostnames for the above IP address. | []string | true |

[Back to TOC](#table-of-contents)

## MetadataConfig

MetadataConfig configures the sending of series metadata to the remote storage.
Expand Down Expand Up @@ -829,6 +845,7 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus
| enforcedLabelValueLengthLimit | Per-scrape limit on length of labels value that will be accepted for a sample. If a label value is longer than this number post metric-relabeling, the entire scrape will be treated as failed. 0 means no limit. Only valid in Prometheus versions 2.27.0 and newer. | *uint64 | false |
| enforcedBodySizeLimit | EnforcedBodySizeLimit defines the maximum size of uncompressed response body that will be accepted by Prometheus. Targets responding with a body larger than this many bytes will cause the scrape to fail. Example: 100MB. If defined, the limit will apply to all service/pod monitors and probes. This is an experimental feature, this behaviour could change or be removed in the future. Only valid in Prometheus versions 2.28.0 and newer. | ByteSize | false |
| minReadySeconds | Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready) This is an alpha field and requires enabling StatefulSetMinReadySeconds feature gate. | *uint32 | false |
| hostAliases | Pods' hostAliases configuration | [][HostAlias](#hostalias) | false |
| retention | Time duration Prometheus shall retain data for. Default is '24h' if retentionSize is not set, and must match the regular expression `[0-9]+(ms\|s\|m\|h\|d\|w\|y)` (milliseconds seconds minutes hours days weeks years). | Duration | false |
| retentionSize | Maximum amount of disk space used by blocks. | ByteSize | false |
| disableCompaction | Disable prometheus compaction. | bool | false |
Expand Down Expand Up @@ -1328,6 +1345,7 @@ ThanosRulerSpec is a specification of the desired behavior of the ThanosRuler. M
| minReadySeconds | Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready) This is an alpha field and requires enabling StatefulSetMinReadySeconds feature gate. | *uint32 | false |
| alertRelabelConfigs | AlertRelabelConfigs configures alert relabeling in ThanosRuler. Alert relabel configurations must have the form as specified in the official Prometheus documentation: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alert_relabel_configs Alternative to AlertRelabelConfigFile, and lower order priority. | *[v1.SecretKeySelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#secretkeyselector-v1-core) | false |
| alertRelabelConfigFile | AlertRelabelConfigFile specifies the path of the alert relabeling configuration file. When used alongside with AlertRelabelConfigs, alertRelabelConfigFile takes precedence. | *string | false |
| hostAliases | Pods' hostAliases configuration | [][HostAlias](#hostalias) | false |

[Back to TOC](#table-of-contents)

Expand Down
66 changes: 66 additions & 0 deletions bundle.yaml
Expand Up @@ -6240,6 +6240,28 @@ spec:
Use case is e.g. spanning an Alertmanager cluster across Kubernetes
clusters with a single replica in each.
type: boolean
hostAliases:
description: Pods' hostAliases configuration
items:
description: HostAlias holds the mapping between IP and hostnames
that will be injected as an entry in the pod's hosts file.
properties:
hostnames:
description: Hostnames for the above IP address.
items:
type: string
type: array
ip:
description: IP address of the host file entry.
type: string
required:
- hostnames
- ip
type: object
type: array
x-kubernetes-list-map-keys:
- ip
x-kubernetes-list-type: map
image:
description: Image if specified has precedence over baseImage, tag
and sha combinations. Specifying the version is still necessary
Expand Down Expand Up @@ -14121,6 +14143,28 @@ spec:
under. This is necessary to generate correct URLs. This is necessary
if Prometheus is not served from root of a DNS name.
type: string
hostAliases:
description: Pods' hostAliases configuration
items:
description: HostAlias holds the mapping between IP and hostnames
that will be injected as an entry in the pod's hosts file.
properties:
hostnames:
description: Hostnames for the above IP address.
items:
type: string
type: array
ip:
description: IP address of the host file entry.
type: string
required:
- hostnames
- ip
type: object
type: array
x-kubernetes-list-map-keys:
- ip
x-kubernetes-list-type: map
ignoreNamespaceSelectors:
description: IgnoreNamespaceSelectors if set to true will ignore NamespaceSelector
settings from all PodMonitor, ServiceMonitor and Probe objects.
Expand Down Expand Up @@ -22888,6 +22932,28 @@ spec:
description: Used to verify the hostname for the targets.
type: string
type: object
hostAliases:
description: Pods' hostAliases configuration
items:
description: HostAlias holds the mapping between IP and hostnames
that will be injected as an entry in the pod's hosts file.
properties:
hostnames:
description: Hostnames for the above IP address.
items:
type: string
type: array
ip:
description: IP address of the host file entry.
type: string
required:
- hostnames
- ip
type: object
type: array
x-kubernetes-list-map-keys:
- ip
x-kubernetes-list-type: map
image:
description: Thanos container image URL.
type: string
Expand Down
Expand Up @@ -2258,6 +2258,28 @@ spec:
Use case is e.g. spanning an Alertmanager cluster across Kubernetes
clusters with a single replica in each.
type: boolean
hostAliases:
description: Pods' hostAliases configuration
items:
description: HostAlias holds the mapping between IP and hostnames
that will be injected as an entry in the pod's hosts file.
properties:
hostnames:
description: Hostnames for the above IP address.
items:
type: string
type: array
ip:
description: IP address of the host file entry.
type: string
required:
- hostnames
- ip
type: object
type: array
x-kubernetes-list-map-keys:
- ip
x-kubernetes-list-type: map
image:
description: Image if specified has precedence over baseImage, tag
and sha combinations. Specifying the version is still necessary
Expand Down
Expand Up @@ -2785,6 +2785,28 @@ spec:
under. This is necessary to generate correct URLs. This is necessary
if Prometheus is not served from root of a DNS name.
type: string
hostAliases:
description: Pods' hostAliases configuration
items:
description: HostAlias holds the mapping between IP and hostnames
that will be injected as an entry in the pod's hosts file.
properties:
hostnames:
description: Hostnames for the above IP address.
items:
type: string
type: array
ip:
description: IP address of the host file entry.
type: string
required:
- hostnames
- ip
type: object
type: array
x-kubernetes-list-map-keys:
- ip
x-kubernetes-list-type: map
ignoreNamespaceSelectors:
description: IgnoreNamespaceSelectors if set to true will ignore NamespaceSelector
settings from all PodMonitor, ServiceMonitor and Probe objects.
Expand Down
Expand Up @@ -2333,6 +2333,28 @@ spec:
description: Used to verify the hostname for the targets.
type: string
type: object
hostAliases:
description: Pods' hostAliases configuration
items:
description: HostAlias holds the mapping between IP and hostnames
that will be injected as an entry in the pod's hosts file.
properties:
hostnames:
description: Hostnames for the above IP address.
items:
type: string
type: array
ip:
description: IP address of the host file entry.
type: string
required:
- hostnames
- ip
type: object
type: array
x-kubernetes-list-map-keys:
- ip
x-kubernetes-list-type: map
image:
description: Thanos container image URL.
type: string
Expand Down
29 changes: 29 additions & 0 deletions jsonnet/prometheus-operator/alertmanagers-crd.json
Expand Up @@ -1974,6 +1974,35 @@
"description": "ForceEnableClusterMode ensures Alertmanager does not deactivate the cluster mode when running with a single replica. Use case is e.g. spanning an Alertmanager cluster across Kubernetes clusters with a single replica in each.",
"type": "boolean"
},
"hostAliases": {
"description": "Pods' hostAliases configuration",
"items": {
"description": "HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file.",
"properties": {
"hostnames": {
"description": "Hostnames for the above IP address.",
"items": {
"type": "string"
},
"type": "array"
},
"ip": {
"description": "IP address of the host file entry.",
"type": "string"
}
},
"required": [
"hostnames",
"ip"
],
"type": "object"
},
"type": "array",
"x-kubernetes-list-map-keys": [
"ip"
],
"x-kubernetes-list-type": "map"
},
"image": {
"description": "Image if specified has precedence over baseImage, tag and sha combinations. Specifying the version is still necessary to ensure the Prometheus Operator knows what version of Alertmanager is being configured.",
"type": "string"
Expand Down
29 changes: 29 additions & 0 deletions jsonnet/prometheus-operator/prometheuses-crd.json
Expand Up @@ -2516,6 +2516,35 @@
"description": "The external URL the Prometheus instances will be available under. This is necessary to generate correct URLs. This is necessary if Prometheus is not served from root of a DNS name.",
"type": "string"
},
"hostAliases": {
"description": "Pods' hostAliases configuration",
"items": {
"description": "HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file.",
"properties": {
"hostnames": {
"description": "Hostnames for the above IP address.",
"items": {
"type": "string"
},
"type": "array"
},
"ip": {
"description": "IP address of the host file entry.",
"type": "string"
}
},
"required": [
"hostnames",
"ip"
],
"type": "object"
},
"type": "array",
"x-kubernetes-list-map-keys": [
"ip"
],
"x-kubernetes-list-type": "map"
},
"ignoreNamespaceSelectors": {
"description": "IgnoreNamespaceSelectors if set to true will ignore NamespaceSelector settings from all PodMonitor, ServiceMonitor and Probe objects. They will only discover endpoints within their current namespace. Defaults to false.",
"type": "boolean"
Expand Down
29 changes: 29 additions & 0 deletions jsonnet/prometheus-operator/thanosrulers-crd.json
Expand Up @@ -2087,6 +2087,35 @@
},
"type": "object"
},
"hostAliases": {
"description": "Pods' hostAliases configuration",
"items": {
"description": "HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file.",
"properties": {
"hostnames": {
"description": "Hostnames for the above IP address.",
"items": {
"type": "string"
},
"type": "array"
},
"ip": {
"description": "IP address of the host file entry.",
"type": "string"
}
},
"required": [
"hostnames",
"ip"
],
"type": "object"
},
"type": "array",
"x-kubernetes-list-map-keys": [
"ip"
],
"x-kubernetes-list-type": "map"
},
"image": {
"description": "Thanos container image URL.",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions pkg/alertmanager/statefulset.go
Expand Up @@ -628,6 +628,7 @@ func makeStatefulSetSpec(a *monitoringv1.Alertmanager, config Config, tlsAssetSe
Tolerations: a.Spec.Tolerations,
Affinity: a.Spec.Affinity,
TopologySpreadConstraints: a.Spec.TopologySpreadConstraints,
HostAliases: k8sutil.HostAliasesMonitoringV1ToCoreV1(a.Spec.HostAliases),
},
},
}, nil
Expand Down

0 comments on commit df59cb0

Please sign in to comment.