Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce http-endpoint flag #125

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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. `<drivername.example.com>` should be replaced by
Expand Down
17 changes: 15 additions & 2 deletions cmd/csi-node-driver-registrar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"flag"
"fmt"
"os"
"strconv"
"time"

"github.com/kubernetes-csi/csi-lib-utils/metrics"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -144,5 +157,5 @@ func main() {
cmm.SetDriverName(csiDriverName)

// Run forever
nodeRegister(csiDriverName)
nodeRegister(csiDriverName, addr)
}
17 changes: 7 additions & 10 deletions cmd/csi-node-driver-registrar/node_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"os/signal"
"runtime"
"strconv"
"syscall"

"google.golang.org/grpc"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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) {
Expand Down