-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdriver.go
More file actions
168 lines (133 loc) · 4.74 KB
/
Copy pathdriver.go
File metadata and controls
168 lines (133 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package blockstorage
import (
"fmt"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
corev1 "k8s.io/client-go/listers/core/v1"
"k8s.io/klog/v2"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/mount"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/metadata"
"github.com/stackitcloud/cloud-provider-stackit/pkg/version"
)
const (
driverName = "block-storage.csi.stackit.cloud"
legacyDriverName = "cinder.csi.openstack.org"
topologyKey = "topology." + driverName + "/zone"
legacyTopologyKey = "topology." + legacyDriverName + "/zone"
// ResizeRequired parameter, if set to true, will trigger a resize on mount operation
ResizeRequired = driverName + "/resizeRequired"
)
var (
// CSI spec version
specVersion = "1.12.0"
Version = "1.0.0"
)
type Driver struct {
name string
fqVersion string // Fully qualified version in format {Version}@{CPO version}
endpoint string
clusterID string
legacyDriver bool
blockVolumeCreation bool
ids *identityServer
cs *controllerServer
ns *nodeServer
vcap []*csi.VolumeCapability_AccessMode
cscap []*csi.ControllerServiceCapability
nscap []*csi.NodeServiceCapability
csi.UnimplementedNodeServer
pvcLister corev1.PersistentVolumeClaimLister
}
type DriverOpts struct {
ClusterID string
Endpoint string
LegacyDriverName bool
BlockVolumeCreation bool
PVCLister corev1.PersistentVolumeClaimLister
}
func NewDriver(o *DriverOpts) *Driver {
d := &Driver{
name: driverName,
fqVersion: fmt.Sprintf("%s@%s", Version, version.Version),
endpoint: o.Endpoint,
clusterID: o.ClusterID,
pvcLister: o.PVCLister,
}
if o.LegacyDriverName {
d.name = legacyDriverName
d.legacyDriver = true
}
if o.BlockVolumeCreation {
d.blockVolumeCreation = true
}
klog.Info("Driver: ", d.name)
klog.Info("Driver version: ", d.fqVersion)
klog.Info("CSI Spec version: ", specVersion)
d.AddControllerServiceCapabilities(
[]csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME,
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES,
csi.ControllerServiceCapability_RPC_GET_VOLUME,
})
d.AddVolumeCapabilityAccessModes(
[]csi.VolumeCapability_AccessMode_Mode{
csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
})
// ignoring error, because AddNodeServiceCapabilities is public
// and so potentially used somewhere else.
_ = d.AddNodeServiceCapabilities(
[]csi.NodeServiceCapability_RPC_Type{
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
csi.NodeServiceCapability_RPC_EXPAND_VOLUME,
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
})
d.ids = NewIdentityServer(d)
return d
}
func (d *Driver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapability_RPC_Type) {
csc := make([]*csi.ControllerServiceCapability, 0, len(cl))
for _, c := range cl {
klog.Infof("Enabling controller service capability: %v", c.String())
csc = append(csc, NewControllerServiceCapability(c))
}
d.cscap = csc
}
func (d *Driver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode {
vca := make([]*csi.VolumeCapability_AccessMode, 0, len(vc))
for _, c := range vc {
klog.Infof("Enabling volume access mode: %v", c.String())
vca = append(vca, NewVolumeCapabilityAccessMode(c))
}
d.vcap = vca
return vca
}
func (d *Driver) AddNodeServiceCapabilities(nl []csi.NodeServiceCapability_RPC_Type) error {
nsc := make([]*csi.NodeServiceCapability, 0, len(nl))
for _, n := range nl {
klog.Infof("Enabling node service capability: %v", n.String())
nsc = append(nsc, NewNodeServiceCapability(n))
}
d.nscap = nsc
return nil
}
func (d *Driver) SetupControllerService(instance stackit.IaasClient) {
klog.Info("Providing controller service")
d.cs = NewControllerServer(d, instance)
}
func (d *Driver) SetupNodeService(mountProvider mount.IMount, metadataProvider metadata.IMetadata, opts stackitconfig.BlockStorageOpts) {
klog.Info("Providing node service")
d.ns = NewNodeServer(d, mountProvider, metadataProvider, opts)
}
func (d *Driver) Run() {
if d.cs == nil && d.ns == nil {
klog.Fatal("No CSI services initialized")
}
RunServicesInitialized(d.endpoint, d.ids, d.cs, d.ns)
}