Skip to content

Commit 42797a2

Browse files
authored
Merge pull request #14 from sbezverk/travis_tests
Update dependency
2 parents 2d6a005 + bf9b842 commit 42797a2

File tree

1,255 files changed

+410998
-86355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,255 files changed

+410998
-86355
lines changed

.travis.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
language: go
22

3+
services:
4+
- docker
5+
6+
# Needed for e2e tests
37
sudo: true
4-
go: 1.9.x
8+
9+
go: 1.10.x
510
go_import_path: github.com/kubernetes-csi/livenessprobe
611
install:
712
- go get -u github.com/golang/dep/cmd/dep
@@ -11,6 +16,7 @@ script:
1116
- go fmt $(go list ./... | grep -v vendor) | wc -l | grep 0
1217
- go vet $(go list ./... | grep -v vendor)
1318
- go test $(go list ./... | grep -v vendor)
19+
- ./hack/e2e-livenessprobe.sh
1420
after_success:
1521
- if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
1622
sudo make livenessprobe-container;

Gopkg.lock

+86-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323

2424
[[constraint]]
2525
name = "github.com/container-storage-interface/spec"
26-
version = "0.2.0-rc1"
26+
version = "~0.3.0"
2727

2828
[[constraint]]
2929
branch = "master"
3030
name = "github.com/golang/glog"
3131

32-
[[constraint]]
33-
name = "github.com/golang/mock"
34-
version = "1.0.0"
35-
3632
[[constraint]]
3733
branch = "master"
3834
name = "github.com/kubernetes-csi/csi-test"
3935

4036
[[constraint]]
4137
name = "google.golang.org/grpc"
4238
version = "1.10.0"
39+
40+
[[constraint]]
41+
name = "github.com/golang/mock"
42+
version = "1.1.1"

cmd/livenessprobe_test.go

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"testing"
22+
"time"
23+
24+
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
25+
"github.com/golang/mock/gomock"
26+
"github.com/kubernetes-csi/csi-test/driver"
27+
"github.com/kubernetes-csi/livenessprobe/pkg/connection"
28+
)
29+
30+
const (
31+
driverName = "foo/bar"
32+
)
33+
34+
func createMockServer(t *testing.T) (
35+
*gomock.Controller,
36+
*driver.MockCSIDriver,
37+
*driver.MockIdentityServer,
38+
*driver.MockControllerServer,
39+
*driver.MockNodeServer,
40+
connection.CSIConnection,
41+
error) {
42+
// Start the mock server
43+
mockController := gomock.NewController(t)
44+
identityServer := driver.NewMockIdentityServer(mockController)
45+
controllerServer := driver.NewMockControllerServer(mockController)
46+
nodeServer := driver.NewMockNodeServer(mockController)
47+
drv := driver.NewMockCSIDriver(&driver.MockCSIDriverServers{
48+
Identity: identityServer,
49+
Controller: controllerServer,
50+
Node: nodeServer,
51+
})
52+
drv.Start()
53+
54+
// Create a client connection to it
55+
addr := drv.Address()
56+
csiConn, err := connection.NewConnection(addr, 10)
57+
if err != nil {
58+
return nil, nil, nil, nil, nil, nil, err
59+
}
60+
61+
return mockController, drv, identityServer, controllerServer, nodeServer, csiConn, nil
62+
}
63+
64+
func TestProbe(t *testing.T) {
65+
mockController, driver, idServer, _, nodeServer, csiConn, err := createMockServer(t)
66+
if err != nil {
67+
t.Fatal(err)
68+
}
69+
defer mockController.Finish()
70+
defer driver.Stop()
71+
defer csiConn.Close()
72+
73+
// Setting up expected calls' responses
74+
inPlugin := &csi.GetPluginInfoRequest{}
75+
outPlugin := &csi.GetPluginInfoResponse{
76+
Name: "foo/bar",
77+
}
78+
var injectedErr error
79+
idServer.EXPECT().GetPluginInfo(gomock.Any(), inPlugin).Return(outPlugin, injectedErr).Times(1)
80+
81+
inNode := &csi.NodeGetIdRequest{}
82+
outNode := &csi.NodeGetIdResponse{
83+
NodeId: "test_node_id",
84+
}
85+
nodeServer.EXPECT().NodeGetId(gomock.Any(), inNode).Return(outNode, injectedErr).Times(1)
86+
inProbe := &csi.ProbeRequest{}
87+
outProbe := &csi.ProbeResponse{}
88+
idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1)
89+
// Calling Probing function
90+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
91+
defer cancel()
92+
if err := runProbe(ctx, csiConn); err != nil {
93+
t.Fatalf("failed to run probe with error: %+v", err)
94+
}
95+
}

