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

Refactor RBD volume #54302

Merged
merged 2 commits into from Oct 24, 2017
Merged

Refactor RBD volume #54302

merged 2 commits into from Oct 24, 2017

Conversation

sbezverk
Copy link
Contributor

@sbezverk sbezverk commented Oct 20, 2017

Refactor RBD Volume Persistent Volume Spec so RBD PV's SecretRef
allows referencing a secret from a persistent volume in any namespace.
This allows locating credentials for persistent volumes in namespaces
other than the one containing the PVC.
Closes #54432

RBD Persistent Volume Sources can now reference User's Secret in namespaces other than the namespace of the bound Persistent Volume Claim

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 20, 2017
@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Oct 20, 2017
@sbezverk
Copy link
Contributor Author

/assign @rootfs

@rootfs
Copy link
Contributor

rootfs commented Oct 20, 2017

/assign @liggitt

@rootfs
Copy link
Contributor

rootfs commented Oct 20, 2017

please split the PR into 2 commits: one for generated files and one for the rest

// Default is nil.
// More info: https://releases.k8s.io/HEAD/examples/volumes/rbd/README.md#how-to-use-it
// +optional
SecretRef *SecretReference `json:"secretRef,omitempty" protobuf:"bytes,5,opt,name=secretRef"`
Copy link
Contributor

Choose a reason for hiding this comment

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

5->7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks a lot. Changed.

