diff --git a/deploy/kubectl/openebs-nfs-provisioner.yaml b/deploy/kubectl/openebs-nfs-provisioner.yaml index 7d57fbe..a6d21ef 100644 --- a/deploy/kubectl/openebs-nfs-provisioner.yaml +++ b/deploy/kubectl/openebs-nfs-provisioner.yaml @@ -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 --- diff --git a/nfs-server-container/nfsd.sh b/nfs-server-container/nfsd.sh index 89e57c2..b7f53a2 100644 --- a/nfs-server-container/nfsd.sh +++ b/nfs-server-container/nfsd.sh @@ -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..." @@ -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 diff --git a/provisioner/config.go b/provisioner/config.go index d06b521..ec196de 100644 --- a/provisioner/config.go +++ b/provisioner/config.go @@ -18,6 +18,7 @@ limitations under the License. package provisioner import ( + "strconv" "strings" mconfig "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1" @@ -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 ( @@ -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]} diff --git a/provisioner/helper_kernel_nfs_server.go b/provisioner/helper_kernel_nfs_server.go index 5d526f9..24c7bd8 100644 --- a/provisioner/helper_kernel_nfs_server.go +++ b/provisioner/helper_kernel_nfs_server.go @@ -17,6 +17,8 @@ limitations under the License. package provisioner import ( + "strconv" + errors "github.com/pkg/errors" "k8s.io/klog" @@ -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 @@ -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( diff --git a/provisioner/provisioner_kernel_nfs_server.go b/provisioner/provisioner_kernel_nfs_server.go index 1af1f56..696c0bc 100644 --- a/provisioner/provisioner_kernel_nfs_server.go +++ b/provisioner/provisioner_kernel_nfs_server.go @@ -30,10 +30,26 @@ 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, @@ -41,6 +57,8 @@ func (p *Provisioner) ProvisionKernalNFSServer(opts pvController.ProvisionOption capacity: capacity.String(), backendStorageClass: volumeConfig.GetBackendStorageClassFromConfig(), nfsServerCustomConfig: volumeConfig.GetCustomNFSServerConfig(), + leaseTime: leaseTime, + graceTime: graceTime, } nfsService, err := p.getNFSServerAddress(nfsServerOpts)