// Handle worker namespace limit range
Handle worker namespace limit range
// Handle worker namespace limit range
func handleWorkerNamespaceLimitRange(c *Controller, providedConfig map[string]string, namespace string) error {
	workerLimitRange, err := c.limitRangeClient.LimitRanges(namespace).Get(context.Background(), workerLimitRangeName, metav1.GetOptions{})
	if err != nil {
		if errors.IsNotFound(err) {
			return nil
		}
		klog.Errorf("could not find LimitRange: %s/%s", namespace, workerLimitRangeName)
		return err
	}
	newWorkerLimitRange := workerLimitRange.DeepCopy()
	for _, limit := range newWorkerLimitRange.Spec.Limits {
		if v1.LimitTypeContainer == limit.Type {
			if defaultCPURaw, ok := providedConfig[workerLRDefaultCPUKey]; ok {
				defaultCPU, err := resource.ParseQuantity(defaultCPURaw)
				if err != nil {
					klog.Errorf("failed to parse default.cpu: %s", defaultCPURaw)
					return err
				}
				limit.Default["cpu"] = defaultCPU
			}
			if defaultMemoryRaw, ok := providedConfig[workerLRDefaultMemoryKey]; ok {
				defaultMemory, err := resource.ParseQuantity(defaultMemoryRaw)
				if err != nil {
					klog.Errorf("failed to parse default.memory: %s", defaultMemoryRaw)
					return err
				}
				limit.Default["memory"] = defaultMemory
			}
			if defaultRequestCPURaw, ok := providedConfig[workerLRDefaultReqCPUKey]; ok {
				defaultRequestCPU, err := resource.ParseQuantity(defaultRequestCPURaw)
				if err != nil {
					klog.Errorf("failed to parse defaultrequest.cpu: %s", defaultRequestCPURaw)
					return err
				}
				limit.DefaultRequest["cpu"] = defaultRequestCPU
			}
			if defaultRequestMemoryRaw, ok := providedConfig[workerLRDefaultReqMemoryKey]; ok {
				defaultRequestMemory, err := resource.ParseQuantity(defaultRequestMemoryRaw)
				if err != nil {
					klog.Errorf("failed to parse defaultrequest.memory: %s", defaultRequestMemoryRaw)
					return err
				}
				limit.DefaultRequest["memory"] = defaultRequestMemory
			}
		}
	}
	_, err = c.limitRangeClient.LimitRanges(namespace).Update(context.Background(), newWorkerLimitRange, metav1.UpdateOptions{})
	if err != nil {
		klog.Errorf("failed to update %s/%s", namespace, workerLimitRangeName)
		return err
	}
	klog.V(5).Infof("updated %s/%s successfully", namespace, workerLimitRangeName)
	return nil
}
func handleWorkerNamespaceLimitRange ( c * Controller , providedConfig map [ string ] string , namespace string ) error { workerLimitRange , err := c . limitRangeClient . LimitRanges ( namespace ) . Get ( context . Background ( ) , workerLimitRangeName , metav1 . GetOptions { } ) if err != nil { if errors . IsNotFound ( err ) { return nil } klog . Errorf ( " " , namespace , workerLimitRangeName ) return err } newWorkerLimitRange := workerLimitRange . DeepCopy ( ) for _ , limit := range newWorkerLimitRange . Spec . Limits { if v1 . LimitTypeContainer == limit . Type { if defaultCPURaw , ok := providedConfig [ workerLRDefaultCPUKey ] ; ok { defaultCPU , err := resource . ParseQuantity ( defaultCPURaw ) if err != nil { klog . Errorf ( " " , defaultCPURaw ) return err } limit . Default [ " " ] = defaultCPU } if defaultMemoryRaw , ok := providedConfig [ workerLRDefaultMemoryKey ] ; ok { defaultMemory , err := resource . ParseQuantity ( defaultMemoryRaw ) if err != nil { klog . Errorf ( " " , defaultMemoryRaw ) return err } limit . Default [ " " ] = defaultMemory } if defaultRequestCPURaw , ok := providedConfig [ workerLRDefaultReqCPUKey ] ; ok { defaultRequestCPU , err := resource . ParseQuantity ( defaultRequestCPURaw ) if err != nil { klog . Errorf ( " " , defaultRequestCPURaw ) return err } limit . DefaultRequest [ " " ] = defaultRequestCPU } if defaultRequestMemoryRaw , ok := providedConfig [ workerLRDefaultReqMemoryKey ] ; ok { defaultRequestMemory , err := resource . ParseQuantity ( defaultRequestMemoryRaw ) if err != nil { klog . Errorf ( " " , defaultRequestMemoryRaw ) return err } limit . DefaultRequest [ " " ] = defaultRequestMemory } } } _ , err = c . limitRangeClient . LimitRanges ( namespace ) . Update ( context . Background ( ) , newWorkerLimitRange , metav1 . UpdateOptions { } ) if err != nil { klog . Errorf ( " " , namespace , workerLimitRangeName ) return err } klog . V ( 5 ) . Infof ( " " , namespace , workerLimitRangeName ) return nil }
Handle worker namespace limit range
Handle worker namespace limit range
// handle for container type // handle default cpu // handle default memory // handle default request cpu // handle default request memory // update worker limit range