Skip to content

Commit a294df6

Browse files
[cinder-csi-plugin] ephemeral volume removal (#2602) (#2640)
Remove openstack credits from node plugin Signed-off-by: Serge Logvinov <[email protected]>
1 parent 333a126 commit a294df6

File tree

17 files changed

+104
-340
lines changed

17 files changed

+104
-340
lines changed

charts/cinder-csi-plugin/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
appVersion: v1.31.0
33
description: Cinder CSI Chart for OpenStack
44
name: openstack-cinder-csi
5-
version: 2.31.0
5+
version: 2.31.2
66
home: https://github.com/kubernetes/cloud-provider-openstack
77
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
88
maintainers:

charts/cinder-csi-plugin/templates/controllerplugin-deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ spec:
173173
- "--endpoint=$(CSI_ENDPOINT)"
174174
- "--cloud-config=$(CLOUD_CONFIG)"
175175
- "--cluster=$(CLUSTER_NAME)"
176+
- "--provide-node-service=false"
176177
{{- if .Values.csi.plugin.httpEndpoint.enabled }}
177178
- "--http-endpoint=:{{ .Values.csi.plugin.httpEndpoint.port }}"
178179
{{- end }}

charts/cinder-csi-plugin/templates/nodeplugin-daemonset.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ spec:
9191
- /bin/cinder-csi-plugin
9292
- "-v={{ .Values.logVerbosityLevel }}"
9393
- "--endpoint=$(CSI_ENDPOINT)"
94+
- "--provide-controller-service=false"
9495
- "--cloud-config=$(CLOUD_CONFIG)"
9596
{{- if .Values.csi.plugin.extraArgs }}
9697
{{- with .Values.csi.plugin.extraArgs }}

cmd/cinder-csi-plugin/main.go

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"fmt"
2021
"os"
2122

2223
"github.com/spf13/cobra"
@@ -50,6 +51,24 @@ func main() {
5051
Run: func(cmd *cobra.Command, args []string) {
5152
handle()
5253
},
54+
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
55+
f := cmd.Flags()
56+
57+
if !provideControllerService {
58+
return nil
59+
}
60+
61+
configs, err := f.GetStringSlice("cloud-config")
62+
if err != nil {
63+
return err
64+
}
65+
66+
if len(configs) == 0 {
67+
return fmt.Errorf("unable to mark flag cloud-config to be required")
68+
}
69+
70+
return nil
71+
},
5372
Version: version.Version,
5473
}
5574

@@ -63,10 +82,7 @@ func main() {
6382
klog.Fatalf("Unable to mark flag endpoint to be required: %v", err)
6483
}
6584

66-
cmd.PersistentFlags().StringSliceVar(&cloudConfig, "cloud-config", nil, "CSI driver cloud config. This option can be given multiple times")
67-
if err := cmd.MarkPersistentFlagRequired("cloud-config"); err != nil {
68-
klog.Fatalf("Unable to mark flag cloud-config to be required: %v", err)
69-
}
85+
cmd.Flags().StringSliceVar(&cloudConfig, "cloud-config", nil, "CSI driver cloud config. This option can be given multiple times")
7086

