mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
*: convert replicas field to pointer
This commit is contained in:
parent
fe13876acf
commit
c1ee759b9b
7 changed files with 33 additions and 19 deletions
pkg
alertmanager
client/monitoring/v1alpha1
prometheus
test/e2e/framework
|
@ -400,7 +400,11 @@ func (c *Operator) syncVersion(a *v1alpha1.Alertmanager) error {
|
|||
|
||||
// If the StatefulSet is still busy scaling, don't interfere by killing pods.
|
||||
// We enqueue ourselves again to until the StatefulSet is ready.
|
||||
if status.Replicas != a.Spec.Replicas {
|
||||
expectedReplicas := int32(1)
|
||||
if a.Spec.Replicas != nil {
|
||||
expectedReplicas = *a.Spec.Replicas
|
||||
}
|
||||
if status.Replicas != expectedReplicas {
|
||||
return fmt.Errorf("scaling in progress")
|
||||
}
|
||||
if status.Replicas == 0 {
|
||||
|
|
|
@ -32,7 +32,10 @@ const (
|
|||
governingServiceName = "alertmanager-operated"
|
||||
defaultBaseImage = "quay.io/prometheus/alertmanager"
|
||||
defaultVersion = "v0.5.1"
|
||||
minReplicas = 1
|
||||
)
|
||||
|
||||
var (
|
||||
minReplicas int32 = 1
|
||||
)
|
||||
|
||||
func makeStatefulSet(am *v1alpha1.Alertmanager, old *v1beta1.StatefulSet, config Config) *v1beta1.StatefulSet {
|
||||
|
@ -46,8 +49,8 @@ func makeStatefulSet(am *v1alpha1.Alertmanager, old *v1beta1.StatefulSet, config
|
|||
if am.Spec.Version == "" {
|
||||
am.Spec.Version = defaultVersion
|
||||
}
|
||||
if am.Spec.Replicas < minReplicas {
|
||||
am.Spec.Replicas = minReplicas
|
||||
if am.Spec.Replicas != nil && *am.Spec.Replicas < minReplicas {
|
||||
am.Spec.Replicas = &minReplicas
|
||||
}
|
||||
|
||||
statefulset := &v1beta1.StatefulSet{
|
||||
|
@ -148,14 +151,14 @@ func makeStatefulSetSpec(a *v1alpha1.Alertmanager, config Config) v1beta1.Statef
|
|||
Path: path.Clean(webRoutePrefix + "/-/reload"),
|
||||
}
|
||||
|
||||
for i := int32(0); i < a.Spec.Replicas; i++ {
|
||||
for i := int32(0); i < *a.Spec.Replicas; i++ {
|
||||
commands = append(commands, fmt.Sprintf("-mesh.peer=%s-%d.%s.%s.svc", prefixedName(a.Name), i, "alertmanager", a.Namespace))
|
||||
}
|
||||
|
||||
terminationGracePeriod := int64(0)
|
||||
return v1beta1.StatefulSetSpec{
|
||||
ServiceName: governingServiceName,
|
||||
Replicas: &a.Spec.Replicas,
|
||||
Replicas: a.Spec.Replicas,
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: apimetav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
|
|
|
@ -48,7 +48,7 @@ type PrometheusSpec struct {
|
|||
// Base image to use for a Prometheus deployment.
|
||||
BaseImage string `json:"baseImage,omitempty"`
|
||||
// Number of instances to deploy for a Prometheus deployment.
|
||||
Replicas int32 `json:"replicas,omitempty"`
|
||||
Replicas *int32 `json:"replicas,omitempty"`
|
||||
// Time duration Prometheus shall retain data for.
|
||||
Retention string `json:"retention,omitempty"`
|
||||
// The external URL the Prometheus instances will be available under. This is
|
||||
|
@ -198,7 +198,7 @@ type AlertmanagerSpec struct {
|
|||
// 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.
|
||||
Replicas int32 `json:"replicas,omitempty"`
|
||||
Replicas *int32 `json:"replicas,omitempty"`
|
||||
// Storage is the definition of how storage will be used by the Alertmanager
|
||||
// instances.
|
||||
Storage *StorageSpec `json:"storage,omitempty"`
|
||||
|
|
|
@ -604,7 +604,11 @@ func (c *Operator) syncVersion(key string, p *v1alpha1.Prometheus) error {
|
|||
|
||||
// If the StatefulSet is still busy scaling, don't interfere by killing pods.
|
||||
// We enqueue ourselves again to until the StatefulSet is ready.
|
||||
if status.Replicas != p.Spec.Replicas {
|
||||
expectedReplicas := int32(1)
|
||||
if p.Spec.Replicas != nil {
|
||||
expectedReplicas = *p.Spec.Replicas
|
||||
}
|
||||
if status.Replicas != expectedReplicas {
|
||||
return fmt.Errorf("scaling in progress")
|
||||
}
|
||||
if status.Replicas == 0 {
|
||||
|
|
|
@ -32,10 +32,13 @@ const (
|
|||
governingServiceName = "prometheus-operated"
|
||||
defaultBaseImage = "quay.io/prometheus/prometheus"
|
||||
defaultVersion = "v1.5.2"
|
||||
minReplicas = 1
|
||||
defaultRetention = "24h"
|
||||
)
|
||||
|
||||
var (
|
||||
minReplicas int32 = 1
|
||||
)
|
||||
|
||||
func makeStatefulSet(p v1alpha1.Prometheus, old *v1beta1.StatefulSet, config *Config) *v1beta1.StatefulSet {
|
||||
// TODO(fabxc): is this the right point to inject defaults?
|
||||
// Ideally we would do it before storing but that's currently not possible.
|
||||
|
@ -47,8 +50,8 @@ func makeStatefulSet(p v1alpha1.Prometheus, old *v1beta1.StatefulSet, config *Co
|
|||
if p.Spec.Version == "" {
|
||||
p.Spec.Version = defaultVersion
|
||||
}
|
||||
if p.Spec.Replicas < minReplicas {
|
||||
p.Spec.Replicas = minReplicas
|
||||
if p.Spec.Replicas != nil && *p.Spec.Replicas < minReplicas {
|
||||
p.Spec.Replicas = &minReplicas
|
||||
}
|
||||
if p.Spec.Retention == "" {
|
||||
p.Spec.Retention = defaultRetention
|
||||
|
@ -193,7 +196,7 @@ func makeStatefulSetSpec(p v1alpha1.Prometheus, c *Config) v1beta1.StatefulSetSp
|
|||
|
||||
return v1beta1.StatefulSetSpec{
|
||||
ServiceName: governingServiceName,
|
||||
Replicas: &p.Spec.Replicas,
|
||||
Replicas: p.Spec.Replicas,
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: apimetav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
|
|
|
@ -47,7 +47,7 @@ func (f *Framework) MakeBasicAlertmanager(name string, replicas int32) *v1alpha1
|
|||
Name: name,
|
||||
},
|
||||
Spec: v1alpha1.AlertmanagerSpec{
|
||||
Replicas: replicas,
|
||||
Replicas: &replicas,
|
||||
Version: "v0.5.0",
|
||||
},
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func (f *Framework) CreateAlertmanagerAndWaitUntilReady(a *v1alpha1.Alertmanager
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(a.Spec.Replicas), amImage(a.Spec.Version), alertmanager.ListOptions(a.Name))
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(*a.Spec.Replicas), amImage(a.Spec.Version), alertmanager.ListOptions(a.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create an Alertmanager cluster (%s) with %d instances: %v", a.Name, a.Spec.Replicas, err)
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ func (f *Framework) UpdateAlertmanagerAndWaitUntilReady(a *v1alpha1.Alertmanager
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(a.Spec.Replicas), amImage(a.Spec.Version), alertmanager.ListOptions(a.Name))
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(*a.Spec.Replicas), amImage(a.Spec.Version), alertmanager.ListOptions(a.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update %d Alertmanager instances (%s): %v", a.Spec.Replicas, a.Name, err)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (f *Framework) MakeBasicPrometheus(name, group string, replicas int32) *v1a
|
|||
Name: name,
|
||||
},
|
||||
Spec: v1alpha1.PrometheusSpec{
|
||||
Replicas: replicas,
|
||||
Replicas: &replicas,
|
||||
Version: "v1.4.0",
|
||||
ServiceMonitorSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
|
@ -124,7 +124,7 @@ func (f *Framework) CreatePrometheusAndWaitUntilReady(p *v1alpha1.Prometheus) er
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(p.Spec.Replicas), promImage(p.Spec.Version), prometheus.ListOptions(p.Name))
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(*p.Spec.Replicas), promImage(p.Spec.Version), prometheus.ListOptions(p.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create %d Prometheus instances (%s): %v", p.Spec.Replicas, p.Name, err)
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func (f *Framework) UpdatePrometheusAndWaitUntilReady(p *v1alpha1.Prometheus) er
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(p.Spec.Replicas), promImage(p.Spec.Version), prometheus.ListOptions(p.Name))
|
||||
_, err = f.WaitForPodsReady(time.Minute*6, int(*p.Spec.Replicas), promImage(p.Spec.Version), prometheus.ListOptions(p.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update %d Prometheus instances (%s): %v", p.Spec.Replicas, p.Name, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue