...

Source file src/k8s.io/kubernetes/pkg/controller/podautoscaler/rate_limiters.go

Documentation: k8s.io/kubernetes/pkg/controller/podautoscaler

     1  /*
     2  Copyright 2015 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 podautoscaler
    18  
    19  import (
    20  	"time"
    21  
    22  	"k8s.io/client-go/util/workqueue"
    23  )
    24  
    25  // FixedItemIntervalRateLimiter limits items to a fixed-rate interval
    26  type FixedItemIntervalRateLimiter struct {
    27  	interval time.Duration
    28  }
    29  
    30  var _ workqueue.RateLimiter = &FixedItemIntervalRateLimiter{}
    31  
    32  // NewFixedItemIntervalRateLimiter creates a new instance of a RateLimiter using a fixed interval
    33  func NewFixedItemIntervalRateLimiter(interval time.Duration) workqueue.RateLimiter {
    34  	return &FixedItemIntervalRateLimiter{
    35  		interval: interval,
    36  	}
    37  }
    38  
    39  // When returns the interval of the rate limiter
    40  func (r *FixedItemIntervalRateLimiter) When(item interface{}) time.Duration {
    41  	return r.interval
    42  }
    43  
    44  // NumRequeues returns back how many failures the item has had
    45  func (r *FixedItemIntervalRateLimiter) NumRequeues(item interface{}) int {
    46  	return 1
    47  }
    48  
    49  // Forget indicates that an item is finished being retried.
    50  func (r *FixedItemIntervalRateLimiter) Forget(item interface{}) {
    51  }
    52  
    53  // NewDefaultHPARateLimiter creates a rate limiter which limits overall (as per the
    54  // default controller rate limiter), as well as per the resync interval
    55  func NewDefaultHPARateLimiter(interval time.Duration) workqueue.RateLimiter {
    56  	return NewFixedItemIntervalRateLimiter(interval)
    57  }
    58  

View as plain text