Skip to content

Commit

Permalink
prevent prometheus sts update loop
Browse files Browse the repository at this point in the history
Changes in kubernetes v1.17 cause an endless update loop due
to validation errors cause by setting the 'apiVersion' and
'kind' fields in the StatefulSet spec.  These two fields are
set to empty strings by the Kube API server, and v1.17 added
validation that does not allow these fields to be modified.

See prometheus-operator#2950
  • Loading branch information
pgier committed Jan 29, 2020
1 parent 67dca66 commit 835dfeb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/prometheus/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ func (c *Operator) sync(key string) error {
if err != nil {
return errors.Wrap(err, "making statefulset failed")
}
sanitizeSTS(sset)

if !exists {
level.Debug(c.logger).Log("msg", "no current Prometheus statefulset found")
Expand Down Expand Up @@ -1183,6 +1184,15 @@ func (c *Operator) sync(key string) error {
return nil
}

// sanitizeSTS removes values for APIVersion and Kind from the VolumeClaimTemplates.
// This prevents update failures due to these fields changing when applied.
func sanitizeSTS(sts *appsv1.StatefulSet) {
for i := range sts.Spec.VolumeClaimTemplates {
sts.Spec.VolumeClaimTemplates[i].APIVersion = ""
sts.Spec.VolumeClaimTemplates[i].Kind = ""
}
}

//checkPrometheusSpecDeprecation checks for deprecated fields in the prometheus spec and logs a warning if applicable
func checkPrometheusSpecDeprecation(key string, p *monitoringv1.Prometheus, logger log.Logger) {
deprecationWarningf := "prometheus key=%v, field %v is deprecated, '%v' field should be used instead"
Expand Down

0 comments on commit 835dfeb

Please sign in to comment.