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

Introduced flag to specify when sts deleted, pvc's behavious #4759

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CharlesQQ
Copy link
Contributor

@CharlesQQ CharlesQQ commented Mar 27, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:
Introduced flag to specify when sts deleted, pvc's behavious

Which issue(s) this PR fixes:
Fixes #4750

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


`karmadactl`/`kubectl-karmada`: Introduced `etcd-sts-pvc-delete-policy` flags to specify when sts deleted, pvc's behavious

@karmada-bot karmada-bot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/bug Categorizes issue or PR as related to a bug. labels Mar 27, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign prodanlabs after the PR has been reviewed.
You can assign the PR to them by writing /assign @prodanlabs in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 27, 2024
@CharlesQQ CharlesQQ changed the title fix(/karmadactl): Introduced flag to specify when sts deleted, pvc's… Introduced flag to specify when sts deleted, pvc's behavious Mar 27, 2024
@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 27, 2024
@codecov-commenter
Copy link

codecov-commenter commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.78%. Comparing base (13dafc6) to head (e5f0662).
Report is 23 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4759      +/-   ##
==========================================
- Coverage   51.81%   51.78%   -0.03%     
==========================================
  Files         250      250              
  Lines       24983    24991       +8     
==========================================
- Hits        12944    12942       -2     
- Misses      11330    11340      +10     
  Partials      709      709              
Flag Coverage Δ
unittests 51.78% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

flags.StringVarP(&opts.EtcdImage, "etcd-image", "", "", "etcd image")
flags.StringVarP(&opts.EtcdInitImage, "etcd-init-image", "", kubernetes.DefaultInitImage, "etcd init container image")
flags.Int32VarP(&opts.EtcdReplicas, "etcd-replicas", "", 1, "etcd replica set, cluster 3,5...singular")
flags.StringVarP(&opts.EtcdHostDataPath, "etcd-data", "", "/var/lib/karmada-etcd", "etcd data path,valid in hostPath mode.")
flags.StringVarP(&opts.EtcdNodeSelectorLabels, "etcd-node-selector-labels", "", "", "etcd pod select the labels of the node. valid in hostPath mode ( e.g. --etcd-node-selector-labels karmada.io/etcd=true)")
flags.StringVarP(&opts.EtcdPersistentVolumeSize, "etcd-pvc-size", "", "5Gi", "etcd data path,valid in pvc mode.")
flags.StringVarP(&opts.EtcdStsPvcDeletePolicy, "etcd-sts-pvc-delete-policy", "", "Retain", fmt.Sprintf("(%s). retain or delete pvc when their stateful set is deleted. Retain, need k8s >= v1.27", strings.Join(kubernetes.SupportedPvcRetentionPolicyType().List(), ",")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chaosi-zju @prodanlabs @liangyuanpeng @RainbowMango How do you think this new flag?

@@ -733,6 +735,11 @@ func generateServerURL(serverIP string, nodePort int32) (string, error) {
}

// SupportedStorageMode Return install etcd supported storage mode
func SupportedStorageMode() []string {
return []string{etcdStorageModeEmptyDir, etcdStorageModeHostPath, etcdStorageModePVC}
func SupportedStorageMode() sets.String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set.String is deprecated, how about use sets.Set[string] to replace it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about use sets.Set[string] to replace it?

ok

if i.EtcdStsPvcDeletePolicy == string(appsv1.DeletePersistentVolumeClaimRetentionPolicyType) {
stsPvcRetentionPolicy = &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{
WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType,
WhenScaled: appsv1.RetainPersistentVolumeClaimRetentionPolicyType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question, I don't understand why this is set up.

Copy link
Contributor Author

@CharlesQQ CharlesQQ Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is set up.

Default policy is appsv1.RetainPersistentVolumeClaimRetentionPolicyType; if set flag, WhenDeleted value shoule be set to appsv1.DeletePersistentVolumeClaimRetentionPolicyType

…behavious

Signed-off-by: chang.qiangqiang <chang.qiangqiang@immomo.com>
flags.StringVarP(&opts.EtcdImage, "etcd-image", "", "", "etcd image")
flags.StringVarP(&opts.EtcdInitImage, "etcd-init-image", "", kubernetes.DefaultInitImage, "etcd init container image")
flags.Int32VarP(&opts.EtcdReplicas, "etcd-replicas", "", 1, "etcd replica set, cluster 3,5...singular")
flags.StringVarP(&opts.EtcdHostDataPath, "etcd-data", "", "/var/lib/karmada-etcd", "etcd data path,valid in hostPath mode.")
flags.StringVarP(&opts.EtcdNodeSelectorLabels, "etcd-node-selector-labels", "", "", "etcd pod select the labels of the node. valid in hostPath mode ( e.g. --etcd-node-selector-labels karmada.io/etcd=true)")
flags.StringVarP(&opts.EtcdPersistentVolumeSize, "etcd-pvc-size", "", "5Gi", "etcd data path,valid in pvc mode.")
flags.StringVarP(&opts.EtcdStsPvcDeletePolicy, "etcd-sts-pvc-delete-policy", "", "Retain", fmt.Sprintf("(%s). retain or delete pvc when their stateful set is deleted. Retain, need k8s >= v1.27", strings.Join(kubernetes.SupportedPvcRetentionPolicyType().UnsortedList(), ",")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly provide two flags to set the WhenDeleted and WhenScaled rotation policy type respectively without processing an extra layer and changing the original meaning?

@XiShanYongYe-Chang
Copy link
Member

What should we do with these flags for Kubernetes versions prior to v1.26?

@CharlesQQ
Copy link
Contributor Author

What should we do with these flags for Kubernetes versions prior to v1.26?

patch ovnerreference to pvc metedata

@XiShanYongYe-Chang
Copy link
Member

patch ovnerreference to pvc metedata

Sorry, let me rephrase my question. If the version of karmada-apiserver is before 1.27, will the current change have no effect or will it cause the etcd statefulset to report an error?

@CharlesQQ
Copy link
Contributor Author

If the version of karmada-apiserver is before 1.27, will the current change have no effect or will it cause the etcd statefulset to report an error?

sts has no field spec.persistentVolumeClaimRetentionPolicy, so sts can't be created and report an error

@XiShanYongYe-Chang
Copy link
Member

This behavior may not be expected as we allow the user to set the version of the apiserver:

flags.StringVar(&opts.KubeImageTag, "kube-image-tag", "v1.27.11", "Choose a specific Kubernetes version for the control plane.")

We may need to add some judgment logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: kubectl karmada deinit doesn't cascade deletion of pvc resources
4 participants