From 489da0d163488c91324fabe6215554b873d7b260 Mon Sep 17 00:00:00 2001 From: mayank Date: Mon, 14 Jun 2021 17:02:39 +0530 Subject: [PATCH] - updating nfsd.sh to ignore unbound value error - updating provisioner-nfs to use default 90s for grace/lease time Signed-off-by: mayank --- nfs-server-container/nfsd.sh | 6 ++++-- provisioner/config.go | 30 ++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/nfs-server-container/nfsd.sh b/nfs-server-container/nfsd.sh index b7f53a2..2e1da5f 100644 --- a/nfs-server-container/nfsd.sh +++ b/nfs-server-container/nfsd.sh @@ -35,11 +35,13 @@ get_nfs_args() { declare -n args=$1 args=(--debug 8 --no-udp --no-nfs-version 2 --no-nfs-version 3) - if [ ! -z ${NFS_GRACE_TIME} ]; then + + # here we are checking if variable exist and its value is not null + if [ ! -z ${NFS_GRACE_TIME:+x} ]; then args+=( --grace-time ${NFS_GRACE_TIME}) fi - if [ ! -z ${NFS_LEASE_TIME} ]; then + if [ ! -z ${NFS_LEASE_TIME:+x} ]; then args+=( --lease-time ${NFS_LEASE_TIME}) fi } diff --git a/provisioner/config.go b/provisioner/config.go index ec196de..a3711b5 100644 --- a/provisioner/config.go +++ b/provisioner/config.go @@ -48,11 +48,13 @@ const ( // LeaseTime defines the renewl period(in seconds) for client state // if not set then default value(90s) will be used - LeaseTime = "LeaseTime" + LeaseTime = "LeaseTime" + DefaultLeaseTime = 90 // GraceTime defines the recovery period(in seconds) to reclaim locks // If it is not set then default value(90s) will be used - GraceTime = "GraceTime" + GraceTime = "GraceTime" + DefaultGraceTime = 90 ) const ( @@ -144,17 +146,33 @@ func (c *VolumeConfig) GetCustomNFSServerConfig() string { func (c *VolumeConfig) GetNFSServerLeaseTime() (int, error) { leaseTime := c.getValue(LeaseTime) if len(strings.TrimSpace(leaseTime)) == 0 { - return 0, nil + return DefaultLeaseTime, nil } - return strconv.Atoi(leaseTime) + leaseTimeVal, err := strconv.Atoi(leaseTime) + if err != nil { + return 0, err + } + if leaseTimeVal == 0 { + leaseTimeVal = DefaultLeaseTime + } + + return leaseTimeVal, nil } func (c *VolumeConfig) GetNFServerGraceTime() (int, error) { graceTime := c.getValue(GraceTime) if len(strings.TrimSpace(graceTime)) == 0 { - return 0, nil + return DefaultGraceTime, nil + } + graceTimeVal, err := strconv.Atoi(graceTime) + if err != nil { + return 0, err + } + + if graceTimeVal == 0 { + graceTimeVal = DefaultGraceTime } - return strconv.Atoi(graceTime) + return graceTimeVal, nil } //getValue is a utility function to extract the value