// Handle worker namespace quota limit
Handle worker namespace quota limit
// Handle worker namespace quota limit
func handleWorkerNamespaceQuotaLimit(c *Controller, providedConfig map[string]string, namespace string) error {
	workerResourceQuota, err := c.resourceQuotaClient.ResourceQuotas(namespace).Get(context.Background(), workerResQuotaName, metav1.GetOptions{})
	if err != nil {
		if errors.IsNotFound(err) {
			return nil
		}
		klog.Errorf("could not find ResourceQuota: %s/%s", namespace, workerResQuotaName)
		return err
	}
	newWorkerResourceQuota := workerResourceQuota.DeepCopy()
	limitCPURaw, ok := providedConfig[workerLimitCPUKey]
	if ok {
		limitCPU, err := resource.ParseQuantity(limitCPURaw)
		if err != nil {
			klog.Errorf("failed to parse limit.cpu: %s", limitCPURaw)
			return err
		}
		newWorkerResourceQuota.Spec.Hard["limits.cpu"] = limitCPU
	}
	limitMemoryRaw, ok := providedConfig[workerLimitMemoryKey]
	if ok {
		limitMemory, err := resource.ParseQuantity(limitMemoryRaw)
		if err != nil {
			klog.Errorf("failed to parse limit.memory: %s", limitMemoryRaw)
			return err
		}
		newWorkerResourceQuota.Spec.Hard["limits.memory"] = limitMemory
	}
	_, err = c.resourceQuotaClient.ResourceQuotas(namespace).Update(context.Background(), newWorkerResourceQuota, metav1.UpdateOptions{})
	if err != nil {
		klog.Errorf("failed to update ResourceQuota: %s/%s", namespace, workerResQuotaName)
		return err
	}
	klog.V(5).Infof("updated %s/%s successfully", namespace, workerResQuotaName)
	return nil
}
func handleWorkerNamespaceQuotaLimit ( c * Controller , providedConfig map [ string ] string , namespace string ) error { workerResourceQuota , err := c . resourceQuotaClient . ResourceQuotas ( namespace ) . Get ( context . Background ( ) , workerResQuotaName , metav1 . GetOptions { } ) if err != nil { if errors . IsNotFound ( err ) { return nil } klog . Errorf ( " " , namespace , workerResQuotaName ) return err } newWorkerResourceQuota := workerResourceQuota . DeepCopy ( ) limitCPURaw , ok := providedConfig [ workerLimitCPUKey ] if ok { limitCPU , err := resource . ParseQuantity ( limitCPURaw ) if err != nil { klog . Errorf ( " " , limitCPURaw ) return err } newWorkerResourceQuota . Spec . Hard [ " " ] = limitCPU } limitMemoryRaw , ok := providedConfig [ workerLimitMemoryKey ] if ok { limitMemory , err := resource . ParseQuantity ( limitMemoryRaw ) if err != nil { klog . Errorf ( " " , limitMemoryRaw ) return err } newWorkerResourceQuota . Spec . Hard [ " " ] = limitMemory } _ , err = c . resourceQuotaClient . ResourceQuotas ( namespace ) . Update ( context . Background ( ) , newWorkerResourceQuota , metav1 . UpdateOptions { } ) if err != nil { klog . Errorf ( " " , namespace , workerResQuotaName ) return err } klog . V ( 5 ) . Infof ( " " , namespace , workerResQuotaName ) return nil }
Handle worker namespace quota limit
Handle worker namespace quota limit
// get the resource quota // apply new changes // invalid limit cpu // update worker resource quota