Skip to content

Commit 2108b7a

Browse files
authored
Merge pull request #3 from sbezverk/master
Initial bits for livenessprobe
2 parents c6c4659 + 11b8f5c commit 2108b7a

File tree

1,741 files changed

+1019655
-0
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,741 files changed

+1019655
-0
lines changed

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: go
2+
3+
# Needed for e2e tests
4+
sudo: true
5+
go: 1.9.x
6+
go_import_path: github.com/kubernetes-csi/drivers
7+
install:
8+
- go get -u github.com/golang/dep/cmd/dep
9+
- dep ensure -vendor-only
10+
- make hostpath
11+
script:
12+
- go fmt $(go list ./... | grep -v vendor) | wc -l | grep 0
13+
- go vet $(go list ./... | grep -v vendor)
14+
- go test $(go list ./... | grep -v vendor)
15+
- ./hack/e2e-hostpath.sh

Gopkg.lock

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

Gopkg.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# Gopkg.toml example
3+
#
4+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5+
# for detailed Gopkg.toml documentation.
6+
#
7+
# required = ["github.com/user/thing/cmd/thing"]
8+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9+
#
10+
# [[constraint]]
11+
# name = "github.com/user/project"
12+
# version = "1.0.0"
13+
#
14+
# [[constraint]]
15+
# name = "github.com/user/project2"
16+
# branch = "dev"
17+
# source = "github.com/myfork/project2"
18+
#
19+
# [[override]]
20+
# name = "github.com/x/y"
21+
# version = "2.4.0"
22+
23+
24+
[[constraint]]
25+
name = "github.com/container-storage-interface/spec"
26+
version = "0.2.0-rc1"
27+
28+
[[constraint]]
29+
branch = "master"
30+
name = "github.com/golang/glog"
31+
32+
[[constraint]]
33+
name = "github.com/golang/mock"
34+
version = "1.0.0"
35+
36+
[[constraint]]
37+
branch = "master"
38+
name = "github.com/kubernetes-csi/csi-test"
39+
40+
[[constraint]]
41+
name = "google.golang.org/grpc"
42+
version = "1.10.0"

Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2017 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
.PHONY: all liveness clean test
16+
17+
ifdef V
18+
TESTARGS = -v -args -alsologtostderr -v 5
19+
else
20+
TESTARGS =
21+
endif
22+
23+
all: livenessprobe
24+
25+
livenessprobe:
26+
mkdir -p bin
27+
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o ./bin/livenessprobe ./cmd
28+
29+
macos-livenessprobe:
30+
mkdir -p bin
31+
CGO_ENABLED=0 GOOS=darwin go build -a -ldflags '-extldflags "-static"' -o ./bin/livenessprobe.osx ./cmd
32+
33+
clean:
34+
rm -rf bin
35+
36+
test:
37+
go test `go list ./... | grep -v 'vendor'` $(TESTARGS)
38+
go vet `go list ./... | grep -v vendor`

cmd/main.go

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
"flag"
22+
"os"
23+
"time"
24+
25+
"github.com/golang/glog"
26+
27+
"github.com/kubernetes-csi/livenessprobe/pkg/connection"
28+
)
29+
30+
const (
31+
// Default timeout of short CSI calls like GetPluginInfo
32+
csiTimeout = time.Second
33+
)
34+
35+
// Command line flags
36+
var (
37+
// kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
38+
connectionTimeout = flag.Duration("connection-timeout", 30*time.Second, "Timeout for waiting for CSI driver socket in seconds.")
39+
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
40+
)
41+
42+
func main() {
43+
flag.Set("logtostderr", "true")
44+
flag.Parse()
45+
46+
// Connect to CSI.
47+
glog.V(1).Infof("Attempting to open a gRPC connection with: %q", csiAddress)
48+
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
49+
if err != nil {
50+
glog.Error(err.Error())
51+
os.Exit(1)
52+
}
53+
54+
// Get CSI driver name.
55+
glog.V(1).Infof("Calling CSI driver to discover driver name.")
56+
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
57+
defer cancel()
58+
csiDriverName, err := csiConn.GetDriverName(ctx)
59+
if err != nil {
60+
glog.Error(err.Error())
61+
os.Exit(1)
62+
}
63+
glog.V(2).Infof("CSI driver name: %q", csiDriverName)
64+
65+
// Get CSI Driver Node ID
66+
glog.V(1).Infof("Calling CSI driver to discover node ID.")
67+
ctx, cancel = context.WithTimeout(context.Background(), csiTimeout)
68+
defer cancel()
69+
csiDriverNodeID, err := csiConn.NodeGetId(ctx)
70+
if err != nil {
71+
glog.Error(err.Error())
72+
os.Exit(1)
73+
}
74+
glog.V(2).Infof("CSI driver node ID: %q", csiDriverNodeID)
75+
76+
// Sending Probe request
77+
glog.V(1).Infof("Sending probe request to CSI driver.")
78+
ctx, cancel = context.WithTimeout(context.Background(), csiTimeout)
79+
defer cancel()
80+
err = csiConn.LivenessProbe(ctx)
81+
if err != nil {
82+
glog.Error(err.Error())
83+
os.Exit(1)
84+
}
85+
// Liveness Probe was sucessfuly
86+
os.Exit(0)
87+
}

0 commit comments

Comments
 (0)