Add containerdVersion flag
Add version flag that only prints the static version for the binary. This commit does not include build details for containers since Makefile does not build them. Closes #8 Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
This commit is contained in:
parent
d6978e3b7f
commit
683fd7f0e5
13
Makefile
13
Makefile
@ -17,6 +17,9 @@ EPOCH_TEST_COMMIT ?= f9e02affccd51702191e5312665a16045ffef8ab
|
||||
PROJECT := github.com/kubernetes-incubator/cri-containerd
|
||||
BINDIR ?= ${DESTDIR}/usr/local/bin
|
||||
BUILD_DIR ?= _output
|
||||
# VERSION is the version of the binary.
|
||||
VERSION:=$(shell git describe --tags --dirty)
|
||||
BUILD_TAGS:= -ldflags '-X $(PROJECT)/pkg/version.criContainerdVersion=$(VERSION)'
|
||||
|
||||
all: binaries
|
||||
|
||||
@ -32,6 +35,7 @@ help:
|
||||
@echo " * 'verify' - Execute the source code verification tools"
|
||||
@echo " * 'install.tools' - Installs tools used by verify"
|
||||
@echo " * 'uninstall' - Remove installed binaries from system locations"
|
||||
@echo " * 'version' - Print current cri-containerd release version"
|
||||
|
||||
.PHONY: check-gopath
|
||||
|
||||
@ -42,6 +46,9 @@ endif
|
||||
|
||||
verify: lint gofmt boiler
|
||||
|
||||
version:
|
||||
@echo $(VERSION)
|
||||
|
||||
lint: check-gopath
|
||||
@echo "checking lint"
|
||||
@./hack/lint.sh
|
||||
@ -56,7 +63,8 @@ boiler:
|
||||
|
||||
cri-containerd: check-gopath
|
||||
$(GO) build -o $(BUILD_DIR)/$@ \
|
||||
$(PROJECT)/cmd/cri-containerd
|
||||
$(BUILD_TAGS) \
|
||||
$(PROJECT)/cmd/cri-containerd
|
||||
|
||||
test:
|
||||
go test -timeout=1m -v -race ./pkg/... $(BUILD_TAGS)
|
||||
@ -102,4 +110,5 @@ install.tools: .install.gitvalidation .install.gometalinter
|
||||
help \
|
||||
install \
|
||||
lint \
|
||||
uninstall
|
||||
uninstall \
|
||||
version
|
||||
|
@ -17,11 +17,14 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/kubernetes-incubator/cri-containerd/cmd/cri-containerd/options"
|
||||
"github.com/kubernetes-incubator/cri-containerd/pkg/server"
|
||||
"github.com/kubernetes-incubator/cri-containerd/pkg/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -29,6 +32,11 @@ func main() {
|
||||
o.AddFlags(pflag.CommandLine)
|
||||
options.InitFlags()
|
||||
|
||||
if o.CRIContainerdVersion {
|
||||
version.PrintVersion()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
glog.V(2).Infof("Connect to containerd socket %q with timeout %v", o.ContainerdSocketPath, o.ContainerdConnectionTimeout)
|
||||
conn, err := server.ConnectToContainerd(o.ContainerdSocketPath, o.ContainerdConnectionTimeout)
|
||||
if err != nil {
|
||||
|
@ -27,6 +27,8 @@ import (
|
||||
type CRIContainerdOptions struct {
|
||||
// CRIContainerdSocketPath is the path to the socket which cri-containerd serves on.
|
||||
CRIContainerdSocketPath string
|
||||
// CRIContainerdVersion is the git release version of cri-containerd
|
||||
CRIContainerdVersion bool
|
||||
// ContainerdSocketPath is the path to the containerd socket.
|
||||
ContainerdSocketPath string
|
||||
// ContainerdConnectionTimeout is the connection timeout for containerd client.
|
||||
@ -46,6 +48,8 @@ func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
"/run/containerd/containerd.sock", "Path to the containerd socket.")
|
||||
fs.DurationVar(&c.ContainerdConnectionTimeout, "containerd-connection-timeout",
|
||||
2*time.Minute, "Connection timeout for containerd client.")
|
||||
fs.BoolVar(&c.CRIContainerdVersion, "version",
|
||||
false, "Print cri-containerd version information and quit.")
|
||||
}
|
||||
|
||||
// InitFlags must be called after adding all cli options flags are defined and
|
||||
|
42
pkg/version/version.go
Normal file
42
pkg/version/version.go
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/blang/semver"
|
||||
)
|
||||
|
||||
var criContainerdVersion = "UNKNOWN"
|
||||
|
||||
func validateSemver(sv string) error {
|
||||
_, err := semver.Parse(sv)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't parse cri-containerd version %q: %v", sv, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrintVersion outputs the release version of cri-containerd
|
||||
func PrintVersion() {
|
||||
err := validateSemver(criContainerdVersion)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println(criContainerdVersion)
|
||||
}
|
33
pkg/version/version_test.go
Normal file
33
pkg/version/version_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
package version
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestValidateSemver(t *testing.T) {
|
||||
err := validateSemver("UNKNOWN")
|
||||
assert := assert.New(t)
|
||||
assert.NotNil(err)
|
||||
err = validateSemver("0.0.0-1-gdf6a1cc-dirty")
|
||||
assert.Nil(err)
|
||||
err = validateSemver(criContainerdVersion)
|
||||
assert.Nil(err)
|
||||
}
|
Loading…
Reference in New Issue
Block a user