7187
cmd.PersistentFlags().StringSliceVar(&cloudNames, "cloud-name", []string{""}, "Cloud name to instruct CSI driver to read additional OpenStack cloud credentials from the configuration subsections. This option can be specified multiple times to manage multiple OpenStack clouds.")
7288
cmd.PersistentFlags().StringToStringVar(&additionalTopologies, "additional-topology", map[string]string{}, "Additional CSI driver topology keys, for example topology.kubernetes.io/region=REGION1. This option can be specified multiple times to add multiple additional topology keys.")
@@ -77,6 +93,7 @@ func main() {
7793
cmd.PersistentFlags().BoolVar(&provideControllerService, "provide-controller-service", true, "If set to true then the CSI driver does provide the controller service (default: true)")
7894
cmd.PersistentFlags().BoolVar(&provideNodeService, "provide-node-service", true, "If set to true then the CSI driver does provide the node service (default: true)")
7995
cmd.PersistentFlags().BoolVar(&noClient, "node-service-no-os-client", false, "If set to true then the CSI driver node service will not use the OpenStack client (default: false)")
96+
cmd.PersistentFlags().MarkDeprecated("node-service-no-os-client", "This flag is deprecated and will be removed in the future. Node service do not use OpenStack credentials anymore.") //nolint:errcheck
8097

8198
openstack.AddExtraFlags(pflag.CommandLine)
8299

@@ -94,7 +111,7 @@ func handle() {
94111
var err error
95112
clouds := make(map[string]openstack.IOpenStack)
96113
for _, cloudName := range cloudNames {
97-
clouds[cloudName], err = openstack.GetOpenStackProvider(cloudName, false)
114+
clouds[cloudName], err = openstack.GetOpenStackProvider(cloudName)
98115
if err != nil {
99116
klog.Warningf("Failed to GetOpenStackProvider %s: %v", cloudName, err)
100117
return
@@ -105,23 +122,19 @@ func handle() {
105122
}
106123

107124
if provideNodeService {
108-
var err error
109-
clouds := make(map[string]openstack.IOpenStack)
110-
for _, cloudName := range cloudNames {
111-
clouds[cloudName], err = openstack.GetOpenStackProvider(cloudName, noClient)
112-
if err != nil {
113-
klog.Warningf("Failed to GetOpenStackProvider %s: %v", cloudName, err)
114-
return
115-
}
116-
}
117-
118125
//Initialize mount
119126
mount := mount.GetMountProvider()
120127

128+
cfg, err := openstack.GetConfigFromFiles(cloudConfig)
129+
if err != nil && !os.IsNotExist(err) {
130+
klog.Warningf("Failed to GetConfigFromFiles: %v", err)
131+
return
132+
}
133+
121134
//Initialize Metadata
122-
metadata := metadata.GetMetadataProvider(clouds[cloudNames[0]].GetMetadataOpts().SearchOrder)
135+
metadata := metadata.GetMetadataProvider(cfg.Metadata.SearchOrder)
123136

124-
d.SetupNodeService(clouds[cloudNames[0]], mount, metadata, additionalTopologies)
137+
d.SetupNodeService(mount, metadata, cfg.BlockStorage, additionalTopologies)
125138
}
126139

127140
d.Run()

docs/cinder-csi-plugin/using-cinder-csi-plugin.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,6 @@ In addition to the standard set of klog flags, `cinder-csi-plugin` accepts the f
111111

112112
The default is to provide the node service.
113113
</dd>
114-
115-
<dt>--node-service-no-os-client &lt;disabled&gt;</dt>
116-
<dd>
117-
If set to true then the CSI driver does not provide the OpenStack client in the node service.
118-
119-
The default is to provide the OpenStack client in the node service.
120-
</dd>
121114
</dl>
122115

123116
## Driver Config
@@ -277,7 +270,7 @@ helm install --namespace kube-system --name cinder-csi ./charts/cinder-csi-plugi
277270
| VolumeSnapshotClass `parameters` | `type` | Empty String | `snapshot` creates a VolumeSnapshot object linked to a Cinder volume snapshot. `backup` creates a VolumeSnapshot object linked to a cinder volume backup. Defaults to `snapshot` if not defined |
278271
| VolumeSnapshotClass `parameters` | `backup-max-duration-seconds-per-gb` | `20` | Defines the amount of time to wait for a backup to complete in seconds per GB of volume size |
279272
| VolumeSnapshotClass `parameters` | `availability` | Same as volume | String. Backup Availability Zone |
280-
| Inline Volume `volumeAttributes` | `capacity` | `1Gi` | volume size for creating inline volumes|
273+
| Inline Volume `volumeAttributes` | `capacity` | `1Gi` | volume size for creating inline volumes|
281274
| Inline Volume `VolumeAttributes` | `type` | Empty String | Name/ID of Volume type. Corresponding volume type should exist in cinder |
282275

283276
## Local Development

manifests/cinder-csi-plugin/cinder-csi-nodeplugin.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ spec:
5757
args:
5858
- /bin/cinder-csi-plugin
5959
- "--endpoint=$(CSI_ENDPOINT)"
60+
- "--provide-controller-service=false"
6061
- "--cloud-config=$(CLOUD_CONFIG)"
6162
- "--v=1"
6263
env:

pkg/csi/cinder/controllerserver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,11 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
10611061
func getCreateVolumeResponse(vol *volumes.Volume, ignoreVolumeAZ bool, accessibleTopologyReq *csi.TopologyRequirement) *csi.CreateVolumeResponse {
10621062

10631063
var volsrc *csi.VolumeContentSource
1064+
volCnx := map[string]string{}
10641065

10651066
if vol.SnapshotID != "" {
1067+
volCnx[ResizeRequired] = "true"
1068+
10661069
volsrc = &csi.VolumeContentSource{
10671070
Type: &csi.VolumeContentSource_Snapshot{
10681071
Snapshot: &csi.VolumeContentSource_SnapshotSource{
@@ -1073,6 +1076,8 @@ func getCreateVolumeResponse(vol *volumes.Volume, ignoreVolumeAZ bool, accessibl
10731076
}
10741077

10751078
if vol.SourceVolID != "" {
1079+
volCnx[ResizeRequired] = "true"
1080+
10761081
volsrc = &csi.VolumeContentSource{
10771082
Type: &csi.VolumeContentSource_Volume{
10781083
Volume: &csi.VolumeContentSource_VolumeSource{
@@ -1083,6 +1088,8 @@ func getCreateVolumeResponse(vol *volumes.Volume, ignoreVolumeAZ bool, accessibl
10831088
}
10841089

10851090
if vol.BackupID != nil && *vol.BackupID != "" {
1091+
volCnx[ResizeRequired] = "true"
1092+
10861093
volsrc = &csi.VolumeContentSource{
10871094
Type: &csi.VolumeContentSource_Snapshot{
10881095
Snapshot: &csi.VolumeContentSource_SnapshotSource{
@@ -1113,9 +1120,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, ignoreVolumeAZ bool, accessibl
11131120
CapacityBytes: int64(vol.Size * 1024 * 1024 * 1024),
11141121
AccessibleTopology: accessibleTopology,
11151122
ContentSource: volsrc,
1123+
VolumeContext: volCnx,
11161124
},
11171125
}
11181126

11191127
return resp
1120-
11211128
}

pkg/csi/cinder/driver.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ import (
3232
const (
3333
driverName = "cinder.csi.openstack.org"
3434
topologyKey = "topology." + driverName + "/zone"
35+
36+
// maxVolumesPerNode is the maximum number of volumes that can be attached to a node
37+
maxVolumesPerNode = 256
38+
39+
// ResizeRequired parameter, if set to true, will trigger a resize on mount operation
40+
ResizeRequired = driverName + "/resizeRequired"
3541
)
3642

3743
var (
@@ -177,9 +183,9 @@ func (d *Driver) SetupControllerService(clouds map[string]openstack.IOpenStack)
177183
d.cs = NewControllerServer(d, clouds)
178184
}
179185

180-
func (d *Driver) SetupNodeService(cloud openstack.IOpenStack, mount mount.IMount, metadata metadata.IMetadata, topologies map[string]string) {
186+
func (d *Driver) SetupNodeService(mount mount.IMount, metadata metadata.IMetadata, opts openstack.BlockStorageOpts, topologies map[string]string) {
181187
klog.Info("Providing node service")
182-
d.ns = NewNodeServer(d, mount, metadata, cloud, topologies)
188+
d.ns = NewNodeServer(d, mount, metadata, opts, topologies)
183189
}
184190

185191
func (d *Driver) Run() {

0 commit comments

Comments
 (0)