k8s.io/kubernetes@v1.29.3/pkg/quota/v1/evaluator/core/registry.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package core
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	"k8s.io/apimachinery/pkg/runtime/schema"
    22  	quota "k8s.io/apiserver/pkg/quota/v1"
    23  	"k8s.io/apiserver/pkg/quota/v1/generic"
    24  	"k8s.io/utils/clock"
    25  )
    26  
    27  // legacyObjectCountAliases are what we used to do simple object counting quota with mapped to alias
    28  var legacyObjectCountAliases = map[schema.GroupVersionResource]corev1.ResourceName{
    29  	corev1.SchemeGroupVersion.WithResource("configmaps"):             corev1.ResourceConfigMaps,
    30  	corev1.SchemeGroupVersion.WithResource("resourcequotas"):         corev1.ResourceQuotas,
    31  	corev1.SchemeGroupVersion.WithResource("replicationcontrollers"): corev1.ResourceReplicationControllers,
    32  	corev1.SchemeGroupVersion.WithResource("secrets"):                corev1.ResourceSecrets,
    33  }
    34  
    35  // NewEvaluators returns the list of static evaluators that manage more than counts
    36  func NewEvaluators(f quota.ListerForResourceFunc) []quota.Evaluator {
    37  	// these evaluators have special logic
    38  	result := []quota.Evaluator{
    39  		NewPodEvaluator(f, clock.RealClock{}),
    40  		NewServiceEvaluator(f),
    41  		NewPersistentVolumeClaimEvaluator(f),
    42  	}
    43  	// these evaluators require an alias for backwards compatibility
    44  	for gvr, alias := range legacyObjectCountAliases {
    45  		result = append(result,
    46  			generic.NewObjectCountEvaluator(gvr.GroupResource(), generic.ListResourceUsingListerFunc(f, gvr), alias))
    47  	}
    48  	return result
    49  }