@@ -46,37 +46,35 @@ func Pull(ctx context.Context, imageName string, opts ...PullOption) error {
4646 pullOpts .client = sdk
4747 }
4848
49+ if pullOpts .credentialsFn == nil {
50+ if err := WithCredentialsFromConfig (pullOpts ); err != nil {
51+ return fmt .Errorf ("set credentials for pull option: %w" , err )
52+ }
53+ }
54+
4955 if imageName == "" {
5056 return errors .New ("image name is not set" )
5157 }
5258
53- authConfigs , err := config . AuthConfigs (imageName )
59+ username , password , err := pullOpts . credentialsFn (imageName )
5460 if err != nil {
55- pullOpts .client .Logger ().Warn ("failed to get image auth, setting empty credentials for the image" , "image" , imageName , "error" , err )
56- } else {
57- // there must be only one auth config for the image
58- if len (authConfigs ) > 1 {
59- return fmt .Errorf ("multiple auth configs found for image %s, expected only one" , imageName )
60- }
61-
62- var tmp config.AuthConfig
63- for _ , ac := range authConfigs {
64- tmp = ac
65- }
61+ return fmt .Errorf ("failed to retrieve registry credentials for %s: %w" , imageName , err )
62+ }
6663
67- authConfig := config.AuthConfig {
68- Username : tmp .Username ,
69- Password : tmp .Password ,
70- }
71- encodedJSON , err := json .Marshal (authConfig )
72- if err != nil {
73- pullOpts .client .Logger ().Warn ("failed to marshal image auth, setting empty credentials for the image" , "image" , imageName , "error" , err )
74- } else {
75- pullOpts .pullOptions .RegistryAuth = base64 .URLEncoding .EncodeToString (encodedJSON )
76- }
64+ authConfig := config.AuthConfig {
65+ Username : username ,
66+ Password : password ,
67+ }
68+ encodedJSON , err := json .Marshal (authConfig )
69+ if err != nil {
70+ pullOpts .client .Logger ().Warn ("failed to marshal image auth, setting empty credentials for the image" , "image" , imageName , "error" , err )
71+ } else {
72+ pullOpts .pullOptions .RegistryAuth = base64 .URLEncoding .EncodeToString (encodedJSON )
7773 }
7874
79- var pull io.ReadCloser
75+ var (
76+ pull io.ReadCloser
77+ )
8078 err = backoff .RetryNotify (
8179 func () error {
8280 pull , err = pullOpts .client .ImagePull (ctx , imageName , pullOpts .pullOptions )
0 commit comments