2019-03-15 19:22:06 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-05-30 12:28:56 -07:00
|
|
|
"github.com/golang/glog"
|
2019-05-29 14:12:09 -07:00
|
|
|
client "github.com/nirmata/kyverno/pkg/dclient"
|
2019-05-21 11:00:09 -07:00
|
|
|
tls "github.com/nirmata/kyverno/pkg/tls"
|
2019-05-29 15:24:19 -07:00
|
|
|
"github.com/nirmata/kyverno/pkg/version"
|
2019-03-15 19:22:06 +02:00
|
|
|
rest "k8s.io/client-go/rest"
|
|
|
|
clientcmd "k8s.io/client-go/tools/clientcmd"
|
|
|
|
)
|
|
|
|
|
2019-05-29 15:24:19 -07:00
|
|
|
func printVersionInfo() {
|
|
|
|
v := version.GetVersion()
|
2019-05-30 12:28:56 -07:00
|
|
|
glog.Infof("Kyverno version: %s\n", v.BuildVersion)
|
|
|
|
glog.Infof("Kyverno BuildHash: %s\n", v.BuildHash)
|
|
|
|
glog.Infof("Kyverno BuildTime: %s\n", v.BuildTime)
|
2019-05-29 15:24:19 -07:00
|
|
|
}
|
|
|
|
|
2019-03-15 19:22:06 +02:00
|
|
|
func createClientConfig(kubeconfig string) (*rest.Config, error) {
|
|
|
|
if kubeconfig == "" {
|
2019-05-30 12:28:56 -07:00
|
|
|
glog.Info("Using in-cluster configuration")
|
2019-03-15 19:22:06 +02:00
|
|
|
return rest.InClusterConfig()
|
|
|
|
}
|
2019-05-30 12:28:56 -07:00
|
|
|
glog.Infof("Using configuration from '%s'", kubeconfig)
|
2019-05-15 18:53:45 -07:00
|
|
|
return clientcmd.BuildConfigFromFlags("", kubeconfig)
|
2019-03-15 19:22:06 +02:00
|
|
|
}
|
|
|
|
|
2019-03-22 22:11:55 +02:00
|
|
|
// Loads or creates PEM private key and TLS certificate for webhook server.
|
|
|
|
// Created pair is stored in cluster's secret.
|
|
|
|
// Returns struct with key/certificate pair.
|
2019-06-05 17:43:59 -07:00
|
|
|
func initTLSPemPair(configuration *rest.Config, client *client.Client) (*tls.TlsPemPair, error) {
|
2019-05-29 12:36:03 -07:00
|
|
|
certProps, err := client.GetTLSCertProps(configuration)
|
2019-03-15 19:22:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
tlsPair := client.ReadTlsPair(certProps)
|
2019-05-14 18:10:25 +03:00
|
|
|
if tls.IsTlsPairShouldBeUpdated(tlsPair) {
|
2019-05-30 12:28:56 -07:00
|
|
|
glog.Info("Generating new key/certificate pair for TLS")
|
2019-03-15 19:22:06 +02:00
|
|
|
tlsPair, err = client.GenerateTlsPemPair(certProps)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = client.WriteTlsPair(certProps, tlsPair)
|
|
|
|
if err != nil {
|
2019-05-30 12:28:56 -07:00
|
|
|
glog.Errorf("Unable to save TLS pair to the cluster: %v", err)
|
2019-03-15 19:22:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return tlsPair, nil
|
2019-03-21 18:09:58 +02:00
|
|
|
}
|