testdriver.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package testsuites
  14. import (
  15. "k8s.io/api/core/v1"
  16. storagev1 "k8s.io/api/storage/v1"
  17. "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
  18. "k8s.io/apimachinery/pkg/util/sets"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. "k8s.io/kubernetes/test/e2e/framework/volume"
  21. "k8s.io/kubernetes/test/e2e/storage/testpatterns"
  22. )
  23. // TestDriver represents an interface for a driver to be tested in TestSuite.
  24. // Except for GetDriverInfo, all methods will be called at test runtime and thus
  25. // can use framework.Skipf, framework.Fatal, Gomega assertions, etc.
  26. type TestDriver interface {
  27. // GetDriverInfo returns DriverInfo for the TestDriver. This must be static
  28. // information.
  29. GetDriverInfo() *DriverInfo
  30. // SkipUnsupportedTest skips test if Testpattern is not
  31. // suitable to test with the TestDriver. It gets called after
  32. // parsing parameters of the test suite and before the
  33. // framework is initialized. Cheap tests that just check
  34. // parameters like the cloud provider can and should be
  35. // done in SkipUnsupportedTest to avoid setting up more
  36. // expensive resources like framework.Framework. Tests that
  37. // depend on a connection to the cluster can be done in
  38. // PrepareTest once the framework is ready.
  39. SkipUnsupportedTest(testpatterns.TestPattern)
  40. // PrepareTest is called at test execution time each time a new test case is about to start.
  41. // It sets up all necessary resources and returns the per-test configuration
  42. // plus a cleanup function that frees all allocated resources.
  43. PrepareTest(f *framework.Framework) (*PerTestConfig, func())
  44. }
  45. // TestVolume is the result of PreprovisionedVolumeTestDriver.CreateVolume.
  46. // The only common functionality is to delete it. Individual driver interfaces
  47. // have additional methods that work with volumes created by them.
  48. type TestVolume interface {
  49. DeleteVolume()
  50. }
  51. // PreprovisionedVolumeTestDriver represents an interface for a TestDriver that has pre-provisioned volume
  52. type PreprovisionedVolumeTestDriver interface {
  53. TestDriver
  54. // CreateVolume creates a pre-provisioned volume of the desired volume type.
  55. CreateVolume(config *PerTestConfig, volumeType testpatterns.TestVolType) TestVolume
  56. }
  57. // InlineVolumeTestDriver represents an interface for a TestDriver that supports InlineVolume
  58. type InlineVolumeTestDriver interface {
  59. PreprovisionedVolumeTestDriver
  60. // GetVolumeSource returns a volumeSource for inline volume.
  61. // It will set readOnly and fsType to the volumeSource, if TestDriver supports both of them.
  62. // It will return nil, if the TestDriver doesn't support either of the parameters.
  63. GetVolumeSource(readOnly bool, fsType string, testVolume TestVolume) *v1.VolumeSource
  64. }
  65. // PreprovisionedPVTestDriver represents an interface for a TestDriver that supports PreprovisionedPV
  66. type PreprovisionedPVTestDriver interface {
  67. PreprovisionedVolumeTestDriver
  68. // GetPersistentVolumeSource returns a PersistentVolumeSource with volume node affinity for pre-provisioned Persistent Volume.
  69. // It will set readOnly and fsType to the PersistentVolumeSource, if TestDriver supports both of them.
  70. // It will return nil, if the TestDriver doesn't support either of the parameters.
  71. GetPersistentVolumeSource(readOnly bool, fsType string, testVolume TestVolume) (*v1.PersistentVolumeSource, *v1.VolumeNodeAffinity)
  72. }
  73. // DynamicPVTestDriver represents an interface for a TestDriver that supports DynamicPV
  74. type DynamicPVTestDriver interface {
  75. TestDriver
  76. // GetDynamicProvisionStorageClass returns a StorageClass dynamic provision Persistent Volume.
  77. // The StorageClass must be created in the current test's namespace and have
  78. // a unique name inside that namespace because GetDynamicProvisionStorageClass might
  79. // be called more than once per test.
  80. // It will set fsType to the StorageClass, if TestDriver supports it.
  81. // It will return nil, if the TestDriver doesn't support it.
  82. GetDynamicProvisionStorageClass(config *PerTestConfig, fsType string) *storagev1.StorageClass
  83. // GetClaimSize returns the size of the volume that is to be provisioned ("5Gi", "1Mi").
  84. // The size must be chosen so that the resulting volume is large enough for all
  85. // enabled tests and within the range supported by the underlying storage.
  86. GetClaimSize() string
  87. }
  88. // SnapshottableTestDriver represents an interface for a TestDriver that supports DynamicSnapshot
  89. type SnapshottableTestDriver interface {
  90. TestDriver
  91. // GetSnapshotClass returns a SnapshotClass to create snapshot.
  92. // It will return nil, if the TestDriver doesn't support it.
  93. GetSnapshotClass(config *PerTestConfig) *unstructured.Unstructured
  94. }
  95. // Capability represents a feature that a volume plugin supports
  96. type Capability string
  97. const (
  98. CapPersistence Capability = "persistence" // data is persisted across pod restarts
  99. CapBlock Capability = "block" // raw block mode
  100. CapFsGroup Capability = "fsGroup" // volume ownership via fsGroup
  101. CapExec Capability = "exec" // exec a file in the volume
  102. CapDataSource Capability = "dataSource" // support populate data from snapshot
  103. // multiple pods on a node can use the same volume concurrently;
  104. // for CSI, see:
  105. // - https://github.com/container-storage-interface/spec/pull/150
  106. // - https://github.com/container-storage-interface/spec/issues/178
  107. // - NodeStageVolume in the spec
  108. CapMultiPODs Capability = "multipods"
  109. CapRWX Capability = "RWX" // support ReadWriteMany access modes
  110. )
  111. // DriverInfo represents static information about a TestDriver.
  112. type DriverInfo struct {
  113. // Internal name of the driver, this is used as a display name in the test
  114. // case and test objects
  115. Name string
  116. // Fully qualified plugin name as registered in Kubernetes of the in-tree
  117. // plugin if it exists and is empty if this DriverInfo represents a CSI
  118. // Driver
  119. InTreePluginName string
  120. FeatureTag string // FeatureTag for the driver
  121. MaxFileSize int64 // Max file size to be tested for this driver
  122. SupportedFsType sets.String // Map of string for supported fs type
  123. SupportedMountOption sets.String // Map of string for supported mount option
  124. RequiredMountOption sets.String // Map of string for required mount option (Optional)
  125. Capabilities map[Capability]bool // Map that represents plugin capabilities
  126. }
  127. // PerTestConfig represents parameters that control test execution.
  128. // One instance gets allocated for each test and is then passed
  129. // via pointer to functions involved in the test.
  130. type PerTestConfig struct {
  131. // The test driver for the test.
  132. Driver TestDriver
  133. // Some short word that gets inserted into dynamically
  134. // generated entities (pods, paths) as first part of the name
  135. // to make debugging easier. Can be the same for different
  136. // tests inside the test suite.
  137. Prefix string
  138. // The framework instance allocated for the current test.
  139. Framework *framework.Framework
  140. // If non-empty, then pods using a volume will be scheduled
  141. // onto the node with this name. Otherwise Kubernetes will
  142. // pick a node.
  143. ClientNodeName string
  144. // Some tests also support scheduling pods onto nodes with
  145. // these label/value pairs. As not all tests use this field,
  146. // a driver that absolutely needs the pods on a specific
  147. // node must use ClientNodeName.
  148. ClientNodeSelector map[string]string
  149. // Some test drivers initialize a storage server. This is
  150. // the configuration that then has to be used to run tests.
  151. // The values above are ignored for such tests.
  152. ServerConfig *volume.TestConfig
  153. }
  154. // GetUniqueDriverName returns unique driver name that can be used parallelly in tests
  155. func (config *PerTestConfig) GetUniqueDriverName() string {
  156. return config.Driver.GetDriverInfo().Name + "-" + config.Framework.UniqueName
  157. }