github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/cloud/pkg/csidriver/server.go (about)

     1  /*
     2  Copyright 2019 The KubeEdge Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package csidriver
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"k8s.io/klog"
    23  
    24  	"github.com/kubeedge/kubeedge/cloud/cmd/csidriver/app/options"
    25  )
    26  
    27  type CSIDriver struct {
    28  	options.CSIDriverOptions
    29  
    30  	ids *identityServer
    31  	cs  *controllerServer
    32  }
    33  
    34  func NewCSIDriver(opts *options.CSIDriverOptions) (*CSIDriver, error) {
    35  	if opts.Endpoint == "" {
    36  		return nil, fmt.Errorf("no driver endpoint provided")
    37  	}
    38  	if opts.DriverName == "" {
    39  		return nil, fmt.Errorf("no driver name provided")
    40  	}
    41  	if opts.NodeID == "" {
    42  		return nil, fmt.Errorf("no node id provided")
    43  	}
    44  	if opts.KubeEdgeEndpoint == "" {
    45  		return nil, fmt.Errorf("no kubeedge endpoint provided")
    46  	}
    47  	if opts.Version == "" {
    48  		return nil, fmt.Errorf("no version provided")
    49  	}
    50  	return &CSIDriver{
    51  		CSIDriverOptions: *opts,
    52  	}, nil
    53  }
    54  
    55  func (cd *CSIDriver) Run() {
    56  	klog.Infof("driver information: %v", cd)
    57  
    58  	// Create GRPC servers
    59  	cd.ids = newIdentityServer(cd.DriverName, cd.Version)
    60  	cd.cs = newControllerServer(cd.NodeID, cd.KubeEdgeEndpoint)
    61  
    62  	s := newNonBlockingGRPCServer()
    63  	s.Start(cd.Endpoint, cd.ids, cd.cs, nil)
    64  	s.Wait()
    65  }