@@ -22,7 +22,6 @@ import (
22
22
"fmt"
23
23
"net/url"
24
24
"os"
25
- "strings"
26
25
"time"
27
26
28
27
helmgetter "helm.sh/helm/v3/pkg/getter"
@@ -43,12 +42,10 @@ import (
43
42
44
43
"github.com/fluxcd/pkg/apis/meta"
45
44
"github.com/fluxcd/pkg/oci"
46
- "github.com/fluxcd/pkg/oci/auth/login"
47
45
"github.com/fluxcd/pkg/runtime/conditions"
48
46
helper "github.com/fluxcd/pkg/runtime/controller"
49
47
"github.com/fluxcd/pkg/runtime/patch"
50
48
"github.com/fluxcd/pkg/runtime/predicates"
51
- "github.com/google/go-containerregistry/pkg/name"
52
49
53
50
"github.com/fluxcd/source-controller/api/v1beta2"
54
51
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
@@ -301,10 +298,8 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *v1beta
301
298
if loginOpt != nil {
302
299
loginOpts = append (loginOpts , loginOpt )
303
300
}
304
- }
305
-
306
- if obj .Spec .Provider != sourcev1 .GenericOCIProvider && obj .Spec .Type == sourcev1 .HelmRepositoryTypeOCI {
307
- auth , authErr := oidcAuth (ctxTimeout , obj )
301
+ } else if obj .Spec .Provider != sourcev1 .GenericOCIProvider && obj .Spec .Type == sourcev1 .HelmRepositoryTypeOCI {
302
+ auth , authErr := oidcAuthFromAdapter (ctxTimeout , obj .Spec .URL , obj .Spec .Provider )
308
303
if authErr != nil && ! errors .Is (authErr , oci .ErrUnconfiguredProvider ) {
309
304
e := fmt .Errorf ("failed to get credential from %s: %w" , obj .Spec .Provider , authErr )
310
305
conditions .MarkFalse (obj , meta .ReadyCondition , sourcev1 .AuthenticationFailedReason , e .Error ())
@@ -387,41 +382,12 @@ func (r *HelmRepositoryOCIReconciler) eventLogf(ctx context.Context, obj runtime
387
382
r .Eventf (obj , eventType , reason , msg )
388
383
}
389
384
390
- // oidcAuth generates the OIDC credential authenticator based on the specified cloud provider.
391
- func oidcAuth (ctx context.Context , obj * sourcev1.HelmRepository ) (helmreg.LoginOption , error ) {
392
- url := strings .TrimPrefix (obj .Spec .URL , sourcev1 .OCIRepositoryPrefix )
393
- ref , err := name .ParseReference (url )
394
- if err != nil {
395
- return nil , fmt .Errorf ("failed to parse URL '%s': %w" , obj .Spec .URL , err )
396
- }
397
-
398
- loginOpt , err := loginWithManager (ctx , obj .Spec .Provider , url , ref )
399
- if err != nil {
400
- return nil , fmt .Errorf ("failed to login to registry '%s': %w" , obj .Spec .URL , err )
401
- }
402
-
403
- return loginOpt , nil
404
- }
405
-
406
- func loginWithManager (ctx context.Context , provider , url string , ref name.Reference ) (helmreg.LoginOption , error ) {
407
- opts := login.ProviderOptions {}
408
- switch provider {
409
- case sourcev1 .AmazonOCIProvider :
410
- opts .AwsAutoLogin = true
411
- case sourcev1 .AzureOCIProvider :
412
- opts .AzureAutoLogin = true
413
- case sourcev1 .GoogleOCIProvider :
414
- opts .GcpAutoLogin = true
415
- }
416
-
417
- auth , err := login .NewManager ().Login (ctx , url , ref , opts )
385
+ // oidcAuthFromAdapter generates the OIDC credential authenticator based on the specified cloud provider.
386
+ func oidcAuthFromAdapter (ctx context.Context , url , provider string ) (helmreg.LoginOption , error ) {
387
+ auth , err := oidcAuth (ctx , url , provider )
418
388
if err != nil {
419
389
return nil , err
420
390
}
421
391
422
- if auth == nil {
423
- return nil , nil
424
- }
425
-
426
392
return registry .OIDCAdaptHelper (auth )
427
393
}
0 commit comments