in cmd/main.go [58:160]
func main() {
klog.InitFlags(nil)
defer klog.Flush()
flag.Parse()
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
if *logFormatJSON {
jsonFactory := json.Factory{}
logger, _ := jsonFactory.Create(logsapi.LoggingConfiguration{Format: "json"})
klog.SetLogger(logger)
}
if *versionInfo {
if err := version.PrintVersion(); err != nil {
klog.ErrorS(err, "failed to print version")
os.Exit(1)
}
os.Exit(0)
}
klog.InfoS("Starting Azure Key Vault Provider", "version", version.BuildVersion)
cloudEnv, err := azure.EnvironmentFromName(*cloudName)
if err != nil {
klog.ErrorS(err, "failed validating default cloud environment", "cloudName", *cloudName)
os.Exit(1)
}
if *enableProfile {
klog.InfoS("Starting profiling", "port", *profilePort)
go func() {
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", "localhost", *profilePort),
ReadHeaderTimeout: readHeaderTimeout,
}
klog.ErrorS(server.ListenAndServe(), "unable to start profiling server")
}()
}
// initialize metrics exporter before creating measurements
if err = metrics.InitMetricsExporter(*metricsBackend, *prometheusPort); err != nil {
klog.ErrorS(err, "failed to initialize metrics exporter")
os.Exit(1)
}
if *constructPEMChain {
klog.Infof("construct pem chain feature enabled")
}
if *writeCertAndKeyInSeparateFiles {
klog.Infof("write cert and key in separate files feature enabled")
}
// Initialize and run the gRPC server
proto, addr, err := utils.ParseEndpoint(*endpoint)
if err != nil {
klog.ErrorS(err, "failed to parse endpoint")
os.Exit(1)
}
if proto == "unix" {
if runtime.GOOS != "windows" {
addr = "/" + addr
}
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
klog.ErrorS(err, "failed to remove socket", "addr", addr)
os.Exit(1)
}
}
listener, err := net.Listen(proto, addr)
if err != nil {
klog.ErrorS(err, "failed to listen", "proto", proto, "addr", addr)
os.Exit(1)
}
opts := []grpc.ServerOption{
grpc.UnaryInterceptor(utils.LogInterceptor()),
}
s := grpc.NewServer(opts...)
csiDriverProviderServer := server.New(*constructPEMChain, *writeCertAndKeyInSeparateFiles, cloudEnv)
k8spb.RegisterCSIDriverProviderServer(s, csiDriverProviderServer)
// Register the health service.
grpc_health_v1.RegisterHealthServer(s, csiDriverProviderServer)
klog.InfoS("Listening for connections", "address", listener.Addr())
go s.Serve(listener)
healthz := &server.HealthZ{
HealthCheckURL: &url.URL{
Host: net.JoinHostPort("", strconv.Itoa(*healthzPort)),
Path: *healthzPath,
},
UnixSocketPath: listener.Addr().String(),
RPCTimeout: *healthzTimeout,
}
go healthz.Serve()
<-signalChan
// gracefully stop the grpc server
klog.Infof("terminating the server")
s.GracefulStop()
}