func newConfig()

in pkg/barrier/barrier.go [118:181]


func newConfig() *Config {
	c := Config{}

	// Setting and Defaulting
	c.KubeApiServerAddress = ci.EnvValueKubeApiServerAddress
	if ci.EnvValueKubeConfigFilePath == "" {
		c.KubeConfigFilePath = *defaultKubeConfigFilePath()
	} else {
		c.KubeConfigFilePath = ci.EnvValueKubeConfigFilePath
	}
	c.FrameworkNamespace = os.Getenv(ci.EnvNameFrameworkNamespace)
	c.FrameworkName = os.Getenv(ci.EnvNameFrameworkName)

	barrierCheckIntervalSecStr := os.Getenv(EnvNameBarrierCheckIntervalSec)
	if barrierCheckIntervalSecStr == "" {
		c.BarrierCheckIntervalSec = 10
	} else {
		i, err := strconv.ParseInt(barrierCheckIntervalSecStr, 10, 64)
		if err != nil {
			klog.Errorf(
				"Failed to parse ${%v}: %v",
				EnvNameBarrierCheckIntervalSec, err)
			exit(ci.CompletionCodeContainerPermanentFailed)
		}
		c.BarrierCheckIntervalSec = i
	}

	barrierCheckTimeoutSecStr := os.Getenv(EnvNameBarrierCheckTimeoutSec)
	if barrierCheckTimeoutSecStr == "" {
		c.BarrierCheckTimeoutSec = 10 * 60
	} else {
		i, err := strconv.ParseInt(barrierCheckTimeoutSecStr, 10, 64)
		if err != nil {
			klog.Errorf(
				"Failed to parse ${%v}: %v",
				EnvNameBarrierCheckTimeoutSec, err)
			exit(ci.CompletionCodeContainerPermanentFailed)
		}
		c.BarrierCheckTimeoutSec = i
	}

	// Validation
	errPrefix := "Validation Failed: "
	if c.FrameworkName == "" {
		klog.Errorf(errPrefix+
			"${%v} should not be empty",
			ci.EnvNameFrameworkName)
		exit(ci.CompletionCodeContainerPermanentFailed)
	}
	if c.BarrierCheckIntervalSec < 5 {
		klog.Errorf(errPrefix+
			"${%v} %v should not be less than 5",
			EnvNameBarrierCheckIntervalSec, c.BarrierCheckIntervalSec)
		exit(ci.CompletionCodeContainerPermanentFailed)
	}
	if c.BarrierCheckTimeoutSec < 60 || c.BarrierCheckTimeoutSec > 20*60 {
		klog.Errorf(errPrefix+
			"${%v} %v should not be less than 60 or greater than 20 * 60",
			EnvNameBarrierCheckTimeoutSec, c.BarrierCheckTimeoutSec)
		exit(ci.CompletionCodeContainerPermanentFailed)
	}

	return &c
}