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

reduce the volume name gap with external-provisioner #178

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

smileusd
Copy link
Contributor

@smileusd smileusd commented Oct 23, 2024

This pr is to reduce the gap with the external-provisioner pv name generation at https://github.com/kubernetes-csi/external-provisioner/blob/0f8b1662e25f37675da1f82acb78cd820b359419/pkg/controller/controller.go#L626
There is a potential bug if user not use default prefix or length to generate the pv name. There is a unexpected error.

/kind bug
/sig storage

Add a callback to customize PV name

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 23, 2024
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 23, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @smileusd. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 23, 2024
Comment on lines 1679 to 1697
func (ctrl *ProvisionController) makeVolumeName(pvcUID string) (string, error) {
// create persistent name based on a volumeNamePrefix and volumeNameUUIDLength
// of PVC's UID
if len(ctrl.volumeNamePrefix) == 0 {
return "", fmt.Errorf("Volume name prefix cannot be of length 0")
}
if ctrl.volumeNameUUIDLength == 0 {
return "", fmt.Errorf("Volume length cannot be 0")
}
if len(pvcUID) == 0 {
return "", fmt.Errorf("corrupted PVC object, it is missing UID")
}
if ctrl.volumeNameUUIDLength == -1 {
// Default behavior is to not truncate or remove dashes
return fmt.Sprintf("%s-%s", ctrl.volumeNamePrefix, pvcUID), nil
}
// Else we remove all dashes from UUID and truncate to volumeNameUUIDLength
return fmt.Sprintf("%s-%s", ctrl.volumeNamePrefix, strings.Replace(string(pvcUID), "-", "", -1)[0:ctrl.volumeNameUUIDLength]), nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to keep this weird function in the external-provisioner and here just provide a configurable callback stored in ProvisionController:

type VolumeNameHook func(claim *v1.PersistentVolumeClaim) string
type ProvisionController struct {
    ...
    volumeNameHook VolumeNameHook
}
...

func VolumeName(hook VolumeNameHook) func(*ProvisionController) error {
	return func(c *ProvisionController) error {
		if c.HasRun() {
			return errRuntime
		}
		c.volumeNameHook = hook
		return nil
	}
}

With the default value getProvisionedVolumeNameForClaim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestion. I try to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Please check @jsafrane

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 1, 2024
@jsafrane
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 16, 2024
@jsafrane
Copy link
Contributor

/lgtm
/approve
Thanks for the patch!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 16, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jsafrane, smileusd

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 16, 2024
@k8s-ci-robot k8s-ci-robot merged commit a0dd6f0 into kubernetes-sigs:master Nov 16, 2024
3 checks passed
@smileusd
Copy link
Contributor Author

@jsafrane Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants