diff --git a/provisioner.go b/provisioner.go index 7b98861305dd741b41eec7276208f9c29823ee43..e85708db11ab217682cbf1bac94890c5dd14e175 100644 --- a/provisioner.go +++ b/provisioner.go @@ -41,9 +41,11 @@ const ( envVolSize = "VOL_SIZE_BYTES" ) -var ( - CmdTimeoutCounts = 120 +const ( + defaultCmdTimeoutSeconds = 120 +) +var ( ConfigFileCheckInterval = 30 * time.Second HelperPodNameMaxLength = 128 @@ -71,6 +73,8 @@ type NodePathMapData struct { type ConfigData struct { NodePathMap []*NodePathMapData `json:"nodePathMap,omitempty"` + + CmdTimeoutSeconds int `json:"cmdTimeoutSeconds,omitempty"` } type NodePathMap struct { @@ -78,7 +82,8 @@ type NodePathMap struct { } type Config struct { - NodePathMap map[string]*NodePathMap + NodePathMap map[string]*NodePathMap + CmdTimeoutSeconds int } func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset, @@ -447,7 +452,7 @@ func (p *LocalPathProvisioner) createHelperPod(action ActionType, cmd []string, }() completed := false - for i := 0; i < CmdTimeoutCounts; i++ { + for i := 0; i < p.config.CmdTimeoutSeconds; i++ { if pod, err := p.kubeClient.CoreV1().Pods(p.namespace).Get(helperPod.Name, metav1.GetOptions{}); err != nil { return err } else if pod.Status.Phase == v1.PodSucceeded { @@ -457,7 +462,7 @@ func (p *LocalPathProvisioner) createHelperPod(action ActionType, cmd []string, time.Sleep(1 * time.Second) } if !completed { - return fmt.Errorf("create process timeout after %v seconds", CmdTimeoutCounts) + return fmt.Errorf("create process timeout after %v seconds", p.config.CmdTimeoutSeconds) } logrus.Infof("Volume %v has been %vd on %v:%v", o.Name, action, o.Node, o.Path) @@ -540,5 +545,10 @@ func canonicalizeConfig(data *ConfigData) (cfg *Config, err error) { npMap.Paths[path] = struct{}{} } } + if data.CmdTimeoutSeconds > 0 { + cfg.CmdTimeoutSeconds = data.CmdTimeoutSeconds + } else { + cfg.CmdTimeoutSeconds = defaultCmdTimeoutSeconds + } return cfg, nil }