...
1
16
17 package flexvolume
18
19 import (
20 "os"
21 "strconv"
22
23 "k8s.io/kubernetes/pkg/volume"
24 "k8s.io/kubernetes/pkg/volume/util"
25 "k8s.io/utils/exec"
26 )
27
28
29 type flexVolumeMounter struct {
30 *flexVolume
31
32 runner exec.Interface
33
34 spec *volume.Spec
35 readOnly bool
36 }
37
38 var _ volume.Mounter = &flexVolumeMounter{}
39
40
41
42
43 func (f *flexVolumeMounter) SetUp(mounterArgs volume.MounterArgs) error {
44 return f.SetUpAt(f.GetPath(), mounterArgs)
45 }
46
47
48 func (f *flexVolumeMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
49
50 alreadyMounted, err := prepareForMount(f.mounter, dir)
51 if err != nil {
52 return err
53 }
54 if alreadyMounted {
55 return nil
56 }
57
58 call := f.plugin.NewDriverCall(mountCmd)
59
60
61 call.Append(dir)
62
63 extraOptions := make(map[string]string)
64
65
66 extraOptions[optionKeyPodName] = f.podName
67 extraOptions[optionKeyPodNamespace] = f.podNamespace
68 extraOptions[optionKeyPodUID] = string(f.podUID)
69
70 extraOptions[optionKeyServiceAccountName] = f.podServiceAccountName
71
72
73 if err := addSecretsToOptions(extraOptions, f.spec, f.podNamespace, f.driverName, f.plugin.host); err != nil {
74 os.Remove(dir)
75 return err
76 }
77
78
79 if mounterArgs.FsGroup != nil {
80 extraOptions[optionFSGroup] = strconv.FormatInt(int64(*mounterArgs.FsGroup), 10)
81 }
82
83 call.AppendSpec(f.spec, f.plugin.host, extraOptions)
84
85 _, err = call.Run()
86 if isCmdNotSupportedErr(err) {
87 err = (*mounterDefaults)(f).SetUpAt(dir, mounterArgs)
88 }
89
90 if err != nil {
91 os.Remove(dir)
92 return err
93 }
94
95 if !f.readOnly {
96 if f.plugin.capabilities.FSGroup {
97
98 volume.SetVolumeOwnership(f, dir, mounterArgs.FsGroup, mounterArgs.FSGroupChangePolicy, util.FSGroupCompleteHook(f.plugin, f.spec))
99 }
100 }
101
102 return nil
103 }
104
105
106
107 func (f *flexVolumeMounter) GetAttributes() volume.Attributes {
108 return (*mounterDefaults)(f).GetAttributes()
109 }
110
View as plain text