Skip to content

Commit 20edecc

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 7eb1f05 commit 20edecc

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.
@@ -365,7 +348,7 @@ func downloadOCIChart(name, version, path string, auth Auth) (string, error) {
365348
if auth.BasicHTTP {
366349
clientOptions = append(clientOptions, registry.ClientOptPlainHTTP())
367350
}
368-
registryClient, err = registry.NewClient(clientOptions...)
351+
registryClient, err := registry.NewClient(clientOptions...)
369352
if err != nil {
370353
return "", err
371354
}
@@ -396,8 +379,15 @@ func downloadOCIChart(name, version, path string, auth Auth) (string, error) {
396379
getterOptions = append(getterOptions, helmgetter.WithInsecureSkipVerifyTLS(auth.InsecureSkipVerify))
397380

398381
c := downloader.ChartDownloader{
399-
Verify: downloader.VerifyNever,
400-
Getters: helmgetter.Providers{fleetOciProvider},
382+
Verify: downloader.VerifyNever,
383+
Getters: helmgetter.Providers{
384+
helmgetter.Provider{
385+
Schemes: []string{registry.OCIScheme},
386+
New: func(options ...helmgetter.Option) (helmgetter.Getter, error) {
387+
return helmgetter.NewOCIGetter(helmgetter.WithRegistryClient(registryClient))
388+
},
389+
},
390+
},
401391
RegistryClient: registryClient,
402392
Options: getterOptions,
403393
}

0 commit comments

Comments
 (0)