mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +00:00
fix: using sentinel error for non limited custom resource
This commit is contained in:
@@ -32,10 +32,22 @@ func GetUsedResourceFromTenant(tenant Tenant, kindGroup string) (int64, error) {
|
||||
return used, nil
|
||||
}
|
||||
|
||||
type NonLimitedResourceError struct {
|
||||
kindGroup string
|
||||
}
|
||||
|
||||
func NewNonLimitedResourceError(kindGroup string) *NonLimitedResourceError {
|
||||
return &NonLimitedResourceError{kindGroup: kindGroup}
|
||||
}
|
||||
|
||||
func (n NonLimitedResourceError) Error() string {
|
||||
return fmt.Sprintf("resource %s is not limited for the current tenant", n.kindGroup)
|
||||
}
|
||||
|
||||
func GetLimitResourceFromTenant(tenant Tenant, kindGroup string) (int64, error) {
|
||||
limitStr, ok := tenant.GetAnnotations()[LimitAnnotationForResource(kindGroup)]
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("resource %s is not limited for the current tenant", kindGroup)
|
||||
return 0, NewNonLimitedResourceError(kindGroup)
|
||||
}
|
||||
|
||||
limit, err := strconv.ParseInt(limitStr, 10, 10)
|
||||
|
||||
@@ -77,7 +77,11 @@ func (r *resourceCounterHandler) OnCreate(clt client.Client, decoder *admission.
|
||||
}
|
||||
|
||||
if limit, retryErr = capsulev1beta1.GetLimitResourceFromTenant(*tnt, kgv); retryErr != nil {
|
||||
return nil
|
||||
if errors.As(err, &capsulev1beta1.NonLimitedResourceError{}) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
used, _ := capsulev1beta1.GetUsedResourceFromTenant(*tnt, kgv)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user