plugins.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. Copyright 2014 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 app
  14. import (
  15. // This file exists to force the desired plugin implementations to be linked.
  16. // This should probably be part of some configuration fed into the build for a
  17. // given binary target.
  18. "fmt"
  19. "k8s.io/klog"
  20. // Cloud providers
  21. cloudprovider "k8s.io/cloud-provider"
  22. // ensure the cloud providers are installed
  23. _ "k8s.io/kubernetes/pkg/cloudprovider/providers"
  24. // Volume plugins
  25. "k8s.io/kubernetes/pkg/volume"
  26. "k8s.io/kubernetes/pkg/volume/awsebs"
  27. "k8s.io/kubernetes/pkg/volume/azure_dd"
  28. "k8s.io/kubernetes/pkg/volume/azure_file"
  29. "k8s.io/kubernetes/pkg/volume/cinder"
  30. "k8s.io/kubernetes/pkg/volume/csi"
  31. "k8s.io/kubernetes/pkg/volume/fc"
  32. "k8s.io/kubernetes/pkg/volume/flexvolume"
  33. "k8s.io/kubernetes/pkg/volume/flocker"
  34. "k8s.io/kubernetes/pkg/volume/gcepd"
  35. "k8s.io/kubernetes/pkg/volume/glusterfs"
  36. "k8s.io/kubernetes/pkg/volume/hostpath"
  37. "k8s.io/kubernetes/pkg/volume/iscsi"
  38. "k8s.io/kubernetes/pkg/volume/local"
  39. "k8s.io/kubernetes/pkg/volume/nfs"
  40. "k8s.io/kubernetes/pkg/volume/photon_pd"
  41. "k8s.io/kubernetes/pkg/volume/portworx"
  42. "k8s.io/kubernetes/pkg/volume/quobyte"
  43. "k8s.io/kubernetes/pkg/volume/rbd"
  44. "k8s.io/kubernetes/pkg/volume/scaleio"
  45. "k8s.io/kubernetes/pkg/volume/storageos"
  46. volumeutil "k8s.io/kubernetes/pkg/volume/util"
  47. "k8s.io/kubernetes/pkg/volume/vsphere_volume"
  48. utilfeature "k8s.io/apiserver/pkg/util/feature"
  49. persistentvolumeconfig "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/config"
  50. "k8s.io/kubernetes/pkg/features"
  51. "k8s.io/utils/exec"
  52. )
  53. // ProbeAttachableVolumePlugins collects all volume plugins for the attach/
  54. // detach controller.
  55. // The list of plugins is manually compiled. This code and the plugin
  56. // initialization code for kubelet really, really need a through refactor.
  57. func ProbeAttachableVolumePlugins() []volume.VolumePlugin {
  58. allPlugins := []volume.VolumePlugin{}
  59. allPlugins = append(allPlugins, awsebs.ProbeVolumePlugins()...)
  60. allPlugins = append(allPlugins, gcepd.ProbeVolumePlugins()...)
  61. allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...)
  62. allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
  63. allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...)
  64. allPlugins = append(allPlugins, azure_dd.ProbeVolumePlugins()...)
  65. allPlugins = append(allPlugins, photon_pd.ProbeVolumePlugins()...)
  66. allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
  67. allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
  68. allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
  69. allPlugins = append(allPlugins, iscsi.ProbeVolumePlugins()...)
  70. allPlugins = append(allPlugins, rbd.ProbeVolumePlugins()...)
  71. if utilfeature.DefaultFeatureGate.Enabled(features.CSIPersistentVolume) {
  72. allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)
  73. }
  74. return allPlugins
  75. }
  76. // GetDynamicPluginProber gets the probers of dynamically discoverable plugins
  77. // for the attach/detach controller.
  78. // Currently only Flexvolume plugins are dynamically discoverable.
  79. func GetDynamicPluginProber(config persistentvolumeconfig.VolumeConfiguration) volume.DynamicPluginProber {
  80. return flexvolume.GetDynamicPluginProber(config.FlexVolumePluginDir, exec.New() /*exec.Interface*/)
  81. }
  82. // ProbeExpandableVolumePlugins returns volume plugins which are expandable
  83. func ProbeExpandableVolumePlugins(config persistentvolumeconfig.VolumeConfiguration) []volume.VolumePlugin {
  84. allPlugins := []volume.VolumePlugin{}
  85. allPlugins = append(allPlugins, awsebs.ProbeVolumePlugins()...)
  86. allPlugins = append(allPlugins, gcepd.ProbeVolumePlugins()...)
  87. allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...)
  88. allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
  89. allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...)
  90. allPlugins = append(allPlugins, glusterfs.ProbeVolumePlugins()...)
  91. allPlugins = append(allPlugins, rbd.ProbeVolumePlugins()...)
  92. allPlugins = append(allPlugins, azure_dd.ProbeVolumePlugins()...)
  93. allPlugins = append(allPlugins, azure_file.ProbeVolumePlugins()...)
  94. allPlugins = append(allPlugins, photon_pd.ProbeVolumePlugins()...)
  95. allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
  96. allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
  97. allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
  98. return allPlugins
  99. }
  100. // ProbeControllerVolumePlugins collects all persistent volume plugins into an
  101. // easy to use list. Only volume plugins that implement any of
  102. // provisioner/recycler/deleter interface should be returned.
  103. func ProbeControllerVolumePlugins(cloud cloudprovider.Interface, config persistentvolumeconfig.VolumeConfiguration) []volume.VolumePlugin {
  104. allPlugins := []volume.VolumePlugin{}
  105. // The list of plugins to probe is decided by this binary, not
  106. // by dynamic linking or other "magic". Plugins will be analyzed and
  107. // initialized later.
  108. // Each plugin can make use of VolumeConfig. The single arg to this func contains *all* enumerated
  109. // options meant to configure volume plugins. From that single config, create an instance of volume.VolumeConfig
  110. // for a specific plugin and pass that instance to the plugin's ProbeVolumePlugins(config) func.
  111. // HostPath recycling is for testing and development purposes only!
  112. hostPathConfig := volume.VolumeConfig{
  113. RecyclerMinimumTimeout: int(config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutHostPath),
  114. RecyclerTimeoutIncrement: int(config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutHostPath),
  115. RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(),
  116. ProvisioningEnabled: config.EnableHostPathProvisioning,
  117. }
  118. if err := AttemptToLoadRecycler(config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, &hostPathConfig); err != nil {
  119. klog.Fatalf("Could not create hostpath recycler pod from file %s: %+v", config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, err)
  120. }
  121. allPlugins = append(allPlugins, hostpath.ProbeVolumePlugins(hostPathConfig)...)
  122. nfsConfig := volume.VolumeConfig{
  123. RecyclerMinimumTimeout: int(config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutNFS),
  124. RecyclerTimeoutIncrement: int(config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutNFS),
  125. RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(),
  126. }
  127. if err := AttemptToLoadRecycler(config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, &nfsConfig); err != nil {
  128. klog.Fatalf("Could not create NFS recycler pod from file %s: %+v", config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, err)
  129. }
  130. allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...)
  131. allPlugins = append(allPlugins, glusterfs.ProbeVolumePlugins()...)
  132. // add rbd provisioner
  133. allPlugins = append(allPlugins, rbd.ProbeVolumePlugins()...)
  134. allPlugins = append(allPlugins, quobyte.ProbeVolumePlugins()...)
  135. allPlugins = append(allPlugins, azure_file.ProbeVolumePlugins()...)
  136. allPlugins = append(allPlugins, flocker.ProbeVolumePlugins()...)
  137. allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
  138. allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
  139. allPlugins = append(allPlugins, local.ProbeVolumePlugins()...)
  140. allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
  141. allPlugins = append(allPlugins, awsebs.ProbeVolumePlugins()...)
  142. allPlugins = append(allPlugins, gcepd.ProbeVolumePlugins()...)
  143. allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...)
  144. allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...)
  145. allPlugins = append(allPlugins, azure_dd.ProbeVolumePlugins()...)
  146. allPlugins = append(allPlugins, photon_pd.ProbeVolumePlugins()...)
  147. if utilfeature.DefaultFeatureGate.Enabled(features.CSIInlineVolume) {
  148. allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)
  149. }
  150. return allPlugins
  151. }
  152. // AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
  153. // If successful, this method will set the recycler on the config.
  154. // If unsuccessful, an error is returned. Function is exported for reuse downstream.
  155. func AttemptToLoadRecycler(path string, config *volume.VolumeConfig) error {
  156. if path != "" {
  157. recyclerPod, err := volumeutil.LoadPodFromFile(path)
  158. if err != nil {
  159. return err
  160. }
  161. if err = volume.ValidateRecyclerPodTemplate(recyclerPod); err != nil {
  162. return fmt.Errorf("pod specification (%v): %v", path, err)
  163. }
  164. config.RecyclerPodTemplate = recyclerPod
  165. }
  166. return nil
  167. }