Skip to content

Commit

Permalink
Fix leak memory and upgrade csi-lib-util dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiawei0227 committed Dec 8, 2020
1 parent e63e79e commit c3d186e
Show file tree
Hide file tree
Showing 321 changed files with 33,603 additions and 94,557 deletions.
13 changes: 11 additions & 2 deletions cmd/livenessprobe/livenessprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

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

Expand Down Expand Up @@ -83,7 +84,11 @@ func TestProbe(t *testing.T) {
outProbe := &csi.ProbeResponse{}
idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1)

hp := &healthProbe{driverName: driverName}
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
hp := &healthProbe{
driverName: driverName,
metricsManager: &metricsManager,
}

server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.String() == "/healthz" {
Expand Down Expand Up @@ -121,7 +126,11 @@ func TestProbe_issue68(t *testing.T) {
outProbe := &csi.ProbeResponse{}
idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1)

hp := &healthProbe{driverName: driverName}
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
hp := &healthProbe{
driverName: driverName,
metricsManager: &metricsManager,
}

server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.String() == "/healthz" {
Expand Down
20 changes: 12 additions & 8 deletions cmd/livenessprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"flag"
"net"
"net/http"
_ "net/http/pprof"
"sync"
"time"

Expand All @@ -42,14 +43,15 @@ var (
)

type healthProbe struct {
driverName string
driverName string
metricsManager *metrics.CSIMetricsManager
}

func (h *healthProbe) checkProbe(w http.ResponseWriter, req *http.Request) {
ctx, cancel := context.WithTimeout(req.Context(), *probeTimeout)
defer cancel()

conn, err := acquireConnection(ctx, metrics.NewCSIMetricsManager(""))
conn, err := acquireConnection(ctx, *h.metricsManager)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand Down Expand Up @@ -114,7 +116,7 @@ func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()
metricsManager := metrics.NewCSIMetricsManager("")
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
csiConn, err := acquireConnection(context.Background(), metricsManager)
if err != nil {
// connlib should retry forever so a returned error should mean
Expand All @@ -131,16 +133,18 @@ func main() {
klog.Infof("CSI driver name: %q", csiDriverName)

hp := &healthProbe{
driverName: csiDriverName,
driverName: csiDriverName,
metricsManager: &metricsManager,
}

mux := http.NewServeMux()
addr := net.JoinHostPort("0.0.0.0", *healthzPort)
metricsManager.RegisterToServer(mux, *metricsPath)
metricsManager.SetDriverName(csiDriverName)
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)

addr := net.JoinHostPort("0.0.0.0", *healthzPort)
http.HandleFunc("/healthz", hp.checkProbe)
mux.HandleFunc("/healthz", hp.checkProbe)
klog.Infof("Serving requests to /healthz on: %s", addr)
err = http.ListenAndServe(addr, nil)
err = http.ListenAndServe(addr, mux)
if err != nil {
klog.Fatalf("failed to start http server with error: %v", err)
}
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ go 1.15
require (
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-lib-utils v0.9.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/grpc v1.29.0
k8s.io/klog/v2 v2.3.0
)
247 changes: 174 additions & 73 deletions go.sum

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

0 comments on commit c3d186e

Please sign in to comment.