func NewConfig()

in pkg/apis/frameworkcontroller/v1/config.go [219:376]


func NewConfig() *Config {
	c := initConfig()

	// Defaulting
	if c.KubeApiServerAddress == nil {
		c.KubeApiServerAddress = common.PtrString(EnvValueKubeApiServerAddress)
	}
	if c.KubeConfigFilePath == nil {
		c.KubeConfigFilePath = defaultKubeConfigFilePath()
	}
	// Based on the default --max-mutating-requests-inflight is 200.
	if c.KubeClientQps == nil {
		c.KubeClientQps = common.PtrFloat32(80)
	}
	if c.KubeClientBurst == nil {
		c.KubeClientBurst = common.PtrInt32(120)
	}
	if c.WorkerNumber == nil {
		c.WorkerNumber = common.PtrInt32(200)
	}
	if c.LargeFrameworkCompression == nil {
		c.LargeFrameworkCompression = common.PtrBool(false)
	}
	if c.CRDEstablishedCheckIntervalSec == nil {
		c.CRDEstablishedCheckIntervalSec = common.PtrInt64(1)
	}
	if c.CRDEstablishedCheckTimeoutSec == nil {
		c.CRDEstablishedCheckTimeoutSec = common.PtrInt64(60)
	}
	if c.ObjectLocalCacheCreationTimeoutSec == nil {
		// Default to k8s.io/kubernetes/pkg/controller.ExpectationsTimeout
		c.ObjectLocalCacheCreationTimeoutSec = common.PtrInt64(5 * 60)
	}
	if c.FrameworkCompletedRetainSec == nil {
		c.FrameworkCompletedRetainSec = common.PtrInt64(30 * 24 * 3600)
	}
	if c.FrameworkMinRetryDelaySecForTransientConflictFailed == nil {
		c.FrameworkMinRetryDelaySecForTransientConflictFailed = common.PtrInt64(60)
	}
	if c.FrameworkMaxRetryDelaySecForTransientConflictFailed == nil {
		c.FrameworkMaxRetryDelaySecForTransientConflictFailed = common.PtrInt64(15 * 60)
	}
	if c.LogObjectSnapshot.Framework.OnFrameworkRetry == nil {
		c.LogObjectSnapshot.Framework.OnFrameworkRetry = common.PtrBool(true)
	}
	if c.LogObjectSnapshot.Framework.OnFrameworkDeletion == nil {
		c.LogObjectSnapshot.Framework.OnFrameworkDeletion = common.PtrBool(true)
	}
	if c.LogObjectSnapshot.Task.OnTaskRetry == nil {
		c.LogObjectSnapshot.Task.OnTaskRetry = common.PtrBool(true)
	}
	if c.LogObjectSnapshot.Task.OnTaskDeletion == nil {
		c.LogObjectSnapshot.Task.OnTaskDeletion = common.PtrBool(true)
	}
	if c.LogObjectSnapshot.Pod.OnPodDeletion == nil {
		c.LogObjectSnapshot.Pod.OnPodDeletion = common.PtrBool(true)
	}
	for _, codeInfo := range c.PodFailureSpec {
		if codeInfo.Type.Name == "" {
			codeInfo.Type.Name = CompletionTypeNameFailed
		}
	}

	// Validation
	errPrefix := "Config Validation Failed: "
	if *c.KubeClientQps <= 0 || *c.KubeClientQps > 10000 {
		panic(fmt.Errorf(errPrefix+
			"KubeClientQps %v should be within (0, 10000]",
			*c.KubeClientQps))
	}
	if *c.KubeClientBurst < 0 || *c.KubeClientBurst > 10000 {
		panic(fmt.Errorf(errPrefix+
			"KubeClientBurst %v should be within [0, 10000]",
			*c.KubeClientBurst))
	}
	if *c.WorkerNumber <= 0 {
		panic(fmt.Errorf(errPrefix+
			"WorkerNumber %v should be positive",
			*c.WorkerNumber))
	}
	if *c.CRDEstablishedCheckIntervalSec < 1 {
		panic(fmt.Errorf(errPrefix+
			"CRDEstablishedCheckIntervalSec %v should not be less than 1",
			*c.CRDEstablishedCheckIntervalSec))
	}
	if *c.CRDEstablishedCheckTimeoutSec < 10 {
		panic(fmt.Errorf(errPrefix+
			"CRDEstablishedCheckTimeoutSec %v should not be less than 10",
			*c.CRDEstablishedCheckTimeoutSec))
	}
	if *c.ObjectLocalCacheCreationTimeoutSec < 60 {
		panic(fmt.Errorf(errPrefix+
			"ObjectLocalCacheCreationTimeoutSec %v should not be less than 60",
			*c.ObjectLocalCacheCreationTimeoutSec))
	}
	if *c.FrameworkMinRetryDelaySecForTransientConflictFailed < 0 {
		panic(fmt.Errorf(errPrefix+
			"FrameworkMinRetryDelaySecForTransientConflictFailed %v should not be negative",
			*c.FrameworkMinRetryDelaySecForTransientConflictFailed))
	}
	if *c.FrameworkMaxRetryDelaySecForTransientConflictFailed <
		*c.FrameworkMinRetryDelaySecForTransientConflictFailed {
		panic(fmt.Errorf(errPrefix+
			"FrameworkMaxRetryDelaySecForTransientConflictFailed %v should not be less than "+
			"FrameworkMinRetryDelaySecForTransientConflictFailed %v",
			*c.FrameworkMaxRetryDelaySecForTransientConflictFailed,
			*c.FrameworkMinRetryDelaySecForTransientConflictFailed))
	}
	codeInfoMap := map[CompletionCode]*CompletionCodeInfo{}
	for _, codeInfo := range c.PodFailureSpec {
		if codeInfo.Type.Name != CompletionTypeNameFailed {
			panic(fmt.Errorf(errPrefix+
				"PodFailureSpec contains CompletionTypeName which is not %v:\n%v",
				CompletionTypeNameFailed, common.ToYaml(codeInfo)))
		}
		if len(codeInfo.PodPatterns) == 0 {
			panic(fmt.Errorf(errPrefix+
				"PodFailureSpec contains empty PodPatterns:\n%v",
				common.ToYaml(codeInfo)))
		}
		for _, podPattern := range codeInfo.PodPatterns {
			if podPattern == nil {
				panic(fmt.Errorf(errPrefix+
					"PodFailureSpec contains nil PodPattern:\n%v",
					common.ToYaml(codeInfo)))
			}
			for _, containerPattern := range podPattern.Containers {
				if containerPattern == nil {
					panic(fmt.Errorf(errPrefix+
						"PodFailureSpec contains nil ContainerPattern:\n%v",
						common.ToYaml(codeInfo)))
				}
			}
		}
		if codeInfo.Code == nil {
			panic(fmt.Errorf(errPrefix+
				"PodFailureSpec contains nil CompletionCode:\n%v",
				common.ToYaml(codeInfo)))
		}
		if CompletionCodeReservedNonPositive.Contains(*codeInfo.Code) ||
			CompletionCodeReservedPositive.Contains(*codeInfo.Code) {
			panic(fmt.Errorf(errPrefix+
				"PodFailureSpec contains CompletionCode which should not be within "+
				"%v and %v:\n%v",
				CompletionCodeReservedNonPositive, CompletionCodeReservedPositive,
				common.ToYaml(codeInfo)))
		}
		if existingCodeInfo, ok := codeInfoMap[*codeInfo.Code]; ok {
			panic(fmt.Errorf(errPrefix+
				"PodFailureSpec contains duplicated CompletionCode:"+
				"\nExisting CompletionCodeInfo:\n%v,\nChecking CompletionCodeInfo:\n%v",
				common.ToYaml(existingCodeInfo), common.ToYaml(codeInfo)))
		}
		codeInfoMap[*codeInfo.Code] = codeInfo
	}

	return c
}