Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statefulsets are updated during each sync even if no changes to the config #2308

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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