1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

*: Add ability to mount custom ConfigMaps

This commit is contained in:
Frederic Branczyk 2018-10-18 15:03:47 +02:00
parent 461d463aab
commit a6cb9dec6d
No known key found for this signature in database
GPG key ID: 7741A52782A90069
11 changed files with 107 additions and 13 deletions

View file

@ -118,6 +118,7 @@ AlertmanagerSpec is a specification of the desired behavior of the Alertmanager
| baseImage | Base image that is used to deploy pods, without tag. | string | false |
| imagePullSecrets | An optional list of references to secrets in the same namespace to use for pulling prometheus and alertmanager images from registries see http://kubernetes.io/docs/user-guide/images#specifying-imagepullsecrets-on-a-pod | [][v1.LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#localobjectreference-v1-core) | false |
| secrets | Secrets is a list of Secrets in the same namespace as the Alertmanager object, which shall be mounted into the Alertmanager Pods. The Secrets are mounted into /etc/alertmanager/secrets/<secret-name>. | []string | false |
| configMaps | ConfigMaps is a list of ConfigMaps in the same namespace as the Alertmanager object, which shall be mounted into the Alertmanager Pods. The ConfigMaps are mounted into /etc/alertmanager/configmaps/<configmap-name>. | []string | false |
| logLevel | Log level for Alertmanager to be configured with. | string | false |
| replicas | Size is the expected size of the alertmanager cluster. The controller will eventually make the size of the running cluster equal to the expected size. | *int32 | false |
| retention | Time duration Alertmanager shall retain data for. Default is '120h', and must match the regular expression `[0-9]+(ms\|s\|m\|h\|d\|w\|y)` (milliseconds seconds minutes hours days weeks years). | string | false |
@ -282,7 +283,8 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus
| resources | Define resources requests and limits for single Pods. | [v1.ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#resourcerequirements-v1-core) | false |
| nodeSelector | Define which Nodes the Pods are scheduled on. | map[string]string | false |
| serviceAccountName | ServiceAccountName is the name of the ServiceAccount to use to run the Prometheus Pods. | string | false |
| secrets | Secrets is a list of Secrets in the same namespace as the Prometheus object, which shall be mounted into the Prometheus Pods. The Secrets are mounted into /etc/prometheus/secrets/<secret-name>. Secrets changes after initial creation of a Prometheus object are not reflected in the running Pods. To change the secrets mounted into the Prometheus Pods, the object must be deleted and recreated with the new list of secrets. | []string | false |
| secrets | Secrets is a list of Secrets in the same namespace as the Prometheus object, which shall be mounted into the Prometheus Pods. The Secrets are mounted into /etc/prometheus/secrets/<secret-name>. | []string | false |
| configMaps | ConfigMaps is a list of ConfigMaps in the same namespace as the Prometheus object, which shall be mounted into the Prometheus Pods. The ConfigMaps are mounted into /etc/prometheus/configmaps/<configmap-name>. | []string | false |
| affinity | If specified, the pod's scheduling constraints. | *v1.Affinity | false |
| tolerations | If specified, the pod's tolerations. | []v1.Toleration | false |
| remoteWrite | If specified, the remote_write spec. This is an experimental feature, it may change in any upcoming release in a breaking way. | [][RemoteWriteSpec](#remotewritespec) | false |

View file

@ -594,6 +594,13 @@ spec:
baseImage:
description: Base image that is used to deploy pods, without tag.
type: string
configMaps:
description: ConfigMaps is a list of ConfigMaps in the same namespace
as the Alertmanager object, which shall be mounted into the Alertmanager
Pods. The ConfigMaps are mounted into /etc/alertmanager/configmaps/<configmap-name>.
items:
type: string
type: array
containers:
description: Containers allows injecting additional containers. This
is meant to allow adding an authentication proxy to an Alertmanager

View file

@ -760,6 +760,13 @@ spec:
baseImage:
description: Base image to use for a Prometheus deployment.
type: string
configMaps:
description: ConfigMaps is a list of ConfigMaps in the same namespace
as the Prometheus object, which shall be mounted into the Prometheus
Pods. The ConfigMaps are mounted into /etc/prometheus/configmaps/<configmap-name>.
items:
type: string
type: array
containers:
description: Containers allows injecting additional containers. This
is meant to allow adding an authentication proxy to a Prometheus pod.
@ -2223,10 +2230,6 @@ spec:
description: Secrets is a list of Secrets in the same namespace as the
Prometheus object, which shall be mounted into the Prometheus Pods.
The Secrets are mounted into /etc/prometheus/secrets/<secret-name>.
Secrets changes after initial creation of a Prometheus object are
not reflected in the running Pods. To change the secrets mounted into
the Prometheus Pods, the object must be deleted and recreated with
the new list of secrets.
items:
type: string
type: array

View file

@ -17,8 +17,9 @@ if hash getenforce 2> /dev/null && getenforce | grep 'Enforcing' > /dev/null; th
VOLUME_OPTIONS=":Z"
fi
# shellcheck disable=SC2068
docker run \
--rm \
-u="$(id -u "$USER")":"$(id -g "$USER")" \
-v "${SCRIPTDIR}/..:/go/src/github.com/coreos/prometheus-operator${VOLUME_OPTIONS}" \
po-jsonnet make "${MFLAGS[@]}" generate
po-jsonnet make ${MFLAGS[@]} generate

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -37,6 +37,7 @@ const (
defaultVersion = "v0.15.2"
defaultRetention = "120h"
secretsDir = "/etc/alertmanager/secrets/"
configmapsDir = "/etc/alertmanager/configmaps/"
alertmanagerConfDir = "/etc/alertmanager/config"
alertmanagerConfFile = alertmanagerConfDir + "/alertmanager.yaml"
alertmanagerStorageDir = "/alertmanager"
@ -367,6 +368,7 @@ func makeStatefulSetSpec(a *monitoringv1.Alertmanager, config Config) (*appsv1.S
SubPath: subPathForStorage(a.Spec.Storage),
},
}
for _, s := range a.Spec.Secrets {
volumes = append(volumes, v1.Volume{
Name: k8sutil.SanitizeVolumeName("secret-" + s),
@ -383,6 +385,24 @@ func makeStatefulSetSpec(a *monitoringv1.Alertmanager, config Config) (*appsv1.S
})
}
for _, c := range a.Spec.ConfigMaps {
volumes = append(volumes, v1.Volume{
Name: k8sutil.SanitizeVolumeName("configmap-" + c),
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Name: c,
},
},
},
})
amVolumeMounts = append(amVolumeMounts, v1.VolumeMount{
Name: k8sutil.SanitizeVolumeName("configmap-" + c),
ReadOnly: true,
MountPath: configmapsDir + c,
})
}
terminationGracePeriod := int64(0)
finalLabels := config.Labels.Merge(podLabels)
return &appsv1.StatefulSetSpec{

View file

@ -589,6 +589,20 @@ func schema_pkg_client_monitoring_v1_AlertmanagerSpec(ref common.ReferenceCallba
},
},
},
"configMaps": {
SchemaProps: spec.SchemaProps{
Description: "ConfigMaps is a list of ConfigMaps in the same namespace as the Alertmanager object, which shall be mounted into the Alertmanager Pods. The ConfigMaps are mounted into /etc/alertmanager/configmaps/<configmap-name>.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
},
},
},
"logLevel": {
SchemaProps: spec.SchemaProps{
Description: "Log level for Alertmanager to be configured with.",
@ -1375,7 +1389,21 @@ func schema_pkg_client_monitoring_v1_PrometheusSpec(ref common.ReferenceCallback
},
"secrets": {
SchemaProps: spec.SchemaProps{
Description: "Secrets is a list of Secrets in the same namespace as the Prometheus object, which shall be mounted into the Prometheus Pods. The Secrets are mounted into /etc/prometheus/secrets/<secret-name>. Secrets changes after initial creation of a Prometheus object are not reflected in the running Pods. To change the secrets mounted into the Prometheus Pods, the object must be deleted and recreated with the new list of secrets.",
Description: "Secrets is a list of Secrets in the same namespace as the Prometheus object, which shall be mounted into the Prometheus Pods. The Secrets are mounted into /etc/prometheus/secrets/<secret-name>.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
},
},
},
"configMaps": {
SchemaProps: spec.SchemaProps{
Description: "ConfigMaps is a list of ConfigMaps in the same namespace as the Prometheus object, which shall be mounted into the Prometheus Pods. The ConfigMaps are mounted into /etc/prometheus/configmaps/<configmap-name>.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{

View file

@ -127,11 +127,11 @@ type PrometheusSpec struct {
// Secrets is a list of Secrets in the same namespace as the Prometheus
// object, which shall be mounted into the Prometheus Pods.
// The Secrets are mounted into /etc/prometheus/secrets/<secret-name>.
// Secrets changes after initial creation of a Prometheus object are not
// reflected in the running Pods. To change the secrets mounted into the
// Prometheus Pods, the object must be deleted and recreated with the new list
// of secrets.
Secrets []string `json:"secrets,omitempty"`
// ConfigMaps is a list of ConfigMaps in the same namespace as the Prometheus
// object, which shall be mounted into the Prometheus Pods.
// The ConfigMaps are mounted into /etc/prometheus/configmaps/<configmap-name>.
ConfigMaps []string `json:"configMaps,omitempty"`
// If specified, the pod's scheduling constraints.
Affinity *v1.Affinity `json:"affinity,omitempty"`
// If specified, the pod's tolerations.
@ -641,6 +641,10 @@ type AlertmanagerSpec struct {
// object, which shall be mounted into the Alertmanager Pods.
// The Secrets are mounted into /etc/alertmanager/secrets/<secret-name>.
Secrets []string `json:"secrets,omitempty"`
// ConfigMaps is a list of ConfigMaps in the same namespace as the Alertmanager
// object, which shall be mounted into the Alertmanager Pods.
// The ConfigMaps are mounted into /etc/alertmanager/configmaps/<configmap-name>.
ConfigMaps []string `json:"configMaps,omitempty"`
// Log level for Alertmanager to be configured with.
LogLevel string `json:"logLevel,omitempty"`
// Size is the expected size of the alertmanager cluster. The controller will

View file

@ -182,6 +182,11 @@ func (in *AlertmanagerSpec) DeepCopyInto(out *AlertmanagerSpec) {
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.ConfigMaps != nil {
in, out := &in.ConfigMaps, &out.ConfigMaps
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Replicas != nil {
in, out := &in.Replicas, &out.Replicas
if *in == nil {
@ -667,6 +672,11 @@ func (in *PrometheusSpec) DeepCopyInto(out *PrometheusSpec) {
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.ConfigMaps != nil {
in, out := &in.ConfigMaps, &out.ConfigMaps
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Affinity != nil {
in, out := &in.Affinity, &out.Affinity
if *in == nil {

View file

@ -42,6 +42,7 @@ const (
confOutDir = "/etc/prometheus/config_out"
rulesDir = "/etc/prometheus/rules"
secretsDir = "/etc/prometheus/secrets/"
configmapsDir = "/etc/prometheus/configmaps/"
configFilename = "prometheus.yaml"
configEnvsubstFilename = "prometheus.env.yaml"
sSetInputHashName = "prometheus-operator-input-hash"
@ -467,6 +468,24 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
})
}
for _, c := range p.Spec.ConfigMaps {
volumes = append(volumes, v1.Volume{
Name: k8sutil.SanitizeVolumeName("configmap-" + c),
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Name: c,
},
},
},
})
promVolumeMounts = append(promVolumeMounts, v1.VolumeMount{
Name: k8sutil.SanitizeVolumeName("configmap-" + c),
ReadOnly: true,
MountPath: configmapsDir + c,
})
}
configReloadVolumeMounts := []v1.VolumeMount{
{
Name: "config",