provide more driver info in logs
This commit is contained in:
parent
ab42e03317
commit
38780f4630
11
Makefile
11
Makefile
@ -24,9 +24,12 @@ DOCKER_CLI_EXPERIMENTAL = enabled
|
|||||||
export GOPATH GOBIN GO111MODULE DOCKER_CLI_EXPERIMENTAL
|
export GOPATH GOBIN GO111MODULE DOCKER_CLI_EXPERIMENTAL
|
||||||
|
|
||||||
include release-tools/build.make
|
include release-tools/build.make
|
||||||
LDFLAGS = "-X ${PKG}/pkg/nfs.driverVersion=${IMAGE_VERSION} -s -w -extldflags '-static'"
|
|
||||||
GIT_COMMIT ?= $(shell git rev-parse HEAD)
|
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||||
IMAGE_VERSION ?= v3.0.0
|
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
IMAGE_VERSION = v3.0.0
|
||||||
|
LDFLAGS = -X ${PKG}/pkg/nfs.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/nfs.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/nfs.buildDate=${BUILD_DATE}
|
||||||
|
EXT_LDFLAGS = -s -w -extldflags "-static"
|
||||||
# Use a custom version for E2E tests if we are testing in CI
|
# Use a custom version for E2E tests if we are testing in CI
|
||||||
ifdef CI
|
ifdef CI
|
||||||
ifndef PUBLISH
|
ifndef PUBLISH
|
||||||
@ -82,7 +85,7 @@ local-k8s-uninstall:
|
|||||||
|
|
||||||
.PHONY: nfs
|
.PHONY: nfs
|
||||||
nfs:
|
nfs:
|
||||||
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -mod vendor -o bin/nfsplugin ./cmd/nfsplugin
|
CGO_ENABLED=0 GOOS=linux go build -a -ldflags "${LDFLAGS} ${EXT_LDFLAGS}" -mod vendor -o bin/nfsplugin ./cmd/nfsplugin
|
||||||
|
|
||||||
.PHONY: container
|
.PHONY: container
|
||||||
container: nfs
|
container: nfs
|
||||||
|
|||||||
1
go.mod
1
go.mod
@ -19,6 +19,7 @@ require (
|
|||||||
k8s.io/klog/v2 v2.4.0
|
k8s.io/klog/v2 v2.4.0
|
||||||
k8s.io/kubernetes v1.21.0-alpha.0.0.20201210005053-f58c4d8cd725
|
k8s.io/kubernetes v1.21.0-alpha.0.0.20201210005053-f58c4d8cd725
|
||||||
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
|
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
|
||||||
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
replace k8s.io/api => k8s.io/api v0.20.0
|
replace k8s.io/api => k8s.io/api v0.20.0
|
||||||
|
|||||||
@ -98,6 +98,12 @@ func NewNodeServer(n *Driver, mounter mount.Interface) *NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Driver) Run(testMode bool) {
|
func (n *Driver) Run(testMode bool) {
|
||||||
|
versionMeta, err := GetVersionYAML()
|
||||||
|
if err != nil {
|
||||||
|
klog.Fatalf("%v", err)
|
||||||
|
}
|
||||||
|
klog.Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta)
|
||||||
|
|
||||||
n.ns = NewNodeServer(n, mount.New(""))
|
n.ns = NewNodeServer(n, mount.New(""))
|
||||||
s := NewNonBlockingGRPCServer()
|
s := NewNonBlockingGRPCServer()
|
||||||
s.Start(n.endpoint,
|
s.Start(n.endpoint,
|
||||||
|
|||||||
67
pkg/nfs/version.go
Normal file
67
pkg/nfs/version.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 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 nfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are set during build time via -ldflags
|
||||||
|
var (
|
||||||
|
driverVersion = "N/A"
|
||||||
|
gitCommit = "N/A"
|
||||||
|
buildDate = "N/A"
|
||||||
|
)
|
||||||
|
|
||||||
|
// VersionInfo holds the version information of the driver
|
||||||
|
type VersionInfo struct {
|
||||||
|
DriverName string `json:"Driver Name"`
|
||||||
|
DriverVersion string `json:"Driver Version"`
|
||||||
|
GitCommit string `json:"Git Commit"`
|
||||||
|
BuildDate string `json:"Build Date"`
|
||||||
|
GoVersion string `json:"Go Version"`
|
||||||
|
Compiler string `json:"Compiler"`
|
||||||
|
Platform string `json:"Platform"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVersion returns the version information of the driver
|
||||||
|
func GetVersion() VersionInfo {
|
||||||
|
return VersionInfo{
|
||||||
|
DriverName: DriverName,
|
||||||
|
DriverVersion: driverVersion,
|
||||||
|
GitCommit: gitCommit,
|
||||||
|
BuildDate: buildDate,
|
||||||
|
GoVersion: runtime.Version(),
|
||||||
|
Compiler: runtime.Compiler,
|
||||||
|
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVersionYAML returns the version information of the driver
|
||||||
|
// in YAML format
|
||||||
|
func GetVersionYAML() (string, error) {
|
||||||
|
info := GetVersion()
|
||||||
|
marshalled, err := yaml.Marshal(&info)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(marshalled)), nil
|
||||||
|
}
|
||||||
60
pkg/nfs/version_test.go
Normal file
60
pkg/nfs/version_test.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 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 nfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetVersion(t *testing.T) {
|
||||||
|
version := GetVersion()
|
||||||
|
|
||||||
|
expected := VersionInfo{
|
||||||
|
DriverName: DriverName,
|
||||||
|
DriverVersion: "N/A",
|
||||||
|
GitCommit: "N/A",
|
||||||
|
BuildDate: "N/A",
|
||||||
|
GoVersion: runtime.Version(),
|
||||||
|
Compiler: runtime.Compiler,
|
||||||
|
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(version, expected) {
|
||||||
|
t.Errorf("Unexpected error. \n Expected: %v \n Found: %v", expected, version)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetVersionYAML(t *testing.T) {
|
||||||
|
resp, err := GetVersionYAML()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
versionInfo := GetVersion()
|
||||||
|
marshalled, _ := yaml.Marshal(&versionInfo)
|
||||||
|
expected := strings.TrimSpace(string(marshalled))
|
||||||
|
|
||||||
|
if resp != expected {
|
||||||
|
t.Fatalf("Unexpected error. \n Expected:%v\nFound:%v", expected, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -742,6 +742,7 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client
|
|||||||
# sigs.k8s.io/structured-merge-diff/v4 v4.0.2
|
# sigs.k8s.io/structured-merge-diff/v4 v4.0.2
|
||||||
sigs.k8s.io/structured-merge-diff/v4/value
|
sigs.k8s.io/structured-merge-diff/v4/value
|
||||||
# sigs.k8s.io/yaml v1.2.0
|
# sigs.k8s.io/yaml v1.2.0
|
||||||
|
## explicit
|
||||||
sigs.k8s.io/yaml
|
sigs.k8s.io/yaml
|
||||||
# k8s.io/api => k8s.io/api v0.20.0
|
# k8s.io/api => k8s.io/api v0.20.0
|
||||||
# k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.0
|
# k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user