2018-01-09 18:57:14 +00:00
|
|
|
/*
|
|
|
|
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 (
|
2021-01-11 08:02:41 +00:00
|
|
|
"context"
|
2019-07-30 06:20:28 +00:00
|
|
|
|
2021-08-24 15:03:25 +00:00
|
|
|
"github.com/ceph/ceph-csi/internal/util/log"
|
2019-07-30 06:20:28 +00:00
|
|
|
|
2018-11-26 18:23:56 +00:00
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
2022-07-18 16:13:36 +00:00
|
|
|
mount "k8s.io/mount-utils"
|
2018-01-09 18:57:14 +00:00
|
|
|
)
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// DefaultNodeServer stores driver object.
|
2018-01-09 18:57:14 +00:00
|
|
|
type DefaultNodeServer struct {
|
2022-07-26 10:04:57 +00:00
|
|
|
csi.UnimplementedNodeServer
|
2022-07-18 16:13:36 +00:00
|
|
|
Driver *CSIDriver
|
|
|
|
Type string
|
|
|
|
Mounter mount.Interface
|
2023-11-17 06:29:00 +00:00
|
|
|
// NodeLabels stores the node labels
|
|
|
|
NodeLabels map[string]string
|
|
|
|
// CLIReadAffinityOptions contains map options passed through command line to enable read affinity.
|
|
|
|
CLIReadAffinityOptions string
|
2018-01-09 18:57:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// NodeGetInfo returns node ID.
|
2021-06-25 11:20:31 +00:00
|
|
|
func (ns *DefaultNodeServer) NodeGetInfo(
|
|
|
|
ctx context.Context,
|
2022-06-01 10:17:19 +00:00
|
|
|
req *csi.NodeGetInfoRequest,
|
|
|
|
) (*csi.NodeGetInfoResponse, error) {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.TraceLog(ctx, "Using default NodeGetInfo")
|
2018-07-18 14:47:22 +00:00
|
|
|
|
2020-01-24 16:26:56 +00:00
|
|
|
csiTopology := &csi.Topology{
|
|
|
|
Segments: ns.Driver.topology,
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:47:22 +00:00
|
|
|
return &csi.NodeGetInfoResponse{
|
2020-01-24 16:26:56 +00:00
|
|
|
NodeId: ns.Driver.nodeID,
|
|
|
|
AccessibleTopology: csiTopology,
|
2018-07-18 14:47:22 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:54:29 +00:00
|
|
|
// NodeGetCapabilities returns RPC unknown capability.
|
2021-06-25 11:20:31 +00:00
|
|
|
func (ns *DefaultNodeServer) NodeGetCapabilities(
|
|
|
|
ctx context.Context,
|
2022-06-01 10:17:19 +00:00
|
|
|
req *csi.NodeGetCapabilitiesRequest,
|
|
|
|
) (*csi.NodeGetCapabilitiesResponse, error) {
|
2021-08-24 15:03:25 +00:00
|
|
|
log.TraceLog(ctx, "Using default NodeGetCapabilities")
|
2018-01-09 18:57:14 +00:00
|
|
|
|
2018-02-15 13:50:31 +00:00
|
|
|
return &csi.NodeGetCapabilitiesResponse{
|
|
|
|
Capabilities: []*csi.NodeServiceCapability{
|
|
|
|
{
|
|
|
|
Type: &csi.NodeServiceCapability_Rpc{
|
|
|
|
Rpc: &csi.NodeServiceCapability_RPC{
|
|
|
|
Type: csi.NodeServiceCapability_RPC_UNKNOWN,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
2018-01-09 18:57:14 +00:00
|
|
|
}
|
2018-11-26 18:23:56 +00:00
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// ConstructMountOptions returns only unique mount options in slice.
|
2020-01-23 08:24:46 +00:00
|
|
|
func ConstructMountOptions(mountOptions []string, volCap *csi.VolumeCapability) []string {
|
|
|
|
if m := volCap.GetMount(); m != nil {
|
|
|
|
hasOption := func(options []string, opt string) bool {
|
|
|
|
for _, o := range options {
|
|
|
|
if o == opt {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2020-01-23 08:24:46 +00:00
|
|
|
return false
|
|
|
|
}
|
2024-04-04 08:55:49 +00:00
|
|
|
for _, f := range m.GetMountFlags() {
|
2020-01-23 08:24:46 +00:00
|
|
|
if !hasOption(mountOptions, f) {
|
|
|
|
mountOptions = append(mountOptions, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2020-01-23 08:24:46 +00:00
|
|
|
return mountOptions
|
|
|
|
}
|
2020-04-16 14:47:43 +00:00
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// MountOptionContains checks the opt is present in mountOptions.
|
2020-04-16 14:47:43 +00:00
|
|
|
func MountOptionContains(mountOptions []string, opt string) bool {
|
|
|
|
for _, mnt := range mountOptions {
|
|
|
|
if mnt == opt {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2020-04-16 14:47:43 +00:00
|
|
|
return false
|
|
|
|
}
|