mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-21 04:20:23 +00:00
82bc993b32
There is no need for an extra import string when the go mod package itself declared in the same. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
112 lines
3.1 KiB
Go
112 lines
3.1 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package csicommon
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
"k8s.io/klog/v2"
|
|
|
|
"github.com/ceph/ceph-csi/internal/util"
|
|
)
|
|
|
|
// CSIDriver stores driver information.
|
|
type CSIDriver struct {
|
|
name string
|
|
nodeID string
|
|
version string
|
|
// topology constraints that this nodeserver will advertise
|
|
topology map[string]string
|
|
capabilities []*csi.ControllerServiceCapability
|
|
vc []*csi.VolumeCapability_AccessMode
|
|
}
|
|
|
|
// NewCSIDriver Creates a NewCSIDriver object. Assumes vendor
|
|
// version is equal to driver version & does not support optional
|
|
// driver plugin info manifest field. Refer to CSI spec for more details.
|
|
func NewCSIDriver(name, v, nodeID string) *CSIDriver {
|
|
if name == "" {
|
|
klog.Errorf("Driver name missing")
|
|
return nil
|
|
}
|
|
|
|
if nodeID == "" {
|
|
klog.Errorf("NodeID missing")
|
|
return nil
|
|
}
|
|
// TODO version format and validation
|
|
if v == "" {
|
|
klog.Errorf("Version argument missing")
|
|
return nil
|
|
}
|
|
|
|
driver := CSIDriver{
|
|
name: name,
|
|
version: v,
|
|
nodeID: nodeID,
|
|
}
|
|
|
|
return &driver
|
|
}
|
|
|
|
// ValidateControllerServiceRequest validates the controller
|
|
// plugin capabilities.
|
|
func (d *CSIDriver) ValidateControllerServiceRequest(c csi.ControllerServiceCapability_RPC_Type) error {
|
|
if c == csi.ControllerServiceCapability_RPC_UNKNOWN {
|
|
return nil
|
|
}
|
|
|
|
for _, capability := range d.capabilities {
|
|
if c == capability.GetRpc().GetType() {
|
|
return nil
|
|
}
|
|
}
|
|
return status.Error(codes.InvalidArgument, fmt.Sprintf("%s", c)) //nolint
|
|
}
|
|
|
|
// AddControllerServiceCapabilities stores the controller capabilities
|
|
// in driver object.
|
|
func (d *CSIDriver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapability_RPC_Type) {
|
|
var csc []*csi.ControllerServiceCapability
|
|
|
|
for _, c := range cl {
|
|
util.DefaultLog("Enabling controller service capability: %v", c.String())
|
|
csc = append(csc, NewControllerServiceCapability(c))
|
|
}
|
|
|
|
d.capabilities = csc
|
|
}
|
|
|
|
// AddVolumeCapabilityAccessModes stores volume access modes.
|
|
func (d *CSIDriver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode {
|
|
var vca []*csi.VolumeCapability_AccessMode
|
|
for _, c := range vc {
|
|
util.DefaultLog("Enabling volume access mode: %v", c.String())
|
|
vca = append(vca, NewVolumeCapabilityAccessMode(c))
|
|
}
|
|
d.vc = vca
|
|
return vca
|
|
}
|
|
|
|
// GetVolumeCapabilityAccessModes returns access modes.
|
|
func (d *CSIDriver) GetVolumeCapabilityAccessModes() []*csi.VolumeCapability_AccessMode {
|
|
return d.vc
|
|
}
|