1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/pkg/utils/kube/cert.go
Charles-Edouard Brétéché 144985ee5a
chore: fix golangcilint timeout (#4388)
* chore: fix golangcilint timeout

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

* fix commit sha

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

* add .gitattributes

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
2022-08-24 21:08:24 +08:00

31 lines
789 B
Go

package kube
import (
"context"
"crypto/x509"
"fmt"
"github.com/kyverno/kyverno/pkg/config"
"google.golang.org/grpc/credentials"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func FetchCert(
ctx context.Context,
certs string,
kubeClient kubernetes.Interface,
) (credentials.TransportCredentials, error) {
secret, err := kubeClient.CoreV1().Secrets(config.KyvernoNamespace()).Get(ctx, certs, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("error fetching certificate from secret")
}
cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM(secret.Data["ca.pem"]) {
return nil, fmt.Errorf("credentials: failed to append certificates")
}
transportCreds := credentials.NewClientTLSFromCert(cp, "")
return transportCreds, nil
}