mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-21 01:50:55 +00:00
Allow lazy binding in credential providers; don't use it in AWS yet
This is step one for cross-region ECR support and has no visible effects yet. I'm not crazy about the name LazyProvide. Perhaps the interface method could remain like that and the package method of the same name could become LateBind(). I still don't understand why the credential provider has a DockerConfigEntry that has the same fields but is distinct from docker.AuthConfiguration. I had to write a converter now that we do that in more than one place. In step two, I'll add another intermediate, lazy provider for each AWS region, whose empty LazyAuthConfiguration will have a refresh time of months or years. Behind the scenes, it'll use an actual ecrProvider with the usual ~12 hour credentials, that will get created (and later refreshed) only when kubelet is attempting to pull an image. If we simply turned ecrProvider directly into a lazy provider, we would bypass all the caching and get new credentials for each image pulled.
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
@@ -30,6 +31,19 @@ import (
|
||||
type DockerConfigProvider interface {
|
||||
Enabled() bool
|
||||
Provide() DockerConfig
|
||||
// LazyProvide() gets called after URL matches have been performed, so the
|
||||
// location used as the key in DockerConfig would be redundant.
|
||||
LazyProvide() *DockerConfigEntry
|
||||
}
|
||||
|
||||
func LazyProvide(creds LazyAuthConfiguration) docker.AuthConfiguration {
|
||||
if creds.Provider != nil {
|
||||
entry := *creds.Provider.LazyProvide()
|
||||
return DockerConfigEntryToLazyAuthConfiguration(entry).AuthConfiguration
|
||||
} else {
|
||||
return creds.AuthConfiguration
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// A DockerConfigProvider that simply reads the .dockercfg file
|
||||
@@ -73,11 +87,21 @@ func (d *defaultDockerConfigProvider) Provide() DockerConfig {
|
||||
return DockerConfig{}
|
||||
}
|
||||
|
||||
// LazyProvide implements dockerConfigProvider. Should never be called.
|
||||
func (d *defaultDockerConfigProvider) LazyProvide() *DockerConfigEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enabled implements dockerConfigProvider
|
||||
func (d *CachingDockerConfigProvider) Enabled() bool {
|
||||
return d.Provider.Enabled()
|
||||
}
|
||||
|
||||
// LazyProvide implements dockerConfigProvider. Should never be called.
|
||||
func (d *CachingDockerConfigProvider) LazyProvide() *DockerConfigEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Provide implements dockerConfigProvider
|
||||
func (d *CachingDockerConfigProvider) Provide() DockerConfig {
|
||||
d.mu.Lock()
|
||||
|
Reference in New Issue
Block a user