diff --git a/README.md b/README.md index 61d953041..b5e59f6ca 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,13 @@ There are two UNIX domain sockets used by the node-driver-registrar: ### Optional arguments -* `--health-port`: This is the port of the health check server for the node-driver-registrar, - which checks if the registration socket exists. A value <= 0 disables the server. - Server is disabled by default. +* `--http-endpoint`: "The TCP network address where the HTTP server for diagnostics, including + the health check indicating whether the registration socket exists, will listen (example: + `:8080`). The default is empty string, which means the server is disabled. + +* `--health-port`: (deprecated) This is the port of the health check server for the + node-driver-registrar, which checks if the registration socket exists. A value <= 0 disables + the server. Server is disabled by default. ### Required permissions @@ -70,6 +74,11 @@ permissions to: * Access the registration socket (typically in `/var/lib/kubelet/plugins_registry/`). * Used by the `node-driver-registrar` to register the driver with kubelet. +### Health Check + +If `--http-endpoint` is set, the node-driver-registrar exposes a health check endpoint at the +specified address and the path `/healthz`, indicating whether the registration socket exists. + ### Example Here is an example sidecar spec in the driver DaemonSet. `` should be replaced by diff --git a/cmd/csi-node-driver-registrar/main.go b/cmd/csi-node-driver-registrar/main.go index 8c6fe4926..5f1a34649 100644 --- a/cmd/csi-node-driver-registrar/main.go +++ b/cmd/csi-node-driver-registrar/main.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "os" + "strconv" "time" "github.com/kubernetes-csi/csi-lib-utils/metrics" @@ -49,7 +50,8 @@ var ( csiAddress = flag.String("csi-address", "/run/csi/socket", "Path of the CSI driver socket that the node-driver-registrar will connect to.") pluginRegistrationPath = flag.String("plugin-registration-path", "/registration", "Path to Kubernetes plugin registration directory.") kubeletRegistrationPath = flag.String("kubelet-registration-path", "", "Path of the CSI driver socket on the Kubernetes host machine.") - healthzPort = flag.Int("health-port", 0, "TCP port for healthz requests. Set to 0 to disable the healthz server.") + healthzPort = flag.Int("health-port", 0, "(deprecated) TCP port for healthz requests. Set to 0 to disable the healthz server. Only one of `--health-port` and `--http-endpoint` can be set.") + httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including the health check indicating whether the registration socket exists, will listen (example: `:8080`). The default is empty string, which means the server is disabled. Only one of `--health-port` and `--http-endpoint` can be set.") showVersion = flag.Bool("version", false, "Show version.") version = "unknown" @@ -112,6 +114,17 @@ func main() { } klog.Infof("Version: %s", version) + if *healthzPort > 0 && *httpEndpoint != "" { + klog.Error("only one of `--health-port` and `--http-endpoint` can be set.") + os.Exit(1) + } + var addr string + if *healthzPort > 0 { + addr = ":" + strconv.Itoa(*healthzPort) + } else { + addr = *httpEndpoint + } + if *connectionTimeout != 0 { klog.Warning("--connection-timeout is deprecated and will have no effect") } @@ -144,5 +157,5 @@ func main() { cmm.SetDriverName(csiDriverName) // Run forever - nodeRegister(csiDriverName) + nodeRegister(csiDriverName, addr) } diff --git a/cmd/csi-node-driver-registrar/node_register.go b/cmd/csi-node-driver-registrar/node_register.go index 3a412ff95..51f2e001d 100644 --- a/cmd/csi-node-driver-registrar/node_register.go +++ b/cmd/csi-node-driver-registrar/node_register.go @@ -23,7 +23,6 @@ import ( "os" "os/signal" "runtime" - "strconv" "syscall" "google.golang.org/grpc" @@ -33,9 +32,7 @@ import ( registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1" ) -func nodeRegister( - csiDriverName string, -) { +func nodeRegister(csiDriverName, httpEndpoint string) { // When kubeletRegistrationPath is specified then driver-registrar ONLY acts // as gRPC server which replies to registration requests initiated by kubelet's // pluginswatcher infrastructure. Node labeling is done by kubelet's csi code. @@ -66,7 +63,7 @@ func nodeRegister( // Registers kubelet plugin watcher api. registerapi.RegisterRegistrationServer(grpcServer, registrar) - go healthzServer(socketPath, *healthzPort) + go healthzServer(socketPath, httpEndpoint) go removeRegSocket(csiDriverName) // Starts service if err := grpcServer.Serve(lis); err != nil { @@ -81,12 +78,12 @@ func buildSocketPath(csiDriverName string) string { return fmt.Sprintf("%s/%s-reg.sock", *pluginRegistrationPath, csiDriverName) } -func healthzServer(socketPath string, port int) { - if port <= 0 { - klog.Infof("Skipping healthz server because port set to: %v", port) +func healthzServer(socketPath string, httpEndpoint string) { + if httpEndpoint == "" { + klog.Infof("Skipping healthz server because HTTP endpoint is set to: %q", httpEndpoint) return } - klog.Infof("Starting healthz server on port: %v\n", port) + klog.Infof("Starting healthz server at HTTP endpoint: %v\n", httpEndpoint) http.HandleFunc("/healthz", func(w http.ResponseWriter, req *http.Request) { socketExists, err := util.DoesSocketExist(socketPath) @@ -105,7 +102,7 @@ func healthzServer(socketPath string, port int) { } }) - klog.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), nil)) + klog.Fatal(http.ListenAndServe(httpEndpoint, nil)) } func removeRegSocket(csiDriverName string) {