From 9e29ab985b70ca76cddcdabfadfba70d392d52c8 Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Mon, 23 Jul 2018 20:31:35 +0530 Subject: [PATCH] Provide an option to supply log-file mount option for gluster plugin. At present, `log-file` location of glusterfs client mount is decided by the plugin, however at times, users/admin want to configure log-file of gluster fuse client process on their own in some setups. Even though they can pass log-file mount option through storage class, before this patch glusterfs plugin always discard it. This patch enable/give preference to admin supplied log-file mount option if specified in storage class. If the log-file mount option is incomplete or wrong, plugin fallback to the location which is carved out by the combination of pvc and pod name. Signed-off-by: Humble Chirammal --- pkg/volume/glusterfs/glusterfs.go | 37 +++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 3577e8f215..39f6d91694 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -288,23 +288,42 @@ func (c *glusterfsUnmounter) TearDownAt(dir string) error { func (b *glusterfsMounter) setUpAtInternal(dir string) error { var errs error - options := []string{} + hasLogFile := false + log := "" + if b.readOnly { options = append(options, "ro") + } - p := path.Join(b.glusterfs.plugin.host.GetPluginDir(glusterfsPluginName), b.glusterfs.volName) - if err := os.MkdirAll(p, 0750); err != nil { - return fmt.Errorf("failed to create directory %v: %v", p, err) + // Check logfile has been provided by user, if provided, use that as the log file. + for _, userOpt := range b.mountOptions { + if dstrings.HasPrefix(userOpt, "log-file") { + glog.V(4).Infof("log-file mount option has provided") + hasLogFile = true + break + } } - // adding log-level ERROR to remove noise - // and more specific log path so each pod has - // its own log based on PV + Pod - log := path.Join(p, b.pod.Name+"-glusterfs.log") - options = append(options, "log-level=ERROR") + // If logfile has not been provided, create driver specific log file. + if !hasLogFile { + log = "" + p := path.Join(b.glusterfs.plugin.host.GetPluginDir(glusterfsPluginName), b.glusterfs.volName) + if err := os.MkdirAll(p, 0750); err != nil { + return fmt.Errorf("failed to create directory %v: %v", p, err) + } + + // adding log-level ERROR to remove noise + // and more specific log path so each pod has + // its own log based on PV + Pod + log = path.Join(p, b.pod.Name+"-glusterfs.log") + + } + + // Use derived/provided log file in gluster fuse mount options = append(options, "log-file="+log) + options = append(options, "log-level=ERROR") var addrlist []string if b.hosts == nil {