Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Glusterfs Vol Plugin]: Check kube client is invalid and return error #39014

Merged
merged 1 commit into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions pkg/volume/glusterfs/glusterfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ func (plugin *glusterfsPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volu
ep_name := source.EndpointsName
// PVC/POD is in same ns.
ns := pod.Namespace
ep, err := plugin.host.GetKubeClient().Core().Endpoints(ns).Get(ep_name, metav1.GetOptions{})
kubeClient := plugin.host.GetKubeClient()
if kubeClient == nil {
return nil, fmt.Errorf("glusterfs: failed to get kube client to initialize mounter")
}
ep, err := kubeClient.Core().Endpoints(ns).Get(ep_name, metav1.GetOptions{})
if err != nil {
glog.Errorf("glusterfs: failed to get endpoints %s[%v]", ep_name, err)
return nil, err
Expand Down Expand Up @@ -434,7 +438,11 @@ func (d *glusterfsVolumeDeleter) GetPath() string {
// in a given storage class, and mark them in the table.
//
func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocator) error {
pvList, err := p.host.GetKubeClient().Core().PersistentVolumes().List(v1.ListOptions{LabelSelector: labels.Everything().String()})
kubeClient := p.host.GetKubeClient()
if kubeClient == nil {
return fmt.Errorf("glusterfs: failed to get kube client when collecting gids")
}
pvList, err := kubeClient.Core().PersistentVolumes().List(v1.ListOptions{LabelSelector: labels.Everything().String()})
if err != nil {
glog.Errorf("glusterfs: failed to get existing persistent volumes")
return err
Expand Down Expand Up @@ -761,7 +769,11 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
Ports: []v1.EndpointPort{{Port: 1, Protocol: "TCP"}},
}},
}
_, err = p.plugin.host.GetKubeClient().Core().Endpoints(namespace).Create(endpoint)
kubeClient := p.plugin.host.GetKubeClient()
if kubeClient == nil {
return nil, nil, fmt.Errorf("glusterfs: failed to get kube client when creating endpoint service")
}
_, err = kubeClient.Core().Endpoints(namespace).Create(endpoint)
if err != nil && errors.IsAlreadyExists(err) {
glog.V(1).Infof("glusterfs: endpoint [%s] already exist in namespace [%s]", endpoint, namespace)
err = nil
Expand All @@ -781,7 +793,7 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
{Protocol: "TCP", Port: 1}}}}
_, err = p.plugin.host.GetKubeClient().Core().Services(namespace).Create(service)
_, err = kubeClient.Core().Services(namespace).Create(service)
if err != nil && errors.IsAlreadyExists(err) {
glog.V(1).Infof("glusterfs: service [%s] already exist in namespace [%s]", service, namespace)
err = nil
Expand All @@ -794,7 +806,11 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
}

func (d *glusterfsVolumeDeleter) deleteEndpointService(namespace string, epServiceName string) (err error) {
err = d.plugin.host.GetKubeClient().Core().Services(namespace).Delete(epServiceName, nil)
kubeClient := d.plugin.host.GetKubeClient()
if kubeClient == nil {
return fmt.Errorf("glusterfs: failed to get kube client when deleting endpoint service")
}
err = kubeClient.Core().Services(namespace).Delete(epServiceName, nil)
if err != nil {
glog.Errorf("glusterfs: error deleting service %s/%s: %v", namespace, epServiceName, err)
return fmt.Errorf("error deleting service %s/%s: %v", namespace, epServiceName, err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/volume/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeCl
}

func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error) {
if kubeClient == nil {
return nil, fmt.Errorf("Cannot get kube client")
}
// TODO: replace with a real attribute after beta
className, found := pv.Annotations["volume.beta.kubernetes.io/storage-class"]
if !found {
Expand Down