Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#279 from verult/http-flag
Browse files Browse the repository at this point in the history
Introduce http-endpoint flag
  • Loading branch information
k8s-ci-robot authored Dec 4, 2020
2 parents c09bf1a + 5a67297 commit 681d7a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ When CSI driver supports `LIST_VOLUMES` and `LIST_VOLUMES_PUBLISHED_NODES` capab

### HTTP endpoint

The external-attacher optionally exposes an HTTP endpoint at address:port specified by `--metrics-address` argument. When set, these two paths are exposed:
The external-attacher optionally exposes an HTTP endpoint at address:port specified by `--http-endpoint` argument. When set, these two paths are exposed:

* Metrics path, as set by `--metrics-path` argument (default is `/metrics`).
* Leader election health check at `/healthz/leader-election`. It is recommended to run a liveness probe against this endpoint when leader election is used to kill external-attacher leader that fails to connect to the API server to renew its leadership. See https://github.com/kubernetes-csi/csi-lib-utils/issues/66 for details.
Expand Down
20 changes: 16 additions & 4 deletions cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ var (

reconcileSync = flag.Duration("reconcile-sync", 1*time.Minute, "Resync interval of the VolumeAttachment reconciler.")

metricsAddress = flag.String("metrics-address", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
metricsAddress = flag.String("metrics-address", "", "(deprecated) The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: :8080). The default is empty string, which means the server is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
)

Expand All @@ -91,6 +92,15 @@ func main() {
}
klog.Infof("Version: %s", version)

if *metricsAddress != "" && *httpEndpoint != "" {
klog.Error("only one of `--metrics-address` and `--http-endpoint` can be set.")
os.Exit(1)
}
addr := *metricsAddress
if addr == "" {
addr = *httpEndpoint
}

// Create the client config. Use kubeconfig if given, otherwise assume in-cluster.
config, err := buildConfig(*kubeconfig)
if err != nil {
Expand Down Expand Up @@ -138,11 +148,11 @@ func main() {

// Prepare http endpoint for metrics + leader election healthz
mux := http.NewServeMux()
if *metricsAddress != "" {
if addr != "" {
metricsManager.RegisterToServer(mux, *metricsPath)
metricsManager.SetDriverName(csiAttacher)
go func() {
err := http.ListenAndServe(*metricsAddress, mux)
err := http.ListenAndServe(addr, mux)
if err != nil {
klog.Fatalf("Failed to start Prometheus metrics endpoint on specified address (%q) and path (%q): %s", *metricsAddress, *metricsPath, err)
}
Expand Down Expand Up @@ -219,7 +229,9 @@ func main() {
// Name of config map with leader election lock
lockName := "external-attacher-leader-" + csiAttacher
le := leaderelection.NewLeaderElection(leClientset, lockName, run)
le.PrepareHealthCheck(mux, leaderelection.DefaultHealthCheckTimeout)
if *httpEndpoint != "" {
le.PrepareHealthCheck(mux, leaderelection.DefaultHealthCheckTimeout)
}

if *leaderElectionNamespace != "" {
le.WithNamespace(*leaderElectionNamespace)
Expand Down
6 changes: 3 additions & 3 deletions deploy/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
- "--v=5"
- "--csi-address=$(ADDRESS)"
- "--leader-election"
- "--metrics-address=:8080"
- "--http-endpoint=:8080"
env:
- name: MY_NAME
valueFrom:
Expand All @@ -52,13 +52,13 @@ spec:
mountPath: /var/lib/csi/sockets/pluginproxy/
ports:
- containerPort: 8080
name: metrics
name: http-endpoint
protocol: TCP
livenessProbe:
failureThreshold: 1
httpGet:
path: /healthz/leader-election
port: metrics
port: http-endpoint
initialDelaySeconds: 10
timeoutSeconds: 10
periodSeconds: 20
Expand Down

0 comments on commit 681d7a4

Please sign in to comment.