Skip to content

Commit

Permalink
Use docker client without auth if dockerCfg is not set (#8273)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuriy Losev <yuriy.losev@flant.com>
  • Loading branch information
yalosev authored Apr 26, 2024
1 parent 2769a3e commit e0a9d40
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ const (
SyncedPollPeriod = 100 * time.Millisecond
)

// GenerateRegistryOptions feteches settings from ModuleSource and generate registry options from them
// GenerateRegistryOptions fetches settings from ModuleSource and generate registry options from them
func GenerateRegistryOptions(ms *v1alpha1.ModuleSource) []cr.Option {
opts := make([]cr.Option, 0)
if ms.Spec.Registry.DockerCFG != "" {
opts = append(opts, cr.WithAuth(ms.Spec.Registry.DockerCFG))
} else {
opts = append(opts, cr.WithDisabledAuth())
opts := []cr.Option{
cr.WithAuth(ms.Spec.Registry.DockerCFG),
}

if ms.Spec.Registry.CA != "" {
Expand Down
11 changes: 4 additions & 7 deletions go_lib/dependency/cr/cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,14 @@ func WithInsecureSchema(insecure bool) Option {
}
}

// WithDisabledAuth don't use authConfig
func WithDisabledAuth() Option {
return func(options *registryOptions) {
options.withoutAuth = true
}
}

// WithAuth use docker config base64 as authConfig
// if dockerCfg is empty - will use client without auth
func WithAuth(dockerCfg string) Option {
return func(options *registryOptions) {
options.dockerCfg = dockerCfg
if dockerCfg == "" {
options.withoutAuth = true
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion modules/002-deckhouse/hooks/check_deckhouse_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,16 @@ func NewDeckhouseReleaseChecker(input *go_hook.HookInput, dc dependency.Containe
repo := input.Values.Get("global.modulesImages.registry.base").String() // host/ns/repo
dockerCfg := input.Values.Get("global.modulesImages.registry.dockercfg").String()
clusterUUID := input.Values.Get("global.discovery.clusterUUID").String()

opts := []cr.Option{
cr.WithCA(getCA(input)),
cr.WithInsecureSchema(isHTTP(input)),
cr.WithUserAgent(clusterUUID),
cr.WithAuth(dockerCfg),
}

// registry.deckhouse.io/deckhouse/ce/release-channel:$release-channel
regCli, err := dc.GetRegistryClient(path.Join(repo, "release-channel"), cr.WithAuth(dockerCfg), cr.WithCA(getCA(input)), cr.WithInsecureSchema(isHTTP(input)), cr.WithUserAgent(clusterUUID))
regCli, err := dc.GetRegistryClient(path.Join(repo, "release-channel"), opts...)
if err != nil {
return nil, err
}
Expand Down
8 changes: 7 additions & 1 deletion modules/002-deckhouse/hooks/update_deckhouse_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ func tagUpdate(input *go_hook.HookInput, dc dependency.Container, deckhousePods

dockerCfg := input.Values.Get("global.modulesImages.registry.dockercfg").String()

regClient, err := dc.GetRegistryClient(repo, cr.WithCA(getCA(input)), cr.WithInsecureSchema(isHTTP(input)), cr.WithAuth(dockerCfg))
opts := []cr.Option{
cr.WithCA(getCA(input)),
cr.WithInsecureSchema(isHTTP(input)),
cr.WithAuth(dockerCfg),
}

regClient, err := dc.GetRegistryClient(repo, opts...)
if err != nil {
input.LogEntry.Errorf("Registry (%s) client init failed: %s", repo, err)
return nil
Expand Down
2 changes: 1 addition & 1 deletion modules/500-okmeter/hooks/update_agent_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func checkRelease(input *go_hook.HookInput, dc dependency.Container) error {
if tag == "" {
tag = "latest"
}
regCli, err := dc.GetRegistryClient(repo, cr.WithDisabledAuth())
regCli, err := dc.GetRegistryClient(repo, cr.WithAuth(""))
if err != nil {
return err
}
Expand Down

0 comments on commit e0a9d40

Please sign in to comment.