-
Notifications
You must be signed in to change notification settings - Fork 307
Improve repository selection, based on prefixes in config and full image name #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,12 +155,12 @@ func NewClientExt(rawRepoURL string, root string, creds Creds, insecure bool, en | |
|
||
// Returns a HTTP client object suitable for go-git to use using the following | ||
// pattern: | ||
// - If insecure is true, always returns a client with certificate verification | ||
// turned off. | ||
// - If one or more custom certificates are stored for the repository, returns | ||
// a client with those certificates in the list of root CAs used to verify | ||
// the server's certificate. | ||
// - Otherwise (and on non-fatal errors), a default HTTP client is returned. | ||
// - If insecure is true, always returns a client with certificate verification | ||
// turned off. | ||
// - If one or more custom certificates are stored for the repository, returns | ||
// a client with those certificates in the list of root CAs used to verify | ||
// the server's certificate. | ||
// - Otherwise (and on non-fatal errors), a default HTTP client is returned. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like only whitespace changes. I think we should avoid these changes. |
||
func GetRepoHTTPClient(repoURL string, insecure bool, creds Creds, proxyURL string) *http.Client { | ||
// Default HTTP client | ||
var customHTTPClient = &http.Client{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"time" | ||
|
||
"github.com/argoproj-labs/argocd-image-updater/pkg/cache" | ||
"github.com/argoproj-labs/argocd-image-updater/pkg/image" | ||
"github.com/argoproj-labs/argocd-image-updater/pkg/log" | ||
|
||
"go.uber.org/ratelimit" | ||
|
@@ -179,8 +180,27 @@ func inferRegistryEndpointFromPrefix(prefix string) *RegistryEndpoint { | |
return NewRegistryEndpoint(prefix, prefix, apiURL, "", "", false, TagListSortUnsorted, 20, 0) | ||
} | ||
|
||
// GetRegistryEndpoint retrieves the endpoint information for the given prefix | ||
func GetRegistryEndpoint(prefix string) (*RegistryEndpoint, error) { | ||
// find registry by prefix based on full image name | ||
func findRegistryEndpointByImage(img *image.ContainerImage) (ep *RegistryEndpoint) { | ||
log.Debugf("Try to find endpoint by image: %s/%s", img.RegistryURL, img.ImageName) | ||
registryLock.RLock() | ||
imgName := fmt.Sprintf("%s/%s", img.RegistryURL, img.ImageName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about moving line 187 to the first line of this func, and use var |
||
|
||
for _, registry := range registries { | ||
if (ep == nil && strings.HasPrefix(imgName, registry.RegistryPrefix)) || (strings.HasPrefix(imgName, registry.RegistryPrefix) && len(registry.RegistryPrefix) > len(ep.RegistryPrefix)) { | ||
log.Debugf("Selected registry: '%s' (last selection in log - final)", registry.RegistryName) | ||
ep = registry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it break after the first match? |
||
} | ||
} | ||
|
||
registryLock.RUnlock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider moving |
||
return | ||
} | ||
|
||
// GetRegistryEndpoint retrieves the endpoint information for the given image | ||
func GetRegistryEndpoint(img *image.ContainerImage) (*RegistryEndpoint, error) { | ||
prefix := img.RegistryURL | ||
|
||
if prefix == "" { | ||
if defaultRegistry == nil { | ||
return nil, fmt.Errorf("no default endpoint configured") | ||
|
@@ -197,7 +217,12 @@ func GetRegistryEndpoint(prefix string) (*RegistryEndpoint, error) { | |
return registry, nil | ||
} else { | ||
var err error | ||
ep := inferRegistryEndpointFromPrefix(prefix) | ||
ep := findRegistryEndpointByImage(img) | ||
if ep != nil { | ||
return ep, err | ||
} | ||
|
||
ep = inferRegistryEndpointFromPrefix(prefix) | ||
if ep != nil { | ||
err = AddRegistryEndpoint(ep) | ||
} else { | ||
|
@@ -235,7 +260,7 @@ func GetDefaultRegistry() *RegistryEndpoint { | |
// SetRegistryEndpointCredentials allows to change the credentials used for | ||
// endpoint access for existing RegistryEndpoint configuration | ||
func SetRegistryEndpointCredentials(prefix, credentials string) error { | ||
registry, err := GetRegistryEndpoint(prefix) | ||
registry, err := GetRegistryEndpoint(&image.ContainerImage{RegistryURL: prefix}) | ||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/registry
has been moved to the sub-moduleregistry-scanner
.