-
Notifications
You must be signed in to change notification settings - Fork 488
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
Fix(volume): fix unexpected pod restart during resize storage size #5602
Merged
ti-chi-bot
merged 12 commits into
pingcap:master
from
ideascf:fix-unexpected-restart-during-resizing-storage-size
Apr 7, 2024
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
45f8f57
Fix(volume): fix unexpected pod restart during resize storage size
ideascf 4962229
address comment
ideascf 1ea0ffd
fix
ideascf ab80380
fix
ideascf 7b7b832
fix test
ideascf b60fe8f
fix test
ideascf fcb5cb0
Merge branch 'master' into fix-unexpected-restart-during-resizing-sto…
ideascf 10f0c5b
fix creating asts failed
ideascf c18c6ee
opt name
ideascf cf7b7fe
Merge branch 'master' into fix-unexpected-restart-during-resizing-sto…
ideascf 96cffc8
Merge branch 'master' into fix-unexpected-restart-during-resizing-sto…
csuzhangxc f50b3c4
Merge branch 'master' into fix-unexpected-restart-during-resizing-sto…
ideascf File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,12 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/pingcap/tidb-operator/pkg/apis/label" | ||
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/equality" | ||
corelisters "k8s.io/client-go/listers/core/v1" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func AddConfigMapDigestSuffix(cm *corev1.ConfigMap) error { | ||
|
@@ -49,3 +54,27 @@ func FindConfigMapVolume(podSpec *corev1.PodSpec, pred func(string) bool) string | |
} | ||
return "" | ||
} | ||
|
||
// KeepConfigMapNameUnchangedWhenCreateSTS is used to overwrite ConfigMap name to keep ConfigMap name remains unchanged | ||
// when create a new StatefulSet. | ||
// In some cases, we may need to delete and recreate STS for updating some immutable fields and are | ||
// expected to keep the name of ConfigMap unchanged to ensure no accidentally restart of pod. | ||
// For example: Updating storage size, iops or throughput of PVC using by TiKV. Now, | ||
// the annotation is set by pvc_resizer(not supported yet), pvc_modifier or pvc_replacer, See pkg/manager/utils/statefulset.go:DeleteStatefulSetWithOrphan. | ||
func KeepConfigMapNameUnchangedWhenCreateSTS(logger klog.Verbose, cmLister corelisters.ConfigMapLister, tc *v1alpha1.TidbCluster, componentType v1alpha1.MemberType, cm *corev1.ConfigMap) (overwritten bool, _ error) { | ||
cmNameInAnno := tc.Annotations[label.AnnoKeyOfConfigMapNameForNewSTS(string(componentType))] | ||
if cmNameInAnno == "" || cm.Name == cmNameInAnno { | ||
return false, nil | ||
} | ||
|
||
logger.Infof("another cm name found in AnnoConfigMapNameForNewSTSPrefix, use it. comp=%s, name=%s, nameInAnno=%s", componentType, cm.Name, cmNameInAnno) | ||
cmInAnno, err := cmLister.ConfigMaps(tc.Namespace).Get(cmNameInAnno) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to get configmap %s/%s: %w", tc.Namespace, cmNameInAnno, err) | ||
} | ||
if !equality.Semantic.DeepEqual(cmInAnno.Data, cm.Data) { | ||
return false, fmt.Errorf("unexpected ConfigMap data change. comp=%s, name=%s, nameInAnno=%s", componentType, cm.Name, cmNameInAnno) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure no ConfigMap data changed between delete and recreate STS |
||
cm.Name = cmNameInAnno | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TiProxyMemberType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed. ab80380