Skip to content

Commit

Permalink
Adding support to pass LeaseTime and GraceTime to nfs server
Browse files Browse the repository at this point in the history
Signed-off-by: mayank <[email protected]>
  • Loading branch information
mayank authored and kmova committed Jun 11, 2021
1 parent a1ce855 commit fe5a311
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
6 changes: 6 additions & 0 deletions deploy/kubectl/openebs-nfs-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ metadata:
value: "kernel"
#- name: BackendStorageClass
# value: "openebs-hostpath"
# LeaseTime defines the renewl period(in seconds) for client state
#- name: LeaseTime
# value: 30
# GraceTime defines the recovery period(in seconds) to reclaim locks
#- name: GraceTime
# value: 30
provisioner: openebs.io/nfsrwx
reclaimPolicy: Delete
---
16 changes: 15 additions & 1 deletion nfs-server-container/nfsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ stop()
exit
}

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
args+=( --grace-time ${NFS_GRACE_TIME})
fi

if [ ! -z ${NFS_LEASE_TIME} ]; then
args+=( --lease-time ${NFS_LEASE_TIME})
fi
}

# Check if the SHARED_DIRECTORY variable is empty
if [ -z "${SHARED_DIRECTORY}" ]; then
echo "The SHARED_DIRECTORY environment variable is unset or null, exiting..."
Expand Down Expand Up @@ -132,7 +145,8 @@ while true; do
# /usr/sbin/rpc.statd

echo "Starting NFS in the background..."
/usr/sbin/rpc.nfsd --debug 8 --no-udp --no-nfs-version 2 --no-nfs-version 3
get_nfs_args nfs_args
/usr/sbin/rpc.nfsd ${nfs_args[@]}
echo "Exporting File System..."
if /usr/sbin/exportfs -rv; then
/usr/sbin/exportfs
Expand Down
25 changes: 25 additions & 0 deletions provisioner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package provisioner

import (
"strconv"
"strings"

mconfig "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
Expand All @@ -44,6 +45,14 @@ const (
//CustomServerConfig defines the server configuration to use,
// if it is set. Otherwise, use the default NFS server configuration.
CustomServerConfig = "CustomServerConfig"

// LeaseTime defines the renewl period(in seconds) for client state
// if not set then default value(90s) will be used
LeaseTime = "LeaseTime"

// GraceTime defines the recovery period(in seconds) to reclaim locks
// If it is not set then default value(90s) will be used
GraceTime = "GraceTime"
)

const (
Expand Down Expand Up @@ -132,6 +141,22 @@ func (c *VolumeConfig) GetCustomNFSServerConfig() string {
return customServerConfig
}

func (c *VolumeConfig) GetNFSServerLeaseTime() (int, error) {
leaseTime := c.getValue(LeaseTime)
if len(strings.TrimSpace(leaseTime)) == 0 {
return 0, nil
}
return strconv.Atoi(leaseTime)
}

func (c *VolumeConfig) GetNFServerGraceTime() (int, error) {
graceTime := c.getValue(GraceTime)
if len(strings.TrimSpace(graceTime)) == 0 {
return 0, nil
}
return strconv.Atoi(graceTime)
}

//getValue is a utility function to extract the value
// of the `key` from the ConfigMap object - which is
// map[string]interface{map[string][string]}
Expand Down
18 changes: 18 additions & 0 deletions provisioner/helper_kernel_nfs_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package provisioner

import (
"strconv"

errors "github.com/pkg/errors"
"k8s.io/klog"

Expand Down Expand Up @@ -63,6 +65,14 @@ type KernelNFSServerOptions struct {
serviceName string
deploymentName string
nfsServerCustomConfig string

// leaseTime defines the renewl period(in seconds) for client state
// this should be in range from 10 to 3600 seconds
leaseTime int

// graceTime defines the recovery period(in seconds) to reclaim
// the locks and state
graceTime int
}

// validate checks that the required fields to create NFS Server
Expand Down Expand Up @@ -216,6 +226,14 @@ func (p *Provisioner) createDeployment(nfsServerOpts *KernelNFSServerOptions) er
Name: "CUSTOM_EXPORTS_CONFIG",
Value: nfsServerOpts.nfsServerCustomConfig,
},
{
Name: "NFS_LEASE_TIME",
Value: strconv.Itoa(nfsServerOpts.leaseTime),
},
{
Name: "NFS_GRACE_TIME",
Value: strconv.Itoa(nfsServerOpts.graceTime),
},
},
).
WithPortsNew(
Expand Down
18 changes: 18 additions & 0 deletions provisioner/provisioner_kernel_nfs_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,35 @@ import (
// ProvisionKernalNFSServer is invoked by the Provisioner to create a NFS
// with kernel NFS server
func (p *Provisioner) ProvisionKernalNFSServer(opts pvController.ProvisionOptions, volumeConfig *VolumeConfig) (*v1.PersistentVolume, error) {
var leaseTime, graceTime int
var leaseErr, graceErr error

pvc := opts.PVC
name := opts.PVName
capacity := opts.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]

leaseTime, leaseErr = volumeConfig.GetNFSServerLeaseTime()
graceTime, graceErr = volumeConfig.GetNFServerGraceTime()
if leaseErr != nil || graceErr != nil {
klog.Errorf("Error parsing lease/grace time, leaseError=%s graceError=%s", leaseErr, graceErr)
alertlog.Logger.Errorw("",
"eventcode", "nfs.pv.provision.failure",
"msg", "Failed to provision NFS PV",
"rname", opts.PVName,
"reason", "Parsing failed for lease/grace time",
"storagetype", "nfs-kernel",
)
}

//Extract the details to create a NFS Server
nfsServerOpts := &KernelNFSServerOptions{
pvName: name,
provisionerNS: p.namespace,
capacity: capacity.String(),
backendStorageClass: volumeConfig.GetBackendStorageClassFromConfig(),
nfsServerCustomConfig: volumeConfig.GetCustomNFSServerConfig(),
leaseTime: leaseTime,
graceTime: graceTime,
}

nfsService, err := p.getNFSServerAddress(nfsServerOpts)
Expand Down

0 comments on commit fe5a311

Please sign in to comment.