2014-08-19 23:40:47 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-08-19 23:40:47 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-02-08 04:07:00 +00:00
|
|
|
package app
|
2014-08-19 23:40:47 +00:00
|
|
|
|
|
|
|
import (
|
2015-01-30 23:31:36 +00:00
|
|
|
// This file exists to force the desired plugin implementations to be linked.
|
|
|
|
// This should probably be part of some configuration fed into the build for a
|
|
|
|
// given binary target.
|
2015-05-29 20:34:32 +00:00
|
|
|
|
2015-10-12 18:27:49 +00:00
|
|
|
"fmt"
|
|
|
|
|
2016-01-05 07:16:18 +00:00
|
|
|
// Cloud providers
|
2016-02-08 21:33:20 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
2015-08-12 05:36:51 +00:00
|
|
|
_ "k8s.io/kubernetes/pkg/cloudprovider/providers"
|
2015-05-29 20:34:32 +00:00
|
|
|
|
|
|
|
// Volume plugins
|
2015-10-12 18:27:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
2015-12-15 09:22:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
|
2015-12-14 14:50:13 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
|
2015-12-15 11:38:59 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/openstack"
|
2015-09-03 03:14:26 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/io"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume"
|
2015-10-12 18:27:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume/aws_ebs"
|
|
|
|
"k8s.io/kubernetes/pkg/volume/cinder"
|
|
|
|
"k8s.io/kubernetes/pkg/volume/gce_pd"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume/host_path"
|
|
|
|
"k8s.io/kubernetes/pkg/volume/nfs"
|
2015-09-03 03:14:26 +00:00
|
|
|
|
|
|
|
"github.com/golang/glog"
|
2014-08-19 23:40:47 +00:00
|
|
|
)
|
2015-05-29 20:34:32 +00:00
|
|
|
|
|
|
|
// ProbeRecyclableVolumePlugins collects all persistent volume plugins into an easy to use list.
|
2016-02-08 21:33:20 +00:00
|
|
|
func ProbeRecyclableVolumePlugins(config componentconfig.VolumeConfiguration) []volume.VolumePlugin {
|
2015-05-29 20:34:32 +00:00
|
|
|
allPlugins := []volume.VolumePlugin{}
|
|
|
|
|
2015-08-31 13:44:37 +00:00
|
|
|
// The list of plugins to probe is decided by this binary, not
|
2015-05-29 20:34:32 +00:00
|
|
|
// by dynamic linking or other "magic". Plugins will be analyzed and
|
|
|
|
// initialized later.
|
2015-08-31 13:44:37 +00:00
|
|
|
|
|
|
|
// Each plugin can make use of VolumeConfig. The single arg to this func contains *all* enumerated
|
2016-02-08 21:33:20 +00:00
|
|
|
// options meant to configure volume plugins. From that single config, create an instance of volume.VolumeConfig
|
2015-08-31 13:44:37 +00:00
|
|
|
// for a specific plugin and pass that instance to the plugin's ProbeVolumePlugins(config) func.
|
2015-09-03 03:14:26 +00:00
|
|
|
|
|
|
|
// HostPath recycling is for testing and development purposes only!
|
2015-08-31 13:44:37 +00:00
|
|
|
hostPathConfig := volume.VolumeConfig{
|
2016-02-08 21:33:20 +00:00
|
|
|
RecyclerMinimumTimeout: config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutHostPath,
|
|
|
|
RecyclerTimeoutIncrement: config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutHostPath,
|
2015-09-03 03:14:26 +00:00
|
|
|
RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(),
|
2015-08-31 13:44:37 +00:00
|
|
|
}
|
2016-02-08 21:33:20 +00:00
|
|
|
if err := AttemptToLoadRecycler(config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, &hostPathConfig); err != nil {
|
|
|
|
glog.Fatalf("Could not create hostpath recycler pod from file %s: %+v", config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, err)
|
2015-08-31 13:44:37 +00:00
|
|
|
}
|
|
|
|
allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...)
|
2015-09-03 03:14:26 +00:00
|
|
|
|
|
|
|
nfsConfig := volume.VolumeConfig{
|
2016-02-08 21:33:20 +00:00
|
|
|
RecyclerMinimumTimeout: config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutNFS,
|
|
|
|
RecyclerTimeoutIncrement: config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutNFS,
|
2015-09-03 03:14:26 +00:00
|
|
|
RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(),
|
|
|
|
}
|
2016-02-08 21:33:20 +00:00
|
|
|
if err := AttemptToLoadRecycler(config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, &nfsConfig); err != nil {
|
|
|
|
glog.Fatalf("Could not create NFS recycler pod from file %s: %+v", config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, err)
|
2015-09-03 03:14:26 +00:00
|
|
|
}
|
2015-08-31 13:44:37 +00:00
|
|
|
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...)
|
2015-09-03 03:14:26 +00:00
|
|
|
|
2015-10-12 18:27:49 +00:00
|
|
|
allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...)
|
|
|
|
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
|
|
|
|
allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...)
|
|
|
|
|
2015-05-29 20:34:32 +00:00
|
|
|
return allPlugins
|
|
|
|
}
|
2015-09-03 03:14:26 +00:00
|
|
|
|
2015-10-12 18:27:49 +00:00
|
|
|
// NewVolumeProvisioner returns a volume provisioner to use when running in a cloud or development environment.
|
|
|
|
// The beta implementation of provisioning allows 1 implied provisioner per cloud, until we allow configuration of many.
|
|
|
|
// We explicitly map clouds to volume plugins here which allows us to configure many later without backwards compatibility issues.
|
|
|
|
// Not all cloudproviders have provisioning capability, which is the reason for the bool in the return to tell the caller to expect one or not.
|
2016-02-08 21:33:20 +00:00
|
|
|
func NewVolumeProvisioner(cloud cloudprovider.Interface, config componentconfig.VolumeConfiguration) (volume.ProvisionableVolumePlugin, error) {
|
2015-10-12 18:27:49 +00:00
|
|
|
switch {
|
2016-02-08 21:33:20 +00:00
|
|
|
case cloud == nil && config.EnableHostPathProvisioning:
|
2015-10-12 18:27:49 +00:00
|
|
|
return getProvisionablePluginFromVolumePlugins(host_path.ProbeVolumePlugins(volume.VolumeConfig{}))
|
2015-12-15 09:22:49 +00:00
|
|
|
case cloud != nil && aws.ProviderName == cloud.ProviderName():
|
|
|
|
return getProvisionablePluginFromVolumePlugins(aws_ebs.ProbeVolumePlugins())
|
2015-12-14 14:50:13 +00:00
|
|
|
case cloud != nil && gce.ProviderName == cloud.ProviderName():
|
|
|
|
return getProvisionablePluginFromVolumePlugins(gce_pd.ProbeVolumePlugins())
|
2015-12-15 11:38:59 +00:00
|
|
|
case cloud != nil && openstack.ProviderName == cloud.ProviderName():
|
|
|
|
return getProvisionablePluginFromVolumePlugins(cinder.ProbeVolumePlugins())
|
2015-10-12 18:27:49 +00:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getProvisionablePluginFromVolumePlugins(plugins []volume.VolumePlugin) (volume.ProvisionableVolumePlugin, error) {
|
|
|
|
for _, plugin := range plugins {
|
|
|
|
if provisonablePlugin, ok := plugin.(volume.ProvisionableVolumePlugin); ok {
|
|
|
|
return provisonablePlugin, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("ProvisionablePlugin expected but not found in %#v: ", plugins)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
|
2015-09-03 03:14:26 +00:00
|
|
|
// If successful, this method will set the recycler on the config.
|
2015-10-12 18:27:49 +00:00
|
|
|
// If unsuccessful, an error is returned. Function is exported for reuse downstream.
|
|
|
|
func AttemptToLoadRecycler(path string, config *volume.VolumeConfig) error {
|
2015-09-03 03:14:26 +00:00
|
|
|
if path != "" {
|
|
|
|
recyclerPod, err := io.LoadPodFromFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
config.RecyclerPodTemplate = recyclerPod
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|