plugins.go 7.7 KB

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