Skip to content

Commit 03edcc8

Browse files
0xavi0thardeck
authored andcommitted
Avoid using a global registry client when downloading OCI helm charts (#3938)
This changes how we instantiate the `registryClient` used when downloading helm charts stored in OCI registries. It fixes race conditions that could lead to `Not Logged In` or even authentication problems. Refers to: #3915 Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
1 parent 4d49321 commit 03edcc8

1 file changed

Lines changed: 10 additions & 20 deletions

File tree

internal/bundlereader/loaddirectory.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,6 @@ import (
2626
"helm.sh/helm/v3/pkg/registry"
2727
)
2828

29-
var (
30-
registryClient *registry.Client
31-
32-
fleetOciProvider = helmgetter.Provider{
33-
Schemes: []string{registry.OCIScheme},
34-
New: NewFleetOCIProvider,
35-
}
36-
)
37-
38-
func NewFleetOCIProvider(options ...helmgetter.Option) (helmgetter.Getter, error) {
39-
if registryClient == nil {
40-
return nil, fmt.Errorf("oci registry client is nil")
41-
}
42-
43-
return helmgetter.NewOCIGetter(helmgetter.WithRegistryClient(registryClient))
44-
}
45-
4629
// ignoreTree represents a tree of ignored paths (read from .fleetignore files), each node being a directory.
4730
// It provides a means for ignored paths to be propagated down the tree, but not between subdirectories of a same
4831
// directory.
@@ -363,7 +346,7 @@ func downloadOCIChart(name, version, path string, auth Auth) (string, error) {
363346
if auth.BasicHTTP {
364347
clientOptions = append(clientOptions, registry.ClientOptPlainHTTP())
365348
}
366-
registryClient, err = registry.NewClient(clientOptions...)
349+
registryClient, err := registry.NewClient(clientOptions...)
367350
if err != nil {
368351
return "", err
369352
}
@@ -394,8 +377,15 @@ func downloadOCIChart(name, version, path string, auth Auth) (string, error) {
394377
getterOptions = append(getterOptions, helmgetter.WithInsecureSkipVerifyTLS(auth.InsecureSkipVerify))
395378

396379
c := downloader.ChartDownloader{
397-
Verify: downloader.VerifyNever,
398-
Getters: helmgetter.Providers{fleetOciProvider},
380+
Verify: downloader.VerifyNever,
381+
Getters: helmgetter.Providers{
382+
helmgetter.Provider{
383+
Schemes: []string{registry.OCIScheme},
384+
New: func(options ...helmgetter.Option) (helmgetter.Getter, error) {
385+
return helmgetter.NewOCIGetter(helmgetter.WithRegistryClient(registryClient))
386+
},
387+
},
388+
},
399389
RegistryClient: registryClient,
400390
Options: getterOptions,
401391
}

0 commit comments

Comments
 (0)