Skip to content

Commit

Permalink
fix: replace panic with error (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitm123 authored Sep 16, 2022
1 parent f344aef commit 38a90fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/lvmplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,9 @@ func handle() {
fmt.Printf("Failed to initialize driver: %s\n", err.Error())
os.Exit(1)
}
driver.Run()
err = driver.Run()
if err != nil {
fmt.Printf("Failed to start driver: %s\n", err.Error())
os.Exit(1)
}
}
10 changes: 5 additions & 5 deletions pkg/lvm/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ type controllerServer struct {
}

// NewControllerServer
func newControllerServer(ephemeral bool, nodeID string, devicesPattern string, vgName string, namespace string, provisionerImage string, pullPolicy v1.PullPolicy) *controllerServer {
func newControllerServer(ephemeral bool, nodeID string, devicesPattern string, vgName string, namespace string, provisionerImage string, pullPolicy v1.PullPolicy) (*controllerServer, error) {
if ephemeral {
return &controllerServer{caps: getControllerServiceCapabilities(nil), nodeID: nodeID}
return &controllerServer{caps: getControllerServiceCapabilities(nil), nodeID: nodeID}, nil
}

config, err := rest.InClusterConfig()
if err != nil {
panic(err.Error())
return nil, err
}
// creates the clientset
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
return nil, err
}
return &controllerServer{
caps: getControllerServiceCapabilities(
Expand All @@ -74,7 +74,7 @@ func newControllerServer(ephemeral bool, nodeID string, devicesPattern string, v
namespace: namespace,
provisionerImage: provisionerImage,
pullPolicy: pullPolicy,
}
}, nil
}

func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,19 @@ func NewLvmDriver(driverName, nodeID, endpoint string, ephemeral bool, maxVolume
}

// Run starts the lvm plugin
func (lvm *Lvm) Run() {
func (lvm *Lvm) Run() error {
var err error
// Create GRPC servers
lvm.ids = newIdentityServer(lvm.name, lvm.version)
lvm.ns = newNodeServer(lvm.nodeID, lvm.ephemeral, lvm.maxVolumesPerNode, lvm.devicesPattern, lvm.vgName)
lvm.cs = newControllerServer(lvm.ephemeral, lvm.nodeID, lvm.devicesPattern, lvm.vgName, lvm.namespace, lvm.provisionerImage, lvm.pullPolicy)

lvm.cs, err = newControllerServer(lvm.ephemeral, lvm.nodeID, lvm.devicesPattern, lvm.vgName, lvm.namespace, lvm.provisionerImage, lvm.pullPolicy)
if err != nil {
return err
}
s := newNonBlockingGRPCServer()
s.start(lvm.endpoint, lvm.ids, lvm.cs, lvm.ns)
s.wait()
return nil
}

func mountLV(lvname, mountPath string, vgName string) (string, error) {
Expand Down

0 comments on commit 38a90fa

Please sign in to comment.