mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Check kube client is valid
This commit is contained in:
parent
2bd077df6d
commit
443ae87b7e
@ -129,7 +129,11 @@ func (plugin *glusterfsPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volu
|
|||||||
ep_name := source.EndpointsName
|
ep_name := source.EndpointsName
|
||||||
// PVC/POD is in same ns.
|
// PVC/POD is in same ns.
|
||||||
ns := pod.Namespace
|
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 {
|
if err != nil {
|
||||||
glog.Errorf("glusterfs: failed to get endpoints %s[%v]", ep_name, err)
|
glog.Errorf("glusterfs: failed to get endpoints %s[%v]", ep_name, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -434,7 +438,11 @@ func (d *glusterfsVolumeDeleter) GetPath() string {
|
|||||||
// in a given storage class, and mark them in the table.
|
// in a given storage class, and mark them in the table.
|
||||||
//
|
//
|
||||||
func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocator) error {
|
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 {
|
if err != nil {
|
||||||
glog.Errorf("glusterfs: failed to get existing persistent volumes")
|
glog.Errorf("glusterfs: failed to get existing persistent volumes")
|
||||||
return err
|
return err
|
||||||
@ -761,7 +769,11 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
|
|||||||
Ports: []v1.EndpointPort{{Port: 1, Protocol: "TCP"}},
|
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) {
|
if err != nil && errors.IsAlreadyExists(err) {
|
||||||
glog.V(1).Infof("glusterfs: endpoint [%s] already exist in namespace [%s]", endpoint, namespace)
|
glog.V(1).Infof("glusterfs: endpoint [%s] already exist in namespace [%s]", endpoint, namespace)
|
||||||
err = nil
|
err = nil
|
||||||
@ -781,7 +793,7 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
|
|||||||
Spec: v1.ServiceSpec{
|
Spec: v1.ServiceSpec{
|
||||||
Ports: []v1.ServicePort{
|
Ports: []v1.ServicePort{
|
||||||
{Protocol: "TCP", Port: 1}}}}
|
{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) {
|
if err != nil && errors.IsAlreadyExists(err) {
|
||||||
glog.V(1).Infof("glusterfs: service [%s] already exist in namespace [%s]", service, namespace)
|
glog.V(1).Infof("glusterfs: service [%s] already exist in namespace [%s]", service, namespace)
|
||||||
err = nil
|
err = nil
|
||||||
@ -794,7 +806,11 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *glusterfsVolumeDeleter) deleteEndpointService(namespace string, epServiceName string) (err error) {
|
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 {
|
if err != nil {
|
||||||
glog.Errorf("glusterfs: error deleting service %s/%s: %v", namespace, epServiceName, err)
|
glog.Errorf("glusterfs: error deleting service %s/%s: %v", namespace, epServiceName, err)
|
||||||
return fmt.Errorf("error deleting service %s/%s: %v", namespace, epServiceName, err)
|
return fmt.Errorf("error deleting service %s/%s: %v", namespace, epServiceName, err)
|
||||||
|
@ -149,6 +149,9 @@ func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error) {
|
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
|
// TODO: replace with a real attribute after beta
|
||||||
className, found := pv.Annotations["volume.beta.kubernetes.io/storage-class"]
|
className, found := pv.Annotations["volume.beta.kubernetes.io/storage-class"]
|
||||||
if !found {
|
if !found {
|
||||||
|
Loading…
Reference in New Issue
Block a user