Skip to content

Commit

Permalink
statefulsets are updated during each sync even if no changes to the c…
Browse files Browse the repository at this point in the history
…onfig (#2308) (#2325)
  • Loading branch information
sre-bot committed Apr 28, 2020
1 parent c62bbd8 commit 3b3fa82
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/manager/member/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ func GetLastAppliedConfig(set *apps.StatefulSet) (*apps.StatefulSetSpec, *corev1

// statefulSetEqual compares the new Statefulset's spec with old Statefulset's last applied config
func statefulSetEqual(new apps.StatefulSet, old apps.StatefulSet) bool {
if !apiequality.Semantic.DeepEqual(new.Annotations, old.Annotations) {
// The annotations in old sts may include LastAppliedConfigAnnotation
tmpAnno := map[string]string{}
for k, v := range old.Annotations {
if k != LastAppliedConfigAnnotation {
tmpAnno[k] = v
}
}
if !apiequality.Semantic.DeepEqual(new.Annotations, tmpAnno) {
return false
}
oldConfig := apps.StatefulSetSpec{}
Expand All @@ -110,8 +117,12 @@ func statefulSetEqual(new apps.StatefulSet, old apps.StatefulSet) bool {
klog.Errorf("unmarshal Statefulset: [%s/%s]'s applied config failed,error: %v", old.GetNamespace(), old.GetName(), err)
return false
}
// oldConfig.Template.Annotations may include LastAppliedConfigAnnotation to keep backward compatiability
// Please check detail in https://github.com/pingcap/tidb-operator/pull/1489
tmpTemplate := oldConfig.Template.DeepCopy()
delete(tmpTemplate.Annotations, LastAppliedConfigAnnotation)
return apiequality.Semantic.DeepEqual(oldConfig.Replicas, new.Spec.Replicas) &&
apiequality.Semantic.DeepEqual(oldConfig.Template, new.Spec.Template) &&
apiequality.Semantic.DeepEqual(*tmpTemplate, new.Spec.Template) &&
apiequality.Semantic.DeepEqual(oldConfig.UpdateStrategy, new.Spec.UpdateStrategy)
}
return false
Expand Down

0 comments on commit 3b3fa82

Please sign in to comment.