@@ -136,9 +136,6 @@ func SetObjectDefaults_PersistentVolume(in *v1.PersistentVolume) {
if in.Spec.PersistentVolumeSource.HostPath != nil {
SetDefaults_HostPathVolumeSource(in.Spec.PersistentVolumeSource.HostPath)
}
if in.Spec.PersistentVolumeSource.RBD != nil {
SetDefaults_RBDVolumeSource(in.Spec.PersistentVolumeSource.RBD)
Copy link
Member

Choose a reason for hiding this comment

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

need to copy SetDefaults_RBDVolumeSource to SetDefaults_RBDPersistentVolumeSource

Copy link
Member

@liggitt liggitt Oct 21, 2017

Choose a reason for hiding this comment

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

which also means copying the registered fuzzing function in pkg/api/fuzzer/fuzzer.go for RBDVolumeSource for RBDPersistentVolumeSource

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 fuzzer, but could you clarify about the first part? Do you want me to manually edit generated file or there is another way to accomplish it without editiing zz file.

Copy link
Member

Choose a reason for hiding this comment

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

SetDefaults_RBDVolumeSource is not in a generated file. Duplicate it there for the new type and rerun generation scripts which will fix up this file

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, I think at least, please check when you have a second.

@@ -40,6 +40,8 @@ type diskManager interface {
DetachDisk(disk rbdUnmounter, mntPath string) error
// Creates a rbd image
CreateImage(provisioner *rbdVolumeProvisioner) (r *v1.RBDVolumeSource, volumeSizeGB int, err error)
Copy link
Member

Choose a reason for hiding this comment

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

I only see this called in a single place, from rbdVolumeProvisioner, right? that should only deal with persistentvolumes... should just change the existing function

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

return nil, err
}
for name, data := range secrets.Data {
secret = string(data)
glog.V(4).Infof("found ceph secret info: %s", name)
Copy link
Member

@liggitt liggitt Oct 21, 2017

Choose a reason for hiding this comment

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

too verbose for inner loop, we weren't logging this before in parsePodSecret

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

@@ -486,16 +486,29 @@ func (c *rbdUnmounter) TearDownAt(dir string) error {
return diskTearDown(c.manager, *c, dir, c.mounter)
}

func getVolumeSource(
spec *volume.Spec) (*v1.RBDVolumeSource, bool, error) {
func getVolumeSource(spec *volume.Spec) ([]string, string, string, string, string, string, bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

this many return values of identical types is asking for trouble... individual accessors are simple and clear

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

@@ -407,6 +407,51 @@ func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDVolumeSource
}, sz, nil
}

func (util *RBDUtil) CreatePersistentVolumeImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVolumeSource, size int, err error) {
Copy link
Member

@liggitt liggitt Oct 21, 2017

Choose a reason for hiding this comment

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

should be able to change the existing CreateImage method instead of introducing this... there are no other callers

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

if err != nil {
glog.Errorf("rbd: create volume failed, err: %v", err)
return nil, err
}
glog.Infof("successfully created rbd image %q", image)
pv := new(v1.PersistentVolume)
metav1.SetMetaDataAnnotation(&pv.ObjectMeta, volumehelper.VolumeDynamicallyCreatedByKey, "rbd-dynamic-provisioner")
rbd.SecretRef = new(v1.LocalObjectReference)
rbd.SecretRef = new(v1.SecretReference)
rbd.SecretRef.Name = secretName
Copy link
Member

Choose a reason for hiding this comment

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

I expected to see rbd.SecretRef.Namespace = secretNamespace set from a case "usersecretnamespace": config param

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

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 21, 2017
@sbezverk
Copy link
Contributor Author

/sig storage

@k8s-ci-robot k8s-ci-robot added the sig/storage Categorizes an issue or PR as relevant to SIG Storage. label Oct 21, 2017
RBD: &api.RBDVolumeSource{
SecretRef: &api.LocalObjectReference{
RBD: &api.RBDPersistentVolumeSource{
SecretRef: &api.SecretReference{
Copy link
Member

Choose a reason for hiding this comment

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

Add a second PV spec that specifies a name and namespace in the RBD secretref (suggest namespace of "rbdns") and update expected namespaced secrets below

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

@@ -349,6 +380,9 @@ func (r *rbdVolumeProvisioner) Provision() (*v1.PersistentVolume, error) {
if secretName == "" {
return nil, fmt.Errorf("missing user secret name")
}
if secretNamespace == "" {
secretNamespace = adminSecretNamespace
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. User secret namespace defaults to "", which uses the namespace of the pod/pvc

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

spec *volume.Spec) (*v1.RBDVolumeSource, bool, error) {
func getVolumeSourceMonitors(spec *volume.Spec) ([]string, error) {
if spec.Volume != nil && spec.Volume.RBD != nil {
mon := spec.Volume.RBD.CephMonitors
Copy link
Member

Choose a reason for hiding this comment

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

for all the accessors, remove all the intermediate assignments and just return spec.Volume.RBD.CephMonitors, nil directly, etc

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

return readOnly, nil
} else if spec.PersistentVolume != nil &&
spec.PersistentVolume.Spec.RBD != nil {
readOnly := spec.ReadOnly
Copy link
Member

Choose a reason for hiding this comment

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

Comment here that this is intentional would be good (also worth noting in the API doc for this field that it is ignored in favor of the PV readonly setting would be good)

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

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 22, 2017
@liggitt liggitt added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 22, 2017
@liggitt
Copy link
Member

liggitt commented Oct 22, 2017

A few gofmt errors to fix:

I1022 18:39:48.130] Verifying hack/make-rules/../../hack/verify-gofmt.sh
I1022 18:40:00.434] diff ./pkg/api/persistentvolume/util_test.go gofmt/./pkg/api/persistentvolume/util_test.go
I1022 18:40:00.434] --- /tmp/gofmt551719841	2017-10-22 18:39:54.826431042 +0000
I1022 18:40:00.434] +++ /tmp/gofmt114547340	2017-10-22 18:39:54.826431042 +0000
I1022 18:40:00.434] @@ -68,13 +68,13 @@
I1022 18:40:00.435]  				RBD: &api.RBDPersistentVolumeSource{
I1022 18:40:00.435]  					SecretRef: &api.SecretReference{
I1022 18:40:00.435]  						Name: "Spec.PersistentVolumeSource.RBD.SecretRef"}}}}},
I1022 18:40:00.435] -                {Spec: api.PersistentVolumeSpec{
I1022 18:40:00.435] -                        ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
I1022 18:40:00.435] -                        PersistentVolumeSource: api.PersistentVolumeSource{
I1022 18:40:00.436] -                                RBD: &api.RBDPersistentVolumeSource{
I1022 18:40:00.436] -                                        SecretRef: &api.SecretReference{
I1022 18:40:00.436] -                                                Name: "Spec.PersistentVolumeSource.RBD.SecretRef",
I1022 18:40:00.436] -                                                Namespace: "rbdns"}}}}},
I1022 18:40:00.436] +		{Spec: api.PersistentVolumeSpec{
I1022 18:40:00.436] +			ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
I1022 18:40:00.436] +			PersistentVolumeSource: api.PersistentVolumeSource{
I1022 18:40:00.437] +				RBD: &api.RBDPersistentVolumeSource{
I1022 18:40:00.437] +					SecretRef: &api.SecretReference{
I1022 18:40:00.437] +						Name:      "Spec.PersistentVolumeSource.RBD.SecretRef",
I1022 18:40:00.437] +						Namespace: "rbdns"}}}}},
I1022 18:40:00.437]  		{Spec: api.PersistentVolumeSpec{
I1022 18:40:00.437]  			ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
I1022 18:40:00.437]  			PersistentVolumeSource: api.PersistentVolumeSource{
I1022 18:40:00.438] @@ -148,7 +148,7 @@
I1022 18:40:00.438]  		"cephfs/Spec.PersistentVolumeSource.CephFS.SecretRef",
I1022 18:40:00.438]  		"claimrefns/Spec.PersistentVolumeSource.FlexVolume.SecretRef",
I1022 18:40:00.438]  		"claimrefns/Spec.PersistentVolumeSource.RBD.SecretRef",
I1022 18:40:00.438] -                "rbdns/Spec.PersistentVolumeSource.RBD.SecretRef",
I1022 18:40:00.438] +		"rbdns/Spec.PersistentVolumeSource.RBD.SecretRef",
I1022 18:40:00.438]  		"claimrefns/Spec.PersistentVolumeSource.ScaleIO.SecretRef",
I1022 18:40:00.439]  		"claimrefns/Spec.PersistentVolumeSource.ISCSI.SecretRef",
I1022 18:40:00.439]  		"storageosns/Spec.PersistentVolumeSource.StorageOS.SecretRef",
I1022 18:40:00.439] diff ./pkg/volume/rbd/rbd.go gofmt/./pkg/volume/rbd/rbd.go
I1022 18:40:00.439] --- /tmp/gofmt441846395	2017-10-22 18:39:55.218430953 +0000
I1022 18:40:00.439] +++ /tmp/gofmt314242462	2017-10-22 18:39:55.218430953 +0000
I1022 18:40:00.439] @@ -589,8 +589,8 @@
I1022 18:40:00.439]  		return spec.Volume.RBD.ReadOnly, nil
I1022 18:40:00.439]  	} else if spec.PersistentVolume != nil &&
I1022 18:40:00.440]  		spec.PersistentVolume.Spec.RBD != nil {
I1022 18:40:00.440] -                // rbd volumes used as a PersistentVolume gets the ReadOnly flag indirectly through
I1022 18:40:00.440] -                // the persistent-claim volume used to mount the PV
I1022 18:40:00.440] +		// rbd volumes used as a PersistentVolume gets the ReadOnly flag indirectly through
I1022 18:40:00.440] +		// the persistent-claim volume used to mount the PV
I1022 18:40:00.440]  		return spec.ReadOnly, nil
I1022 18:40:00.440]  	}
I1022 18:40:00.441]  
I1022 18:40:00.441] �[0;31mFAILED�[0m   hack/make-rules/../../hack/verify-gofmt.sh	12s

lgtm orherwise

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 23, 2017
@sbezverk
Copy link
Contributor Author

/test pull-kubernetes-unit

@liggitt liggitt added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 24, 2017
@liggitt
Copy link
Member

liggitt commented Oct 24, 2017

/lgtm
needs a release note and doc update indicating the new storage class secret param

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Oct 24, 2017
@sbezverk
Copy link
Contributor Author

/release-note
RBD Persistent Volume Sources can now reference User's Secret in namespaces other than the namespace of the bound Persistent Volume Claim

@k8s-ci-robot
Copy link
Contributor

@sbezverk: the /release-note and /release-note-action-required commands have been deprecated.
Please edit the release-note block in the PR body text to include the release note. If the release note requires additional action include the string action required in the release note. For example:

```release-note
Some release note with action required.
```

In response to this:

/release-note
RBD Persistent Volume Sources can now reference User's Secret in namespaces other than the namespace of the bound Persistent Volume Claim

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/test-infra repository.

@sbezverk
Copy link
Contributor Author

RBD Persistent Volume Sources can now reference User's Secret in namespaces other than the namespace of the bound Persistent Volume Claim.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 24, 2017
@rootfs
Copy link
Contributor

rootfs commented Oct 24, 2017

/lgtm

@rootfs
Copy link
Contributor

rootfs commented Oct 24, 2017

/assign @thockin @smarterclayton @pwittrock
for doc approval

@smarterclayton
Copy link
Contributor

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, rootfs, sbezverk, smarterclayton

Associated issue: 54432

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 54229, 54380, 54302, 54454). If you want to cherry-pick this change to another branch, please follow the instructions here.

@krmayankk
Copy link

@liggitt @rootfs @sbezverk why do most of these PR's not have a milestone, its hard to know which release they are part of. this is a great change. thanks for doing this. Is this also done in the external provisioner

"v1.RBDVolumeSource": {
"id": "v1.RBDVolumeSource",
"v1.RBDPersistentVolumeSource": {
"id": "v1.RBDPersistentVolumeSource",

Choose a reason for hiding this comment

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

@rootfs is this a backward compatible change ?

Copy link
Member

Choose a reason for hiding this comment

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

It is wire compatible. The type name never appears in serialized proto and json, and the new struct contains identical fields, with the addition of a namespace field in the secret ref

@@ -21674,6 +21674,51 @@
}
}
},
"v1.RBDVolumeSource": {

Choose a reason for hiding this comment

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

why do we have both RBDPersistentVolumeSource and this ?

Copy link
Member

Choose a reason for hiding this comment

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

Because only the persistent volume version lets you reference a secret in a namespace other than the pod.

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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet