mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
*: Ensure containers have "FallbackToLogsOnError" termination policy
This commit is contained in:
parent
04e46043b0
commit
395c1df715
4 changed files with 50 additions and 16 deletions
pkg
|
@ -503,6 +503,7 @@ func makeStatefulSetSpec(a *monitoringv1.Alertmanager, config Config) (*appsv1.S
|
|||
},
|
||||
},
|
||||
},
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
}, {
|
||||
Name: "config-reloader",
|
||||
Image: config.ConfigReloaderImage,
|
||||
|
@ -517,7 +518,8 @@ func makeStatefulSetSpec(a *monitoringv1.Alertmanager, config Config) (*appsv1.S
|
|||
MountPath: alertmanagerConfDir,
|
||||
},
|
||||
},
|
||||
Resources: resources,
|
||||
Resources: resources,
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
},
|
||||
}, a.Spec.Containers...),
|
||||
Volumes: volumes,
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
@ -527,3 +527,18 @@ func TestSidecarsNoMemoryLimits(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminationPolicy(t *testing.T) {
|
||||
sset, err := makeStatefulSet(&monitoringv1.Alertmanager{
|
||||
Spec: monitoringv1.AlertmanagerSpec{},
|
||||
}, nil, defaultTestConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error while making StatefulSet: %v", err)
|
||||
}
|
||||
|
||||
for _, c := range sset.Spec.Template.Spec.Containers {
|
||||
if c.TerminationMessagePolicy != v1.TerminationMessageFallbackToLogsOnError {
|
||||
t.Fatalf("Unexpected TermintationMessagePolicy. Expected %v got %v", v1.TerminationMessageFallbackToLogsOnError, c.TerminationMessagePolicy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -711,8 +711,9 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
|
|||
Args: []string{
|
||||
fmt.Sprintf("--webhook-url=%s", localReloadURL),
|
||||
},
|
||||
VolumeMounts: []v1.VolumeMount{},
|
||||
Resources: v1.ResourceRequirements{Limits: v1.ResourceList{}},
|
||||
VolumeMounts: []v1.VolumeMount{},
|
||||
Resources: v1.ResourceRequirements{Limits: v1.ResourceList{}},
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
}
|
||||
|
||||
if c.ConfigReloaderCPU != "0" {
|
||||
|
@ -759,8 +760,9 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
|
|||
}
|
||||
|
||||
container := v1.Container{
|
||||
Name: "thanos-sidecar",
|
||||
Image: thanosImage,
|
||||
Name: "thanos-sidecar",
|
||||
Image: thanosImage,
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
Args: []string{
|
||||
"sidecar",
|
||||
fmt.Sprintf("--prometheus.url=http://%s:9090%s", c.LocalHost, path.Clean(webRoutePrefix)),
|
||||
|
@ -844,17 +846,19 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
|
|||
|
||||
operatorContainers := append([]v1.Container{
|
||||
{
|
||||
Name: "prometheus",
|
||||
Image: prometheusImage,
|
||||
Ports: ports,
|
||||
Args: promArgs,
|
||||
VolumeMounts: promVolumeMounts,
|
||||
LivenessProbe: livenessProbe,
|
||||
ReadinessProbe: readinessProbe,
|
||||
Resources: p.Spec.Resources,
|
||||
Name: "prometheus",
|
||||
Image: prometheusImage,
|
||||
Ports: ports,
|
||||
Args: promArgs,
|
||||
VolumeMounts: promVolumeMounts,
|
||||
LivenessProbe: livenessProbe,
|
||||
ReadinessProbe: readinessProbe,
|
||||
Resources: p.Spec.Resources,
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
}, {
|
||||
Name: "prometheus-config-reloader",
|
||||
Image: c.PrometheusConfigReloaderImage,
|
||||
Name: "prometheus-config-reloader",
|
||||
Image: c.PrometheusConfigReloaderImage,
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
Name: "POD_NAME",
|
||||
|
|
|
@ -921,3 +921,16 @@ func TestThanosListenLocal(t *testing.T) {
|
|||
t.Fatal("Thanos not listening on loopback when it should.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminationPolicy(t *testing.T) {
|
||||
sset, err := makeStatefulSet(monitoringv1.Prometheus{Spec: monitoringv1.PrometheusSpec{}}, defaultTestConfig, nil, "")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error while making StatefulSet: %v", err)
|
||||
}
|
||||
|
||||
for _, c := range sset.Spec.Template.Spec.Containers {
|
||||
if c.TerminationMessagePolicy != v1.TerminationMessageFallbackToLogsOnError {
|
||||
t.Fatalf("Unexpected TermintationMessagePolicy. Expected %v got %v", v1.TerminationMessageFallbackToLogsOnError, c.TerminationMessagePolicy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue