Skip to content

Commit 9877349

Browse files
authored
chore(backendPvcTimeout): option to configure BackendPvcTimeout using env Var (#84)
* chore(backendPvcTimeout): configure backendPvcTimeout through env var OPENEBS_IO_NFS_SERVER_BACKEND_PVC_TIMEOUT * unit test to verify backendPvcTimeout value * updating helm chart and deployment yaml to configure backendPvcTimeout Signed-off-by: mayank <[email protected]>
1 parent de87a90 commit 9877349

File tree

9 files changed

+73
-18
lines changed

9 files changed

+73
-18
lines changed

deploy/helm/charts/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Helm chart for OpenEBS Dynamic NFS PV. For instructions to install
44
type: application
55
# This is the chart version. This version number should be incremented each time you make changes
66
# to the chart and its templates, including the app version.
7-
version: 0.5.0
7+
version: 0.5.1
88
# This is the version number of the application being deployed. This version number should be
99
# incremented each time you make changes to the application.
1010
appVersion: 0.5.0

deploy/helm/charts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ helm install openebs-nfs openebs-nfs/nfs-provisioner --namespace openebs --creat
129129
| `nfsProvisioner.tolerations` | NFS Provisioner pod toleration values | `""` |
130130
| `nfsProvisioner.nfsServerNamespace` | NFS server namespace | `"openebs"` |
131131
| `nfsProvisioner.nfsServerNodeAffinity` | NFS Server node affinity rules | `""` |
132+
| `nfsProvisioner.nfsBackendPvcTimeout` | Timeout for backend PVC binding in seconds | `"60"` |
132133
| `nfsStorageClass.backendStorageClass` | StorageClass to be used to provision the backend volume. If not specified, the default StorageClass is used. | `""` |
133134
| `nfsStorageClass.isDefaultClass` | Make 'openebs-kernel-nfs' the default StorageClass | `"false"` |
134135
| `nfsStorageClass.reclaimPolicy` | ReclaimPolicy for NFS PVs | `"Delete"` |

deploy/helm/charts/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ spec:
9999
- name: OPENEBS_IO_NFS_SERVER_NODE_AFFINITY
100100
value: "{{ .Values.nfsProvisioner.nfsServerNodeAffinity }}"
101101
{{- end }}
102+
{{- if .Values.nfsProvisioner.nfsBackendPvcTimeout }}
103+
- name: OPENEBS_IO_NFS_SERVER_BACKEND_PVC_TIMEOUT
104+
value: "{{ .Values.nfsProvisioner.nfsBackendPvcTimeout }}"
105+
{{- end }}
102106
# Process name used for matching is limited to the 15 characters
103107
# present in the pgrep output.
104108
# So fullname can't be used here with pgrep (>15 chars).A regular expression

deploy/kubectl/openebs-nfs-provisioner.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ spec:
143143
# leader election is enabled.
144144
#- name: LEADER_ELECTION_ENABLED
145145
# value: "true"
146+
# Set Timeout for backend PVC to bound, Default value is 60 seconds
147+
#- name: OPENEBS_IO_NFS_SERVER_BACKEND_PVC_TIMEOUT
148+
# value: "60"
146149
# Process name used for matching is limited to the 15 characters
147150
# present in the pgrep output.
148151
# So fullname can't be used here with pgrep (>15 chars).A regular expression

provisioner/env.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
menv "github.com/openebs/maya/pkg/env/v1alpha1"
2121
)
2222

23-
//This file defines the environement variable names that are specific
23+
//This file defines the environment variable names that are specific
2424
// to this provisioner. In addition to the variables defined in this file,
2525
// provisioner also uses the following:
2626
// OPENEBS_NAMESPACE
@@ -54,6 +54,9 @@ const (
5454

5555
// NodeAffinityKey holds the env name representing Node affinity rules
5656
NodeAffinityKey menv.ENVKey = "OPENEBS_IO_NFS_SERVER_NODE_AFFINITY"
57+
58+
// NFSBackendPvcTimeout defines env name to store BackendPvcBoundTimeout value
59+
NFSBackendPvcTimeout menv.ENVKey = "OPENEBS_IO_NFS_SERVER_BACKEND_PVC_TIMEOUT"
5760
)
5861

5962
var (
@@ -94,3 +97,7 @@ func getNFSServerImage() string {
9497
func getNfsServerNodeAffinity() string {
9598
return menv.Get(NodeAffinityKey)
9699
}
100+
101+
func getBackendPvcTimeout() string {
102+
return menv.Get(NFSBackendPvcTimeout)
103+
}

provisioner/helper_kernel_nfs_server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ const (
5353
//RPCBindPort set the RPC Bind Port
5454
RPCBindPort = 111
5555

56-
// BackendPvcBoundTimeout defines the timeout for PVC Bound check
56+
// DefaultBackendPvcBoundTimeout defines the timeout for PVC Bound check.
5757
// set to 60 seconds
58-
BackendPvcBoundTimeout = 60 * time.Second
58+
DefaultBackendPvcBoundTimeout = 60
5959
)
6060

6161
var (
@@ -423,7 +423,7 @@ func (p *Provisioner) deleteService(nfsServerOpts *KernelNFSServerOptions) error
423423
svcName := "nfs-" + nfsServerOpts.pvName
424424
klog.V(4).Infof("Verifying if Service(%v) for NFS storage exists.", svcName)
425425

426-
//Check if the Serivce still exists. It could have been removed
426+
//Check if the Service still exists. It could have been removed
427427
// or never created due to a provisioning create failure.
428428
_, err := p.kubeClient.CoreV1().
429429
Services(p.serverNamespace).
@@ -493,7 +493,7 @@ func (p *Provisioner) createNFSServer(nfsServerOpts *KernelNFSServerOptions) err
493493
return errors.Wrapf(err, "failed to initialize NFS Storage Deployment for RWX PVC{%v}", nfsServerOpts.pvName)
494494
}
495495

496-
err = waitForPvcBound(p.kubeClient, p.serverNamespace, "nfs-"+nfsServerOpts.pvName, BackendPvcBoundTimeout)
496+
err = waitForPvcBound(p.kubeClient, p.serverNamespace, "nfs-"+nfsServerOpts.pvName, p.backendPvcTimeout)
497497
if err != nil {
498498
return err
499499
}

provisioner/helper_kernel_nfs_server_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"testing"
23+
"time"
2324

2425
errors "github.com/pkg/errors"
2526
"github.com/stretchr/testify/assert"
@@ -655,8 +656,9 @@ func TestGetNFSServerAddress(t *testing.T) {
655656
backendStorageClass: "test1-sc",
656657
},
657658
provisioner: &Provisioner{
658-
kubeClient: fake.NewSimpleClientset(),
659-
serverNamespace: "nfs-server-ns1",
659+
kubeClient: fake.NewSimpleClientset(),
660+
serverNamespace: "nfs-server-ns1",
661+
backendPvcTimeout: 60 * time.Second,
660662
},
661663
expectedServiceIP: "nfs-test1-pv.nfs-server-ns1.svc.cluster.local",
662664
shouldBoundBackendPvc: true,
@@ -670,9 +672,10 @@ func TestGetNFSServerAddress(t *testing.T) {
670672
backendStorageClass: "test2-sc",
671673
},
672674
provisioner: &Provisioner{
673-
kubeClient: fake.NewSimpleClientset(),
674-
serverNamespace: "nfs-server-ns2",
675-
useClusterIP: true,
675+
kubeClient: fake.NewSimpleClientset(),
676+
serverNamespace: "nfs-server-ns2",
677+
useClusterIP: true,
678+
backendPvcTimeout: 60 * time.Second,
676679
},
677680
// Since we are using fake clients there won't be ClusterIP on service
678681
// so expecting for empty value
@@ -688,9 +691,30 @@ func TestGetNFSServerAddress(t *testing.T) {
688691
backendStorageClass: "test3-sc",
689692
},
690693
provisioner: &Provisioner{
691-
kubeClient: fake.NewSimpleClientset(),
692-
serverNamespace: "nfs-server-ns3",
693-
useClusterIP: false,
694+
kubeClient: fake.NewSimpleClientset(),
695+
serverNamespace: "nfs-server-ns3",
696+
useClusterIP: false,
697+
backendPvcTimeout: 60 * time.Second,
698+
},
699+
// Since we are using fake clients there won't be ClusterIP on service
700+
// so expecting for empty value
701+
expectedServiceIP: "",
702+
isErrExpected: true,
703+
shouldBoundBackendPvc: false,
704+
},
705+
"when provisioner configured with very low backendPvcTimeout value": {
706+
// NOTE: Populated only fields required for test
707+
options: &KernelNFSServerOptions{
708+
provisionerNS: "openebs",
709+
pvName: "test3-pv",
710+
capacity: "5G",
711+
backendStorageClass: "test3-sc",
712+
},
713+
provisioner: &Provisioner{
714+
kubeClient: fake.NewSimpleClientset(),
715+
serverNamespace: "nfs-server-ns3",
716+
useClusterIP: false,
717+
backendPvcTimeout: 1 * time.Second,
694718
},
695719
// Since we are using fake clients there won't be ClusterIP on service
696720
// so expecting for empty value

provisioner/provisioner.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ package provisioner
3333

3434
import (
3535
"fmt"
36+
"strconv"
3637
"strings"
38+
"time"
3739

3840
"github.com/openebs/maya/pkg/alertlog"
3941

@@ -67,6 +69,14 @@ func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset) (*Pro
6769
if len(strings.TrimSpace(namespace)) == 0 {
6870
return nil, fmt.Errorf("Cannot start Provisioner: failed to get namespace")
6971
}
72+
73+
backendPvcTimeoutStr := getBackendPvcTimeout()
74+
backendPvcTimeoutVal, err := strconv.Atoi(backendPvcTimeoutStr)
75+
if err != nil || backendPvcTimeoutVal == 0 {
76+
klog.Warningf("Invalid backendPvcTimeout value=%s, using default value %d", backendPvcTimeoutStr, DefaultBackendPvcBoundTimeout)
77+
backendPvcTimeoutVal = DefaultBackendPvcBoundTimeout
78+
}
79+
7080
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, 0)
7181
k8sNodeInformer := kubeInformerFactory.Core().V1().Nodes().Informer()
7282

@@ -86,10 +96,11 @@ func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset) (*Pro
8696
Value: getDefaultNFSServerType(),
8797
},
8898
},
89-
useClusterIP: menv.Truthy(ProvisionerNFSServerUseClusterIP),
90-
k8sNodeLister: listersv1.NewNodeLister(k8sNodeInformer.GetIndexer()),
91-
nodeAffinity: getNodeAffinityRules(),
92-
pvTracker: pvTracker,
99+
useClusterIP: menv.Truthy(ProvisionerNFSServerUseClusterIP),
100+
k8sNodeLister: listersv1.NewNodeLister(k8sNodeInformer.GetIndexer()),
101+
nodeAffinity: getNodeAffinityRules(),
102+
pvTracker: pvTracker,
103+
backendPvcTimeout: time.Duration(backendPvcTimeoutVal) * time.Second,
93104
}
94105
p.getVolumeConfig = p.GetVolumeConfig
95106

provisioner/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ limitations under the License.
1818
package provisioner
1919

2020
import (
21+
"time"
22+
2123
mconfig "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
2224
corev1 "k8s.io/api/core/v1"
2325
clientset "k8s.io/client-go/kubernetes"
@@ -57,6 +59,9 @@ type Provisioner struct {
5759

5860
// pvTracker to track in-progress provisioning request
5961
pvTracker ProvisioningTracker
62+
63+
// backendPvcTimeout defines timeout for backend PVC Bound check
64+
backendPvcTimeout time.Duration
6065
}
6166

6267
//VolumeConfig struct contains the merged configuration of the PVC

0 commit comments

Comments
 (0)