2019-02-06 12:52:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-02-21 18:31:18 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/nirmata/kube-policy/controller"
|
|
|
|
"github.com/nirmata/kube-policy/server"
|
|
|
|
|
|
|
|
"k8s.io/sample-controller/pkg/signals"
|
2019-02-11 17:49:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-02-21 18:31:18 +00:00
|
|
|
masterURL string
|
|
|
|
kubeconfig string
|
|
|
|
cert string
|
|
|
|
key string
|
2019-02-06 12:52:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-02-12 14:30:40 +00:00
|
|
|
flag.Parse()
|
2019-02-11 17:49:27 +00:00
|
|
|
|
2019-02-14 14:36:55 +00:00
|
|
|
if cert == "" || key == "" {
|
2019-02-12 14:30:40 +00:00
|
|
|
log.Fatal("TLS certificate or/and key is not set")
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:31:18 +00:00
|
|
|
crdcLogger := log.New(os.Stdout, "Policy Controller: ", log.LstdFlags|log.Lshortfile)
|
|
|
|
controller, err := controller.NewPolicyController(masterURL, kubeconfig, crdcLogger)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error creating PolicyController! Error: %s\n", err)
|
|
|
|
return
|
|
|
|
}
|
2019-02-07 17:22:04 +00:00
|
|
|
|
2019-02-21 18:31:18 +00:00
|
|
|
httpLogger := log.New(os.Stdout, "HTTPS Server: ", log.LstdFlags|log.Lshortfile)
|
|
|
|
server := server.NewWebhookServer(cert, key, controller, httpLogger)
|
2019-02-07 17:22:04 +00:00
|
|
|
server.RunAsync()
|
|
|
|
|
2019-02-21 18:31:18 +00:00
|
|
|
stopCh := signals.SetupSignalHandler()
|
|
|
|
controller.Run(stopCh)
|
2019-02-11 17:49:27 +00:00
|
|
|
|
2019-02-21 18:31:18 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error running PolicyController! Error: %s\n", err)
|
|
|
|
}
|
2019-02-14 14:36:55 +00:00
|
|
|
|
2019-02-21 18:31:18 +00:00
|
|
|
fmt.Printf("Policy PolicyController has started")
|
|
|
|
<-stopCh
|
|
|
|
server.Stop()
|
|
|
|
fmt.Printf("Policy PolicyController has stopped")
|
2019-02-11 17:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2019-02-21 18:31:18 +00:00
|
|
|
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
|
|
|
|
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
|
|
|
|
flag.StringVar(&cert, "cert", "", "TLS certificate used in connection with cluster.")
|
|
|
|
flag.StringVar(&key, "key", "", "Key, used in TLS connection.")
|
|
|
|
}
|