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

persistent and ephemeral csi volumes #79983

Merged

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Jul 10, 2019

What type of PR is this?
/kind feature

What this PR does / why we need it:

This is part of the effort to move CSI inline ephemeral volumes to beta.

Which issue(s) this PR fixes:
Related-to: #79624

Does this PR introduce a user-facing change?:

when PodInfoOnMount is enabled for a CSI driver, the new csi.storage.k8s.io/ephemeral parameter in the volume context allows a driver's NodePublishVolume implementation to determine on a case-by-case basis whether the volume is ephemeral or a normal persistent volume

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. 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. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 10, 2019
@pohly
Copy link
Contributor Author

pohly commented Jul 10, 2019

/assign @vladimirvivien
/sig-storage

@pohly
Copy link
Contributor Author

pohly commented Jul 10, 2019

/sig storage
/priority important

@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 10, 2019
@k8s-ci-robot k8s-ci-robot requested review from copejon and saad-ali July 10, 2019 12:24
@@ -60,7 +61,7 @@ type csiMountMgr struct {
k8s kubernetes.Interface
plugin *csiPlugin
driverName csiDriverName
driverMode driverMode
volumeMode volumeMode
Copy link
Contributor

@cwdsuzhou cwdsuzhou Jul 10, 2019

Choose a reason for hiding this comment

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

If volumeMode would be misleading or confused with pv.spec.volumeMode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, naming is hard 😦

I also considered ephemeralMode or inlineMode, but both then don't make much sense when the value is persistent.

Any suggestions?

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 VolumeSource, with persistent and ephemeral as values?

It's then different from driverMode, but perhaps that's okay.

Choose a reason for hiding this comment

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

Yeah, naming things is hard. Slight preference to the previous name, driverMode, as that kind of matches the spec:
CSIDriver.Spec.Mode -> driverMode.

Or maybe csiDriverMode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VolumeSource also could be misunderstood (see snapshotting...). Let's see how well CSIVolumeMode works...

Choose a reason for hiding this comment

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

Works for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left "driverMode" unchanged, because as you said, it is derived from CSIDriver.Spec.Mode.

Copy link

@kfox1111 kfox1111 left a comment

Choose a reason for hiding this comment

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

With my limited knowledge of how e2e works, and excluding the naming question, this all looks good to me. :)

