@@ -25,7 +25,9 @@ import (
2525 "strings"
2626
2727 "github.com/google/go-containerregistry/pkg/authn"
28+ "github.com/google/go-containerregistry/pkg/logs"
2829 corev1 "k8s.io/api/core/v1"
30+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
2931 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3032 "k8s.io/client-go/kubernetes"
3133 "k8s.io/client-go/rest"
@@ -65,23 +67,33 @@ func New(ctx context.Context, client kubernetes.Interface, opt Options) (authn.K
6567 var pullSecrets []corev1.Secret
6668 for _ , name := range opt .ImagePullSecrets {
6769 ps , err := client .CoreV1 ().Secrets (opt .Namespace ).Get (ctx , name , metav1.GetOptions {})
68- if err != nil {
70+ if k8serrors .IsNotFound (err ) {
71+ logs .Warn .Printf ("secret %s/%s not found; ignoring" , opt .Namespace , name )
72+ continue
73+ } else if err != nil {
6974 return nil , err
7075 }
7176 pullSecrets = append (pullSecrets , * ps )
7277 }
7378
7479 // Second, fetch all of the pull secrets attached to our service account.
7580 sa , err := client .CoreV1 ().ServiceAccounts (opt .Namespace ).Get (ctx , opt .ServiceAccountName , metav1.GetOptions {})
76- if err != nil {
81+ if k8serrors .IsNotFound (err ) {
82+ logs .Warn .Printf ("serviceaccount %s/%s not found; ignoring" , opt .Namespace , opt .ServiceAccountName )
83+ } else if err != nil {
7784 return nil , err
7885 }
79- for _ , localObj := range sa .ImagePullSecrets {
80- ps , err := client .CoreV1 ().Secrets (opt .Namespace ).Get (ctx , localObj .Name , metav1.GetOptions {})
81- if err != nil {
82- return nil , err
86+ if sa != nil {
87+ for _ , localObj := range sa .ImagePullSecrets {
88+ ps , err := client .CoreV1 ().Secrets (opt .Namespace ).Get (ctx , localObj .Name , metav1.GetOptions {})
89+ if k8serrors .IsNotFound (err ) {
90+ logs .Warn .Printf ("secret %s/%s not found; ignoring" , opt .Namespace , localObj .Name )
91+ continue
92+ } else if err != nil {
93+ return nil , err
94+ }
95+ pullSecrets = append (pullSecrets , * ps )
8396 }
84- pullSecrets = append (pullSecrets , * ps )
8597 }
8698
8799 return NewFromPullSecrets (ctx , pullSecrets )
@@ -236,8 +248,9 @@ func splitURL(url *url.URL) (parts []string, port string) {
236248// glob wild cards in the host name.
237249//
238250// Examples:
239- // globURL=*.docker.io, targetURL=blah.docker.io => match
240- // globURL=*.docker.io, targetURL=not.right.io => no match
251+ //
252+ // globURL=*.docker.io, targetURL=blah.docker.io => match
253+ // globURL=*.docker.io, targetURL=not.right.io => no match
241254//
242255// Note that we don't support wildcards in ports and paths yet.
243256func urlsMatch (globURL * url.URL , targetURL * url.URL ) (bool , error ) {
0 commit comments