mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #28611 from deads2k/union-quota-regsitry
Automatic merge from submit-queue add union registry for quota Adds the ability to combine multiple quota registries together. Kube needs this for other types. @derekwaynecarr
This commit is contained in:
		@@ -214,7 +214,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
 | 
			
		||||
			},
 | 
			
		||||
		)
 | 
			
		||||
	default:
 | 
			
		||||
		return nil, fmt.Errorf("no replenishment controller available for %s", options.GroupKind)
 | 
			
		||||
		return nil, NewUnhandledGroupKindError(options.GroupKind)
 | 
			
		||||
	}
 | 
			
		||||
	return result, nil
 | 
			
		||||
}
 | 
			
		||||
@@ -229,3 +229,38 @@ func ServiceReplenishmentUpdateFunc(options *ReplenishmentControllerOptions) fun
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type unhandledKindErr struct {
 | 
			
		||||
	kind unversioned.GroupKind
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e unhandledKindErr) Error() string {
 | 
			
		||||
	return fmt.Sprintf("no replenishment controller available for %s", e.kind)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewUnhandledGroupKindError(kind unversioned.GroupKind) error {
 | 
			
		||||
	return unhandledKindErr{kind: kind}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func IsUnhandledGroupKindError(err error) bool {
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	_, ok := err.(unhandledKindErr)
 | 
			
		||||
	return ok
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UnionReplenishmentControllerFactory iterates through its constituent factories ignoring, UnhandledGroupKindErrors
 | 
			
		||||
// returning the first success or failure it hits.  If there are no hits either way, it return an UnhandledGroupKind error
 | 
			
		||||
type UnionReplenishmentControllerFactory []ReplenishmentControllerFactory
 | 
			
		||||
 | 
			
		||||
func (f UnionReplenishmentControllerFactory) NewController(options *ReplenishmentControllerOptions) (framework.ControllerInterface, error) {
 | 
			
		||||
	for _, factory := range f {
 | 
			
		||||
		controller, err := factory.NewController(options)
 | 
			
		||||
		if !IsUnhandledGroupKindError(err) {
 | 
			
		||||
			return controller, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil, NewUnhandledGroupKindError(options.GroupKind)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -64,3 +64,19 @@ type Registry interface {
 | 
			
		||||
	// Evaluators returns the set Evaluator objects registered to a groupKind
 | 
			
		||||
	Evaluators() map[unversioned.GroupKind]Evaluator
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UnionRegistry combines multiple registries.  Order matters because first registry to claim a GroupKind
 | 
			
		||||
// is the "winner"
 | 
			
		||||
type UnionRegistry []Registry
 | 
			
		||||
 | 
			
		||||
func (r UnionRegistry) Evaluators() map[unversioned.GroupKind]Evaluator {
 | 
			
		||||
	ret := map[unversioned.GroupKind]Evaluator{}
 | 
			
		||||
 | 
			
		||||
	for i := len(r) - 1; i >= 0; i-- {
 | 
			
		||||
		for k, v := range r[i].Evaluators() {
 | 
			
		||||
			ret[k] = v
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ret
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user