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

refactor: decouple pod labels from selector labels ()

* refactor: decouple pod labels from selector labels

prometheus pods can not be rolled out without downtime when label's are changed

Fixes 

* chore: run go fmt

* fix unit tests
This commit is contained in:
Miklós Kiss 2020-06-25 10:41:17 +02:00 committed by GitHub
parent ca324956d4
commit 45de764e39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View file

@ -657,6 +657,10 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
podAnnotations := map[string]string{}
podLabels := map[string]string{}
podSelectorLabels := map[string]string{
"app": "prometheus",
"prometheus": p.Name,
}
if p.Spec.PodMetadata != nil {
if p.Spec.PodMetadata.Labels != nil {
for k, v := range p.Spec.PodMetadata.Labels {
@ -670,9 +674,11 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
}
}
podLabels["app"] = "prometheus"
podLabels["prometheus"] = p.Name
for k, v := range podSelectorLabels {
podLabels[k] = v
}
finalSelectorLabels := c.Labels.Merge(podSelectorLabels)
finalLabels := c.Labels.Merge(podLabels)
var additionalContainers []v1.Container
@ -904,7 +910,7 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
Type: appsv1.RollingUpdateStatefulSetStrategyType,
},
Selector: &metav1.LabelSelector{
MatchLabels: finalLabels,
MatchLabels: finalSelectorLabels,
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{

View file

@ -101,6 +101,25 @@ func TestPodLabelsAnnotations(t *testing.T) {
t.Fatal("Pod annotaitons are not properly propagated")
}
}
func TestPodLabelsShouldNotBeSelectorLabels(t *testing.T) {
labels := map[string]string{
"testlabel": "testvalue",
}
sset, err := makeStatefulSet(monitoringv1.Prometheus{
ObjectMeta: metav1.ObjectMeta{},
Spec: monitoringv1.PrometheusSpec{
PodMetadata: &monitoringv1.EmbeddedObjectMetadata{
Labels: labels,
},
},
}, defaultTestConfig, nil, "")
require.NoError(t, err)
if sset.Spec.Selector.MatchLabels["testlabel"] == "testvalue" {
t.Fatal("Pod Selector are not properly propagated")
}
}
func TestStatefulSetPVC(t *testing.T) {
labels := map[string]string{