cmd/main.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@ var (
4141
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
4242
)
4343

44-
func runProbe(ctx context.Context) error {
45-
46-
// Connect to CSI.
47-
glog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
48-
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
49-
if err != nil {
50-
return err
51-
}
44+
func runProbe(ctx context.Context, csiConn connection.CSIConnection) error {
5245

5346
// Get CSI driver name.
5447
glog.Infof("Calling CSI driver to discover driver name.")
@@ -74,13 +67,29 @@ func runProbe(ctx context.Context) error {
7467
return nil
7568
}
7669

70+
func getCSIConnection() (connection.CSIConnection, error) {
71+
// Connect to CSI.
72+
glog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
73+
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
74+
if err != nil {
75+
return nil, err
76+
}
77+
return csiConn, nil
78+
}
79+
7780
func chekcHealth(w http.ResponseWriter, req *http.Request) {
7881

7982
glog.Infof("Request: %s from: %s\n", req.URL.Path, req.RemoteAddr)
83+
csiConn, err := getCSIConnection()
84+
if err != nil {
85+
w.WriteHeader(http.StatusInternalServerError)
86+
w.Write([]byte(err.Error()))
87+
glog.Infof("Failed to get connection to CSI with error: %v.", err)
88+
return
89+
}
8090
ctx, cancel := context.WithTimeout(context.Background(), *connectionTimeout)
8191
defer cancel()
82-
err := runProbe(ctx)
83-
if err != nil {
92+
if err := runProbe(ctx, csiConn); err != nil {
8493
w.WriteHeader(http.StatusInternalServerError)
8594
w.Write([]byte(err.Error()))
8695
glog.Infof("Health check failed with: %v.", err)

hack/e2e-livenessprobe.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -x
3+
4+
## This file is for livenessprove which runs in a pair with csi
5+
## hostpath
6+
7+
## Must be run from the root of the repo
8+
UDS="/tmp/e2e-csi-sanity.sock"
9+
CSI_ENDPOINT="unix://${UDS}"
10+
CSI_MOUNTPOINT="/mnt"
11+
APP=hostpathplugin
12+
13+
SKIP="WithCapacity"
14+
if [ x${TRAVIS} = x"true" ] ; then
15+
SKIP="WithCapacity|NodeUnpublishVolume|NodePublishVolume"
16+
fi
17+
18+
git clone https://github.com/kubernetes-csi/drivers $GOPATH/src/github.com/kubernetes-csi/drivers
19+
pushd $GOPATH/src/github.com/kubernetes-csi/drivers
20+
# Build
21+
make hostpath; ret=$?
22+
if [ $ret -ne 0 ]; then
23+
echo "Failed to build hostpath plugin, file a bug against drivers repo"
24+
exit 1
25+
fi
26+
popd
27+
28+
sudo rm -rf "$UDS" || true
29+
30+
# Start hostpathplugin in the background
31+
sudo $GOPATH/src/github.com/kubernetes-csi/drivers/_output/$APP --endpoint=$CSI_ENDPOINT --nodeid=1 --v=5 &
32+
33+
# Start liveness probe in the background
34+
sudo ./bin/livenessprobe --csi-address=$CSI_ENDPOINT &
35+
36+
# Give time to CSI hostpathplugin and livenessprobe to initialize
37+
sleep 3
38+
39+
# Requesting health
40+
health=$(curl -I http://localhost:9808/healthz | grep HTTP | awk '{print $2}')
41+
if [[ "x$health" != "x200" ]]; then
42+
echo "Health check failed, but it was not supposed to, exiting..."
43+
exit 1
44+
fi
45+
46+
# Killing hostpathplugin
47+
sudo kill -9 $(pidof hostpathplugin)
48+
sleep 3
49+
50+
# Requesting health, should fail since hostpathplugin is gone
51+
health=$(curl -I http://localhost:9808/healthz| grep HTTP | awk '{print $2}')
52+
if [[ "x$health" != "x500" ]]; then
53+
echo "Health check did not detect driver failure, returned code: $health, exiting..."
54+
exit 1
55+
fi
56+
57+
sudo rm -f $UDS
58+
exit 0

0 commit comments

Comments
 (0)