Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial bits for livenessprobe #3

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: go

# Needed for e2e tests
sudo: true
go: 1.9.x
go_import_path: github.com/kubernetes-csi/drivers
install:
- go get -u github.com/golang/dep/cmd/dep
- dep ensure -vendor-only
- make hostpath
script:
- go fmt $(go list ./... | grep -v vendor) | wc -l | grep 0
- go vet $(go list ./... | grep -v vendor)
- go test $(go list ./... | grep -v vendor)
- ./hack/e2e-hostpath.sh
63 changes: 63 additions & 0 deletions Gopkg.lock

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

42 changes: 42 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/container-storage-interface/spec"
version = "0.2.0-rc1"

[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/golang/mock"
version = "1.0.0"

[[constraint]]
branch = "master"
name = "github.com/kubernetes-csi/csi-test"

[[constraint]]
name = "google.golang.org/grpc"
version = "1.10.0"
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: all liveness clean test

ifdef V
TESTARGS = -v -args -alsologtostderr -v 5
else
TESTARGS =
endif

all: livenessprobe

livenessprobe:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o ./bin/livenessprobe ./cmd

macos-livenessprobe:
mkdir -p bin
CGO_ENABLED=0 GOOS=darwin go build -a -ldflags '-extldflags "-static"' -o ./bin/livenessprobe.osx ./cmd

clean:
rm -rf bin

test:
go test `go list ./... | grep -v 'vendor'` $(TESTARGS)
go vet `go list ./... | grep -v vendor`
87 changes: 87 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"context"
"flag"
"os"
"time"

"github.com/golang/glog"

"github.com/kubernetes-csi/livenessprobe/pkg/connection"
)

const (
// Default timeout of short CSI calls like GetPluginInfo
csiTimeout = time.Second
)

// Command line flags
var (
// kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
connectionTimeout = flag.Duration("connection-timeout", 30*time.Second, "Timeout for waiting for CSI driver socket in seconds.")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
)

func main() {
flag.Set("logtostderr", "true")
flag.Parse()

// Connect to CSI.
glog.V(1).Infof("Attempting to open a gRPC connection with: %q", csiAddress)
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
if err != nil {
glog.Error(err.Error())
os.Exit(1)
}

// Get CSI driver name.
glog.V(1).Infof("Calling CSI driver to discover driver name.")
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
defer cancel()
csiDriverName, err := csiConn.GetDriverName(ctx)
if err != nil {
glog.Error(err.Error())
os.Exit(1)
}
glog.V(2).Infof("CSI driver name: %q", csiDriverName)

// Get CSI Driver Node ID
glog.V(1).Infof("Calling CSI driver to discover node ID.")
ctx, cancel = context.WithTimeout(context.Background(), csiTimeout)
defer cancel()
csiDriverNodeID, err := csiConn.NodeGetId(ctx)
if err != nil {
glog.Error(err.Error())
os.Exit(1)
}
glog.V(2).Infof("CSI driver node ID: %q", csiDriverNodeID)

// Sending Probe request
glog.V(1).Infof("Sending probe request to CSI driver.")
ctx, cancel = context.WithTimeout(context.Background(), csiTimeout)
defer cancel()
err = csiConn.LivenessProbe(ctx)
if err != nil {
glog.Error(err.Error())
os.Exit(1)
}
// Liveness Probe was sucessfuly
os.Exit(0)
}
Loading