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

Allow passing in custom resource constraint

This adds a resource constraint which is set for the Prometheus
container. We also add standard limits for the config reloader
container.
This commit is contained in:
Fabian Reinartz 2016-11-14 14:32:40 +01:00
parent 0e6ed12026
commit 4a0755e292
3 changed files with 29 additions and 27 deletions

View file

@ -418,12 +418,12 @@ func (c *Operator) reconcile(p *spec.Prometheus) error {
}
if !exists {
if _, err := psetClient.Create(makePetSet(p, nil, am)); err != nil {
if _, err := psetClient.Create(makePetSet(*p, nil, am)); err != nil {
return fmt.Errorf("create petset: %s", err)
}
return nil
}
if _, err := psetClient.Update(makePetSet(p, obj.(*v1alpha1.PetSet), am)); err != nil {
if _, err := psetClient.Update(makePetSet(*p, obj.(*v1alpha1.PetSet), am)); err != nil {
return err
}

View file

@ -19,39 +19,35 @@ import (
"strings"
"github.com/coreos/prometheus-operator/pkg/spec"
"k8s.io/client-go/1.5/pkg/api/resource"
"k8s.io/client-go/1.5/pkg/api/v1"
"k8s.io/client-go/1.5/pkg/apis/apps/v1alpha1"
"k8s.io/client-go/1.5/pkg/util/intstr"
)
func makePetSet(p *spec.Prometheus, old *v1alpha1.PetSet, alertmanagers []string) *v1alpha1.PetSet {
func makePetSet(p spec.Prometheus, old *v1alpha1.PetSet, alertmanagers []string) *v1alpha1.PetSet {
// TODO(fabxc): is this the right point to inject defaults?
// Ideally we would do it before storing but that's currently not possible.
// Potentially an update handler on first insertion.
baseImage := p.Spec.BaseImage
if baseImage == "" {
baseImage = "quay.io/prometheus/prometheus"
if p.Spec.BaseImage == "" {
p.Spec.BaseImage = "quay.io/prometheus/prometheus"
}
version := p.Spec.Version
if version == "" {
version = "v1.3.0"
if p.Spec.Version == "" {
p.Spec.Version = "v1.3.0"
}
replicas := p.Spec.Replicas
if replicas < 1 {
replicas = 1
if p.Spec.Replicas < 1 {
p.Spec.Replicas = 1
}
retention := p.Spec.Retention
if retention == "" {
retention = "24h"
if p.Spec.Retention == "" {
p.Spec.Retention = "24h"
}
image := fmt.Sprintf("%s:%s", baseImage, version)
petset := &v1alpha1.PetSet{
ObjectMeta: v1.ObjectMeta{
Name: p.Name,
},
Spec: makePetSetSpec(p.Name, image, version, retention, replicas, alertmanagers),
Spec: makePetSetSpec(p, alertmanagers),
}
if vc := p.Spec.Storage; vc == nil {
petset.Spec.Template.Spec.Volumes = append(petset.Spec.Template.Spec.Volumes, v1.Volume{
@ -126,19 +122,19 @@ func makePetSetService(p *spec.Prometheus) *v1.Service {
return svc
}
func makePetSetSpec(name, image, version, retention string, replicas int32, alertmanagers []string) v1alpha1.PetSetSpec {
func makePetSetSpec(p spec.Prometheus, alertmanagers []string) v1alpha1.PetSetSpec {
// Prometheus may take quite long to shut down to checkpoint existing data.
// Allow up to 10 minutes for clean termination.
terminationGracePeriod := int64(600)
return v1alpha1.PetSetSpec{
ServiceName: "prometheus",
Replicas: &replicas,
Replicas: &p.Spec.Replicas,
Template: v1.PodTemplateSpec{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"app": "prometheus",
"prometheus": name,
"prometheus": p.Name,
},
Annotations: map[string]string{
"pod.alpha.kubernetes.io/initialized": "true",
@ -148,7 +144,7 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
Containers: []v1.Container{
{
Name: "prometheus",
Image: image,
Image: fmt.Sprintf("%s:%s", p.Spec.BaseImage, p.Spec.Version),
Ports: []v1.ContainerPort{
{
Name: "web",
@ -157,7 +153,7 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
},
},
Args: []string{
"-storage.local.retention=" + retention,
"-storage.local.retention=" + p.Spec.Retention,
"-storage.local.memory-chunks=500000",
"-storage.local.path=/var/prometheus/data",
"-config.file=/etc/prometheus/config/prometheus.yaml",
@ -175,7 +171,7 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
MountPath: "/etc/prometheus/rules",
},
{
Name: fmt.Sprintf("%s-db", name),
Name: fmt.Sprintf("%s-db", p.Name),
MountPath: "/var/prometheus/data",
SubPath: "prometheus-db",
},
@ -194,6 +190,7 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
// Wait up to 5 minutes.
FailureThreshold: 100,
},
Resources: p.Spec.Resources,
}, {
Name: "config-reloader",
Image: "jimmidyson/configmap-reload",
@ -208,6 +205,12 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
MountPath: "/etc/prometheus/config",
},
},
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
"cpu": resource.MustParse("5m"),
"memory": resource.MustParse("5Mi"),
},
},
}, {
Name: "rules-reloader",
Image: "jimmidyson/configmap-reload",
@ -231,7 +234,7 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
Name: p.Name,
},
},
},
@ -241,7 +244,7 @@ func makePetSetSpec(name, image, version, retention string, replicas int32, aler
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Name: fmt.Sprintf("%s-rules", name),
Name: fmt.Sprintf("%s-rules", p.Name),
},
},
},

View file

@ -45,8 +45,7 @@ type PrometheusSpec struct {
Retention string `json:"retention"`
Storage *StorageSpec `json:"storage"`
Alerting AlertingSpec `json:"alerting"`
// Replicas int `json:"replicas"`
// Resources apiV1.ResourceRequirements `json:"resources"`
Resources v1.ResourceRequirements `json:"resources"`
// Alerting AlertingSpec `json:"alerting"`
// Remote RemoteSpec `json:"remote"`
// Persistence...