Skip to content

Commit

Permalink
Merge pull request #70 from humblec/livenessprobe
Browse files Browse the repository at this point in the history
Correct connlib.Connect and update dependencies.
  • Loading branch information
k8s-ci-robot authored Aug 24, 2020
2 parents 094ef04 + 7f7b14d commit 6fd0ae8
Show file tree
Hide file tree
Showing 667 changed files with 162,635 additions and 56,962 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ spec:

* `--probe-timeout <duration>`: Maximum duration of single `Probe()` call (default "1s").

* `--metrics-address <port>`: The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.

* `--metrics-path <path>`: The HTTP path where prometheus metrics will be exposed. Default is `/metrics`."

* All glog / klog arguments are supported, such as `-v <log level>` or `-alsologtostderr`.

## Community, discussion, contribution, and support
Expand Down
2 changes: 1 addition & 1 deletion cmd/livenessprobe/livenessprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/mock/gomock"
"github.com/kubernetes-csi/csi-test/driver"
"github.com/kubernetes-csi/csi-test/v4/driver"
)

const (
Expand Down
28 changes: 17 additions & 11 deletions cmd/livenessprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ import (
"sync"
"time"

"k8s.io/klog"
"google.golang.org/grpc"
"k8s.io/klog/v2"

connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
"github.com/kubernetes-csi/csi-lib-utils/rpc"

"google.golang.org/grpc"
)

// Command line flags
var (
probeTimeout = flag.Duration("probe-timeout", time.Second, "Probe timeout in seconds")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
probeTimeout = flag.Duration("probe-timeout", time.Second, "Probe timeout in seconds")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
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.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
)

type healthProbe struct {
Expand All @@ -47,7 +49,7 @@ func (h *healthProbe) checkProbe(w http.ResponseWriter, req *http.Request) {
ctx, cancel := context.WithTimeout(req.Context(), *probeTimeout)
defer cancel()

conn, err := acquireConnection(ctx)
conn, err := acquireConnection(ctx, metrics.NewCSIMetricsManager(""))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand Down Expand Up @@ -79,12 +81,13 @@ func (h *healthProbe) checkProbe(w http.ResponseWriter, req *http.Request) {

// acquireConnection wraps the connlib.Connect but adding support to context
// cancelation.
func acquireConnection(ctx context.Context) (conn *grpc.ClientConn, err error) {
func acquireConnection(ctx context.Context, metricsManager metrics.CSIMetricsManager) (conn *grpc.ClientConn, err error) {

var m sync.Mutex
var canceled bool
ready := make(chan bool)
go func() {
conn, err = connlib.Connect(*csiAddress)
conn, err = connlib.Connect(*csiAddress, metricsManager)

m.Lock()
defer m.Unlock()
Expand All @@ -111,8 +114,8 @@ func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

csiConn, err := acquireConnection(context.Background())
metricsManager := metrics.NewCSIMetricsManager("")
csiConn, err := acquireConnection(context.Background(), metricsManager)
if err != nil {
// connlib should retry forever so a returned error should mean
// the grpc client is misconfigured rather than an error on the network
Expand All @@ -131,6 +134,9 @@ func main() {
driverName: csiDriverName,
}

metricsManager.SetDriverName(csiDriverName)
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)

addr := net.JoinHostPort("0.0.0.0", *healthzPort)
http.HandleFunc("/healthz", hp.checkProbe)
klog.Infof("Serving requests to /healthz on: %s", addr)
Expand Down
21 changes: 9 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
module github.com/kubernetes-csi/livenessprobe

go 1.12
go 1.15

require (
github.com/container-storage-interface/spec v1.1.0
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.3.1 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.6.1
github.com/kubernetes-csi/csi-test v2.0.0+incompatible
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
github.com/container-storage-interface/spec v1.3.0
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.4.2 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.7.0
github.com/kubernetes-csi/csi-test/v4 v4.0.0-20200806214950-555d70a11a8b
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect
google.golang.org/grpc v1.20.0
k8s.io/klog v0.3.0
google.golang.org/grpc v1.29.0
k8s.io/klog/v2 v2.3.0
)
Loading

0 comments on commit 6fd0ae8

Please sign in to comment.