util: NewK8sClient() should not panic on non-Kubernetes clusters

When NewK8sClient() detects and error, it used to call FatalLogMsg()
which causes a panic. There are additional features that can be used on
Kubernetes clusters, but these are not a requirement for most
functionalities of the driver.

Instead of causing a panic, returning an error should suffice. This
allows using the driver on non-Kubernetes clusters again.

Fixes: #2452
Signed-off-by: Niels de Vos <ndevos@redhat.com>
(cherry picked from commit 60c2afbcca)
This commit is contained in:
Niels de Vos
2021-08-31 14:18:37 +02:00
committed by mergify[bot]
parent cf93951f3b
commit 24f92b2255
9 changed files with 79 additions and 21 deletions

View File

@ -125,7 +125,13 @@ func callNodeStageVolume(ns *NodeServer, c *k8s.Clientset, pv *v1.PersistentVolu
// runVolumeHealer heal the volumes attached on a node.
func runVolumeHealer(ns *NodeServer, conf *util.Config) error {
c := util.NewK8sClient()
c, err := util.NewK8sClient()
if err != nil {
util.ErrorLogMsg("failed to connect to Kubernetes: %v", err)
return err
}
val, err := c.StorageV1().VolumeAttachments().List(context.TODO(), metav1.ListOptions{})
if err != nil {
util.ErrorLogMsg("list volumeAttachments failed, err: %v", err)

View File

@ -1060,7 +1060,11 @@ func genVolFromVolID(
// be the same in the PV.Spec.CSI.VolumeHandle. Check the PV annotation for
// the new volumeHandle. If the new volumeHandle is found, generate the RBD
// volume structure from the new volumeHandle.
c := util.NewK8sClient()
c, cErr := util.NewK8sClient()
if cErr != nil {
return vol, cErr
}
listOpt := metav1.ListOptions{
LabelSelector: PVReplicatedLabelKey,
}