1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/registryclient/utils.go
Charles-Edouard Brétéché a135076661
refactor: remove manual keychain refresh from client (#7806)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-07-11 15:19:44 +02:00

25 lines
840 B
Go

package registryclient
import (
"context"
"github.com/google/go-containerregistry/pkg/authn"
kauth "github.com/google/go-containerregistry/pkg/authn/kubernetes"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
corev1listers "k8s.io/client-go/listers/core/v1"
)
// generateKeychainForPullSecrets generates keychain by fetching secrets data from imagePullSecrets.
func generateKeychainForPullSecrets(lister corev1listers.SecretNamespaceLister, imagePullSecrets ...string) (authn.Keychain, error) {
var secrets []corev1.Secret
for _, imagePullSecret := range imagePullSecrets {
secret, err := lister.Get(imagePullSecret)
if err == nil {
secrets = append(secrets, *secret)
} else if !k8serrors.IsNotFound(err) {
return nil, err
}
}
return kauth.NewFromPullSecrets(context.TODO(), secrets)
}