mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
fdfdcc058f
Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
30 lines
777 B
Go
30 lines
777 B
Go
package tls
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
|
corev1 "k8s.io/api/core/v1"
|
|
corev1listers "k8s.io/client-go/listers/core/v1"
|
|
)
|
|
|
|
var ErrorsNotFound = "root CA certificate not found"
|
|
|
|
// ReadRootCASecret returns the RootCA from the pre-defined secret
|
|
func ReadRootCASecret(client corev1listers.SecretNamespaceLister) ([]byte, error) {
|
|
sname := GenerateRootCASecretName()
|
|
stlsca, err := client.Get(sname)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// try "tls.crt"
|
|
result := stlsca.Data[corev1.TLSCertKey]
|
|
// if not there, try old "rootCA.crt"
|
|
if len(result) == 0 {
|
|
result = stlsca.Data[rootCAKey]
|
|
}
|
|
if len(result) == 0 {
|
|
return nil, fmt.Errorf("%s in secret %s/%s", ErrorsNotFound, config.KyvernoNamespace(), stlsca.Name)
|
|
}
|
|
return result, nil
|
|
}
|