mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 11:18:16 +00:00
Move image pull throttling logic to kubelet/images
This allows runtimes in different packages (dockertools, rkt, kuberuntime) to share the same logic. Before this change, only dockertools support this feature. Now all three packages support image pull throttling.
This commit is contained in:
@@ -38,7 +38,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/leaky"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
"k8s.io/kubernetes/pkg/util/flowcontrol"
|
||||
"k8s.io/kubernetes/pkg/util/parsers"
|
||||
)
|
||||
|
||||
@@ -114,25 +113,12 @@ type dockerPuller struct {
|
||||
keyring credentialprovider.DockerKeyring
|
||||
}
|
||||
|
||||
type throttledDockerPuller struct {
|
||||
puller dockerPuller
|
||||
limiter flowcontrol.RateLimiter
|
||||
}
|
||||
|
||||
// newDockerPuller creates a new instance of the default implementation of DockerPuller.
|
||||
func newDockerPuller(client DockerInterface, qps float32, burst int) DockerPuller {
|
||||
dp := dockerPuller{
|
||||
func newDockerPuller(client DockerInterface) DockerPuller {
|
||||
return &dockerPuller{
|
||||
client: client,
|
||||
keyring: credentialprovider.NewDockerKeyring(),
|
||||
}
|
||||
|
||||
if qps == 0.0 {
|
||||
return dp
|
||||
}
|
||||
return &throttledDockerPuller{
|
||||
puller: dp,
|
||||
limiter: flowcontrol.NewTokenBucketRateLimiter(qps, burst),
|
||||
}
|
||||
}
|
||||
|
||||
func filterHTTPError(err error, image string) error {
|
||||
@@ -285,13 +271,6 @@ func (p dockerPuller) Pull(image string, secrets []api.Secret) error {
|
||||
return utilerrors.NewAggregate(pullErrs)
|
||||
}
|
||||
|
||||
func (p throttledDockerPuller) Pull(image string, secrets []api.Secret) error {
|
||||
if p.limiter.TryAccept() {
|
||||
return p.puller.Pull(image, secrets)
|
||||
}
|
||||
return fmt.Errorf("pull QPS exceeded.")
|
||||
}
|
||||
|
||||
func (p dockerPuller) IsImagePresent(image string) (bool, error) {
|
||||
_, err := p.client.InspectImage(image)
|
||||
if err == nil {
|
||||
@@ -303,10 +282,6 @@ func (p dockerPuller) IsImagePresent(image string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
func (p throttledDockerPuller) IsImagePresent(name string) (bool, error) {
|
||||
return p.puller.IsImagePresent(name)
|
||||
}
|
||||
|
||||
// Creates a name which can be reversed to identify both full pod name and container name.
|
||||
// This function returns stable name, unique name and a unique id.
|
||||
// Although rand.Uint32() is not really unique, but it's enough for us because error will
|
||||
|
||||
Reference in New Issue
Block a user