Skip to content

Commit 338e5d6

Browse files
committed
Update example to expose the fs-group volume attribute
Signed-off-by: joshvanl <[email protected]>
1 parent 62ced5a commit 338e5d6

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

example/main.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"fmt"
2929
"net"
3030
"net/url"
31-
"strconv"
3231
"strings"
3332
"time"
3433

@@ -65,10 +64,12 @@ const (
6564

6665
RenewBeforeKey string = "csi.cert-manager.io/renew-before"
6766
ReusePrivateKey string = "csi.cert-manager.io/reuse-private-key"
67+
)
6868

69-
// fs-user is used to optionally set the UID ownership of the volume's files.
70-
// Useful when running containers with a specified user.
71-
FsUserKey string = "csi.cert-manager.io/fs-user"
69+
var (
70+
// fs-group is used to optionally set the GID ownership of the volume's
71+
// files. Useful when running containers with a specified user and group.
72+
FsGroupKey string = "csi.cert-manager.io/fs-group"
7273
)
7374

7475
var (
@@ -102,6 +103,8 @@ func main() {
102103
panic("failed to setup filesystem: " + err.Error())
103104
}
104105

106+
store.FSGroupVolumeAttributeKey = &FsGroupKey
107+
105108
d, err := driver.New(*endpoint, log, driver.Options{
106109
DriverName: "csi.cert-manager.io",
107110
DriverVersion: "v0.0.1",
@@ -255,21 +258,11 @@ func (w *writer) writeKeypair(meta metadata.Metadata, key crypto.PrivateKey, cha
255258
return fmt.Errorf("calculating next issuance time: %w", err)
256259
}
257260

258-
var fsUser *int64
259-
fsUserStr, ok := meta.VolumeContext[FsUserKey]
260-
if ok {
261-
i, err := strconv.ParseInt(fsUserStr, 10, 64)
262-
if err != nil {
263-
return fmt.Errorf("failed to parse %q, value must be a valid integer: %w", FsUserKey, err)
264-
}
265-
fsUser = &i
266-
}
267-
268-
if err := w.store.WriteFiles(meta.VolumeID, map[string][]byte{
261+
if err := w.store.WriteFiles(meta, map[string][]byte{
269262
pkFile: keyPEM,
270263
crtFile: chain,
271264
caFile: ca,
272-
}, fsUser); err != nil {
265+
}); err != nil {
273266
return fmt.Errorf("writing data: %w", err)
274267
}
275268

0 commit comments

Comments
 (0)