// ProbeRecyclableVolumePlugins collects all persistent volume plugins into an easy to use list. func ProbeRecyclableVolumePlugins(flags VolumeConfigFlags) []volume.VolumePlugin { allPlugins := []volume.VolumePlugin{} // The list of plugins to probe is decided by this binary, not // by dynamic linking or other "magic". Plugins will be analyzed and // initialized later. // Each plugin can make use of VolumeConfig. The single arg to this func contains *all* enumerated // CLI flags meant to configure volume plugins. From that single config, create an instance of volume.VolumeConfig // for a specific plugin and pass that instance to the plugin's ProbeVolumePlugins(config) func. // HostPath recycling is for testing and development purposes only! hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: flags.PersistentVolumeRecyclerMinimumTimeoutHostPath, RecyclerTimeoutIncrement: flags.PersistentVolumeRecyclerIncrementTimeoutHostPath, RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(), } if err := attemptToLoadRecycler(flags.PersistentVolumeRecyclerPodTemplateFilePathHostPath, &hostPathConfig); err != nil { glog.Fatalf("Could not create hostpath recycler pod from file %s: %+v", err) } allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: flags.PersistentVolumeRecyclerMinimumTimeoutNFS, RecyclerTimeoutIncrement: flags.PersistentVolumeRecyclerIncrementTimeoutNFS, RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(), } if err := attemptToLoadRecycler(flags.PersistentVolumeRecyclerPodTemplateFilePathNFS, &nfsConfig); err != nil { glog.Fatalf("Could not create NFS recycler pod from file %s: %+v", err) } allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) return allPlugins }
// ProbeControllerVolumePlugins collects all persistent volume plugins into an // easy to use list. Only volume plugins that implement any of // provisioner/recycler/deleter interface should be returned. func ProbeControllerVolumePlugins(cloud cloudprovider.Interface, config componentconfig.VolumeConfiguration) []volume.VolumePlugin { allPlugins := []volume.VolumePlugin{} // The list of plugins to probe is decided by this binary, not // by dynamic linking or other "magic". Plugins will be analyzed and // initialized later. // Each plugin can make use of VolumeConfig. The single arg to this func contains *all* enumerated // options meant to configure volume plugins. From that single config, create an instance of volume.VolumeConfig // for a specific plugin and pass that instance to the plugin's ProbeVolumePlugins(config) func. // HostPath recycling is for testing and development purposes only! hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: int(config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutHostPath), RecyclerTimeoutIncrement: int(config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutHostPath), RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(), ProvisioningEnabled: config.EnableHostPathProvisioning, } 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) } allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: int(config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutNFS), RecyclerTimeoutIncrement: int(config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutNFS), RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(), } 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) } allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) allPlugins = append(allPlugins, glusterfs.ProbeVolumePlugins()...) // add rbd provisioner allPlugins = append(allPlugins, rbd.ProbeVolumePlugins()...) allPlugins = append(allPlugins, quobyte.ProbeVolumePlugins()...) allPlugins = append(allPlugins, flocker.ProbeVolumePlugins()...) if cloud != nil { switch { case aws.ProviderName == cloud.ProviderName(): allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...) case gce.ProviderName == cloud.ProviderName(): allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...) case openstack.ProviderName == cloud.ProviderName(): allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...) case vsphere.ProviderName == cloud.ProviderName(): allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...) case azure.CloudProviderName == cloud.ProviderName(): allPlugins = append(allPlugins, azure_dd.ProbeVolumePlugins()...) case photon.ProviderName == cloud.ProviderName(): allPlugins = append(allPlugins, photon_pd.ProbeVolumePlugins()...) } } return allPlugins }
// probeRecyclableVolumePlugins collects all persistent volume plugins into an easy to use list. func probeRecyclableVolumePlugins(config componentconfig.VolumeConfiguration, namespace, recyclerImageName, recyclerServiceAccountName string) []volume.VolumePlugin { uid := int64(0) defaultScrubPod := volume.NewPersistentVolumeRecyclerPodTemplate() defaultScrubPod.Namespace = namespace defaultScrubPod.Spec.ServiceAccountName = recyclerServiceAccountName defaultScrubPod.Spec.Containers[0].Image = recyclerImageName defaultScrubPod.Spec.Containers[0].Command = []string{"/usr/bin/recycle"} defaultScrubPod.Spec.Containers[0].Args = []string{"/scrub"} defaultScrubPod.Spec.Containers[0].SecurityContext = &kapi.SecurityContext{RunAsUser: &uid} defaultScrubPod.Spec.Containers[0].ImagePullPolicy = kapi.PullIfNotPresent allPlugins := []volume.VolumePlugin{} // The list of plugins to probe is decided by this binary, not // by dynamic linking or other "magic". Plugins will be analyzed and // initialized later. // Each plugin can make use of VolumeConfig. The single arg to this func contains *all* enumerated // options meant to configure volume plugins. From that single config, create an instance of volume.VolumeConfig // for a specific plugin and pass that instance to the plugin's ProbeVolumePlugins(config) func. // HostPath recycling is for testing and development purposes only! hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: int(config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutHostPath), RecyclerTimeoutIncrement: int(config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutHostPath), RecyclerPodTemplate: defaultScrubPod, } if err := kctrlmgr.AttemptToLoadRecycler(config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, &hostPathConfig); err != nil { glog.Fatalf("Could not create hostpath recycler pod from file %s: %+v", config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, err) } allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: int(config.PersistentVolumeRecyclerConfiguration.MinimumTimeoutNFS), RecyclerTimeoutIncrement: int(config.PersistentVolumeRecyclerConfiguration.IncrementTimeoutNFS), RecyclerPodTemplate: volume.NewPersistentVolumeRecyclerPodTemplate(), } if err := kctrlmgr.AttemptToLoadRecycler(config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, &nfsConfig); err != nil { glog.Fatalf("Could not create NFS recycler pod from file %s: %+v", config.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, err) } allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...) allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...) allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...) allPlugins = append(allPlugins, flexvolume.ProbeVolumePlugins(config.FlexVolumePluginDir)...) allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...) return allPlugins }
func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string) { defaultScrubPod := volume.NewPersistentVolumeRecyclerPodTemplate() defaultScrubPod.Spec.Containers[0].Image = recyclerImageName defaultScrubPod.Spec.Containers[0].Command = []string{"/usr/share/openshift/scripts/volumes/recycler.sh"} defaultScrubPod.Spec.Containers[0].Args = []string{"/scrub"} hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: 30, RecyclerTimeoutIncrement: 30, RecyclerPodTemplate: defaultScrubPod, } nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: 180, RecyclerTimeoutIncrement: 30, RecyclerPodTemplate: defaultScrubPod, } allPlugins := []volume.VolumePlugin{} allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler(c.KubeClient, c.ControllerManager.PVClaimBinderSyncPeriod, allPlugins) if err != nil { glog.Fatalf("Could not start Persistent Volume Recycler: %+v", err) } recycler.Run() }
func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string, client *client.Client) { uid := int64(0) defaultScrubPod := volume.NewPersistentVolumeRecyclerPodTemplate() defaultScrubPod.Spec.Containers[0].Image = recyclerImageName defaultScrubPod.Spec.Containers[0].Command = []string{"/usr/bin/recycle"} defaultScrubPod.Spec.Containers[0].Args = []string{"/scrub"} defaultScrubPod.Spec.Containers[0].SecurityContext = &kapi.SecurityContext{RunAsUser: &uid} defaultScrubPod.Spec.Containers[0].ImagePullPolicy = kapi.PullIfNotPresent hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: 30, RecyclerTimeoutIncrement: 30, RecyclerPodTemplate: defaultScrubPod, } nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: 180, RecyclerTimeoutIncrement: 30, RecyclerPodTemplate: defaultScrubPod, } allPlugins := []volume.VolumePlugin{} allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler(client, c.ControllerManager.PVClaimBinderSyncPeriod, allPlugins) if err != nil { glog.Fatalf("Could not start Persistent Volume Recycler: %+v", err) } recycler.Run() }
func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string, client *client.Client, namespace string) { uid := int64(0) defaultScrubPod := volume.NewPersistentVolumeRecyclerPodTemplate() defaultScrubPod.Namespace = namespace defaultScrubPod.Spec.Containers[0].Image = recyclerImageName defaultScrubPod.Spec.Containers[0].Command = []string{"/usr/bin/recycle"} defaultScrubPod.Spec.Containers[0].Args = []string{"/scrub"} defaultScrubPod.Spec.Containers[0].SecurityContext = &kapi.SecurityContext{RunAsUser: &uid} defaultScrubPod.Spec.Containers[0].ImagePullPolicy = kapi.PullIfNotPresent volumeConfig := c.ControllerManager.VolumeConfiguration hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: int(volumeConfig.PersistentVolumeRecyclerConfiguration.MinimumTimeoutHostPath), RecyclerTimeoutIncrement: int(volumeConfig.PersistentVolumeRecyclerConfiguration.IncrementTimeoutHostPath), RecyclerPodTemplate: defaultScrubPod, } if len(volumeConfig.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath) != 0 { if err := attemptToLoadRecycler(volumeConfig.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, &hostPathConfig); err != nil { glog.Fatalf("Could not create hostpath recycler pod from file %s: %+v", volumeConfig.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathHostPath, err) } } nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: int(volumeConfig.PersistentVolumeRecyclerConfiguration.MinimumTimeoutNFS), RecyclerTimeoutIncrement: int(volumeConfig.PersistentVolumeRecyclerConfiguration.IncrementTimeoutNFS), RecyclerPodTemplate: defaultScrubPod, } if len(volumeConfig.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS) != 0 { if err := attemptToLoadRecycler(volumeConfig.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, &nfsConfig); err != nil { glog.Fatalf("Could not create NFS recycler pod from file %s: %+v", volumeConfig.PersistentVolumeRecyclerConfiguration.PodTemplateFilePathNFS, err) } } allPlugins := []volume.VolumePlugin{} allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) // dynamic provisioning allows deletion of volumes as a recycling operation after a claim is deleted allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...) allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...) allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...) recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler( clientadapter.FromUnversionedClient(client), c.ControllerManager.PVClaimBinderSyncPeriod.Duration, int(volumeConfig.PersistentVolumeRecyclerConfiguration.MaximumRetry), allPlugins, c.CloudProvider, ) if err != nil { glog.Fatalf("Could not start Persistent Volume Recycler: %+v", err) } recycler.Run() }
func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string, client *client.Client) { uid := int64(0) defaultScrubPod := volume.NewPersistentVolumeRecyclerPodTemplate() defaultScrubPod.Spec.Containers[0].Image = recyclerImageName defaultScrubPod.Spec.Containers[0].Command = []string{"/usr/bin/recycle"} defaultScrubPod.Spec.Containers[0].Args = []string{"/scrub"} defaultScrubPod.Spec.Containers[0].SecurityContext = &kapi.SecurityContext{RunAsUser: &uid} defaultScrubPod.Spec.Containers[0].ImagePullPolicy = kapi.PullIfNotPresent volumeConfig := c.ControllerManager.VolumeConfigFlags hostPathConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: volumeConfig.PersistentVolumeRecyclerMinimumTimeoutHostPath, RecyclerTimeoutIncrement: volumeConfig.PersistentVolumeRecyclerIncrementTimeoutHostPath, RecyclerPodTemplate: defaultScrubPod, } if len(volumeConfig.PersistentVolumeRecyclerPodTemplateFilePathHostPath) != 0 { if err := attemptToLoadRecycler(volumeConfig.PersistentVolumeRecyclerPodTemplateFilePathHostPath, &hostPathConfig); err != nil { glog.Fatalf("Could not create hostpath recycler pod from file %s: %+v", volumeConfig.PersistentVolumeRecyclerPodTemplateFilePathHostPath, err) } } nfsConfig := volume.VolumeConfig{ RecyclerMinimumTimeout: volumeConfig.PersistentVolumeRecyclerMinimumTimeoutNFS, RecyclerTimeoutIncrement: volumeConfig.PersistentVolumeRecyclerIncrementTimeoutNFS, RecyclerPodTemplate: defaultScrubPod, } if len(volumeConfig.PersistentVolumeRecyclerPodTemplateFilePathNFS) != 0 { if err := attemptToLoadRecycler(volumeConfig.PersistentVolumeRecyclerPodTemplateFilePathNFS, &nfsConfig); err != nil { glog.Fatalf("Could not create NFS recycler pod from file %s: %+v", volumeConfig.PersistentVolumeRecyclerPodTemplateFilePathNFS, err) } } allPlugins := []volume.VolumePlugin{} allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...) allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...) recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler(client, c.ControllerManager.PVClaimBinderSyncPeriod, allPlugins) if err != nil { glog.Fatalf("Could not start Persistent Volume Recycler: %+v", err) } recycler.Run() }
func TestSavePodToFile(t *testing.T) { pod := volume.NewPersistentVolumeRecyclerPodTemplate() // sets all default values on a pod for equality comparison after decoding from file encoded, err := latest.Codec.Encode(pod) latest.Codec.DecodeInto(encoded, pod) path := fmt.Sprintf("/tmp/kube-io-test-%s", uuid.New()) defer os.Remove(path) if err := SavePodToFile(pod, path, 777); err != nil { t.Fatalf("failed to save pod to file: %v", err) } podFromFile, err := LoadPodFromFile(path) if err != nil { t.Fatalf("failed to load pod from file: %v", err) } if !api.Semantic.DeepEqual(pod, podFromFile) { t.Errorf("\nexpected %#v\ngot %#v\n", pod, podFromFile) } }
func TestSavePodToFile(t *testing.T) { pod := volume.NewPersistentVolumeRecyclerPodTemplate() // sets all default values on a pod for equality comparison after decoding from file codec := api.Codecs.LegacyCodec(registered.GroupOrDie(api.GroupName).GroupVersion) encoded, err := runtime.Encode(codec, pod) runtime.DecodeInto(codec, encoded, pod) path := fmt.Sprintf("/tmp/kube-io-test-%s", uuid.New()) defer os.Remove(path) if err := io.SavePodToFile(pod, path, 777); err != nil { t.Fatalf("failed to save pod to file: %v", err) } podFromFile, err := io.LoadPodFromFile(path) if err != nil { t.Fatalf("failed to load pod from file: %v", err) } if !api.Semantic.DeepEqual(pod, podFromFile) { t.Errorf("\nexpected %#v\ngot %#v\n", pod, podFromFile) } }