@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from 80b6fe7 to fc451cb Compare July 11, 2019 14:50
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 11, 2019
if csiVolumeMode == ephemeralVolumeMode {
klog.V(5).Info(log("plugin.CanDeviceMount skipped ephemeral mode detected for spec %v", spec.Name()))
return false, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this make it more clear?

If you do not think so, ignore it.

if !inlineEnabled {
    return true, nil
}
driverMode, err := p.getDriverMode(spec)
...

return true, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that's better and more consistent with usual Go style. I changed it, please have another look.

@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from fc451cb to a32af6b Compare July 12, 2019 11:01
@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 Jul 12, 2019
@pohly
Copy link
Contributor Author

pohly commented Jul 12, 2019

/retest

@pohly
Copy link
Contributor Author

pohly commented Jul 15, 2019

@cwdsuzhou is it okay now?

@@ -323,6 +324,7 @@ func (c *csiMountMgr) podAttributes() (map[string]string, error) {
"csi.storage.k8s.io/pod.namespace": c.pod.Namespace,
"csi.storage.k8s.io/pod.uid": string(c.pod.UID),
"csi.storage.k8s.io/serviceAccount.name": c.pod.Spec.ServiceAccountName,
"csi.storage.k8s.io/ephemeral": strconv.FormatBool(c.csiVolumeMode == ephemeralVolumeMode),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kfox1111 should the presence of this new field in the PodInfo depend on the feature gate?

Choose a reason for hiding this comment

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

Hmm... That is a good question...

It shouldn't hurt anything to have it always defined as it is, but following the principal that nothing should change if the gate is disabled, it probably should be behind the gate, yeah.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it optional, i.e. it only gets added when the feature gate is set.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 17, 2019
func InitEphemeralTestSuite() TestSuite {
return &ephemeralTestSuite{
tsInfo: TestSuiteInfo{
name: "ephemeral",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/hold

Currently ephemeral inline volumes are an alpha feature, so this whole suite must have a [Feature:CSIInlineVolume] tag. Will add 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.

Done.

@pohly
Copy link
Contributor Author

pohly commented Jul 24, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 24, 2019
Copy link
Contributor Author

@pohly pohly left a comment

Choose a reason for hiding this comment

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

These consts should be defined in the api. If the API is not there yet, then we should remember to remove these once we add it

The API still needs to be added. I've done that in a follow-up branch and also moved the constants.

@@ -44,6 +44,8 @@ var (
PreprovisionedPV TestVolType = "PreprovisionedPV"
// DynamicPV represents a volume type for dynamic provisioned Persistent Volume
DynamicPV TestVolType = "DynamicPV"
// CSIVolume represents a volume type that is defined inline and provided by a CSI driver.
CSIVolume TestVolType = "CSIVolume"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can rename "CSIVolume" to "CSIInlineVolume". I chose "CSIVolume" because that's also the term used in "CSIVolumeSource" (

// Represents a source location of a volume to mount, managed by an external CSI driver
type CSIVolumeSource struct {
), but I agree, the longer term is better and also used elsewhere (for example, in the feature gate).

The reason for the separate volume type is, as you said, that the characteristics of the volume are different. I don't know whether it makes a difference in practice, though.

@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from aa8999a to 564e628 Compare July 24, 2019 17:33
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 24, 2019
@pohly
Copy link
Contributor Author

pohly commented Jul 24, 2019

/retest

@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from 564e628 to dc5ecfa Compare July 24, 2019 20:31
@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

/retest

@pohly pohly mentioned this pull request Jul 25, 2019
@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from dc5ecfa to 93a0afe Compare July 25, 2019 13:37
@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

I included another fix (problem found while enabling in-tree testing of ephemeral volumes with the CSI hostpath driver):

diff --git a/test/e2e/storage/testsuites/ephemeral.go b/test/e2e/storage/testsuites/ephemeral.go
index bc7b8b244e..c9e4152cae 100644
--- a/test/e2e/storage/testsuites/ephemeral.go
+++ b/test/e2e/storage/testsuites/ephemeral.go
@@ -92,7 +92,7 @@ func (p *ephemeralTestSuite) defineTests(driver TestDriver, pattern testpatterns
                l.testCase = &EphemeralTest{
                        Client:     l.config.Framework.ClientSet,
                        Namespace:  f.Namespace.Name,
-                       DriverName: dInfo.Name,
+                       DriverName: l.config.GetUniqueDriverName(),
                        Node:       framework.NodeSelection{Name: l.config.ClientNodeName},
                        GetVolumeAttributes: func(volumeNumber int) map[string]string {
                                return eDriver.GetVolumeAttributes(l.config, volumeNumber)

It worked when testing an external driver because the unique name is the same as the base name...

@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

It worked when testing an external driver because the unique name is the same as the base name...

And using the generated name breaks testing an external driver... this needs some more work before it works for both.

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 25, 2019
@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

Fixed this way:

diff --git a/test/e2e/storage/external/external.go b/test/e2e/storage/external/external.go
index 6ff28829de..cb2c95535b 100644
--- a/test/e2e/storage/external/external.go
+++ b/test/e2e/storage/external/external.go
@@ -148,9 +148,6 @@ type driverDefinition struct {
 	// the default file system are enabled.
 	DriverInfo testsuites.DriverInfo
 
-	// ShortName is used to create unique names for test cases and test resources.
-	ShortName string
-
 	// StorageClass must be set to enable dynamic provisioning tests.
 	// The default is to not run those tests.
 	StorageClass struct {
@@ -186,6 +183,8 @@ type driverDefinition struct {
 	// has to be defined to enable testing of inline ephemeral volumes.
 	// If a test needs more volumes than defined, some of the defined
 	// volumes will be used multiple times.
+	//
+	// DriverInfo.Name is used as name of the driver in the inline volume.
 	InlineVolumeAttributes []map[string]string
 
 	// ClaimSize defines the desired size of dynamically
@@ -301,6 +300,10 @@ func (d *driverDefinition) GetVolumeAttributes(config *testsuites.PerTestConfig,
 	return d.InlineVolumeAttributes[volumeNumber%len(d.InlineVolumeAttributes)]
 }
 
+func (d *driverDefinition) GetCSIDriverName(config *testsuites.PerTestConfig) string {
+	return d.DriverInfo.Name
+}
+
 func (d *driverDefinition) PrepareTest(f *framework.Framework) (*testsuites.PerTestConfig, func()) {
 	config := &testsuites.PerTestConfig{
 		Driver:         d,
diff --git a/test/e2e/storage/testsuites/ephemeral.go b/test/e2e/storage/testsuites/ephemeral.go
index c9e4152cae..ee9cfcbf71 100644
--- a/test/e2e/storage/testsuites/ephemeral.go
+++ b/test/e2e/storage/testsuites/ephemeral.go
@@ -92,7 +92,7 @@ func (p *ephemeralTestSuite) defineTests(driver TestDriver, pattern testpatterns
 		l.testCase = &EphemeralTest{
 			Client:     l.config.Framework.ClientSet,
 			Namespace:  f.Namespace.Name,
-			DriverName: l.config.GetUniqueDriverName(),
+			DriverName: eDriver.GetCSIDriverName(l.config),
 			Node:       framework.NodeSelection{Name: l.config.ClientNodeName},
 			GetVolumeAttributes: func(volumeNumber int) map[string]string {
 				return eDriver.GetVolumeAttributes(l.config, volumeNumber)
diff --git a/test/e2e/storage/testsuites/testdriver.go b/test/e2e/storage/testsuites/testdriver.go
index 74224ca8d4..4c05d2554f 100644
--- a/test/e2e/storage/testsuites/testdriver.go
+++ b/test/e2e/storage/testsuites/testdriver.go
@@ -111,6 +111,11 @@ type EphemeralTestDriver interface {
 	// all be the same or different, depending what the driver supports
 	// and/or wants to test.
 	GetVolumeAttributes(config *PerTestConfig, volumeNumber int) map[string]string
+
+	// GetCSIDriverName returns the name that was used when registering with
+	// kubelet. Depending on how the driver was deployed, this can be different
+	// from DriverInfo.Name.
+	GetCSIDriverName(config *PerTestConfig) string
 }
 
 // SnapshottableTestDriver represents an interface for a TestDriver that supports DynamicSnapshot

The removal of ShortName is unrelated and a separate commit, I just noticed while looking into the driver naming problem that it exists although not used anywhere.

@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from 93a0afe to 817a43d Compare July 25, 2019 14:20
@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 25, 2019
@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

For reference, the in-tree usage of the new ephemeral testsuite test is part of PR #80568, currently in commit 4de69dcf9e759c9f096f83d0a444a3e091342f73.

pohly added 4 commits July 25, 2019 16:45
The name was meant to be used as shorter replacement for potentially
long CSI driver names, but was never used in practice.
The conceptual change is that the mode in which a volume gets handled
is derived from it's spec, not from the ability of the driver. In
practice, that is already how the code worked because it didn't
actually look at CSIDriver.Spec.Mode at all.

Therefore the code change itself is mostly just renaming "driver mode"
to "volume mode". In some places (CanDeviceMount, CanAttach) the
feature check that was used elsewhere seemed to be missing. Now their
code path for ephemeral volumes are also only entered if that feature
is enabled.

The sanity check whether a CSI driver is being used correctly still
needs to be implemented.

Related-to: kubernetes#79624
The PodInfo tests can be extended to also cover the new
csi.storage.k8s.io/ephemeral flag. However, the presence of that flag
depends on whether inline volume support is enabled, so tests that run
with and without the feature have to detect that at runtime.

Other tests have a feature tag and thus can assume that they only run
when that feature is enabled. However, we need a newer csi-mock driver
before we can actually ask it to publish an ephemeral inline volume.
@pohly pohly force-pushed the persistent-and-ephemeral-csi-volumes branch from 817a43d to 4bc5d06 Compare July 25, 2019 14:46
@pohly
Copy link
Contributor Author

pohly commented Jul 25, 2019

/test pull-kubernetes-integration

@msau42
Copy link
Member

msau42 commented Jul 25, 2019

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: msau42, pohly

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 Jul 25, 2019
@k8s-ci-robot k8s-ci-robot merged commit a375050 into kubernetes:master Jul 25, 2019
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. area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.

6 participants