提交 a62e9e5c 编写于 作者: L Lucas Käldström

Removed localkube start and version commands in favor for starting as default...

Removed localkube start and version commands in favor for starting as default and using version as a flag. Also the version is now set my the Makefile
上级 73709243
......@@ -15,6 +15,8 @@
# Use the native vendor/ dependency system
export GO15VENDOREXPERIMENT=1
# Bump this on release
VERSION ?= v0.0.1
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
BUILD_DIR ?= ./out
......@@ -31,8 +33,9 @@ endif
# Use system python if it exists, otherwise use Docker.
PYTHON := $(shell command -v python || docker run --rm -it -v $(shell pwd):/minikube -w /minikube python python)
# Set the version information for the Kubernetes servers, and build localkube statically
VERSION_LDFLAGS := $(shell $(PYTHON) hack/get_k8s_version.py)
LDFLAGS := "$(VERSION_LDFLAGS) -s -w -extldflags '-static'"
K8S_VERSION_LDFLAGS := $(shell $(PYTHON) hack/get_k8s_version.py 2>&1)
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION)
LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w -extldflags '-static'"
clean:
rm -rf $(GOPATH)
......@@ -49,14 +52,14 @@ out/minikube: out/minikube-$(GOOS)-$(GOARCH)
out/localkube: $(LOCALKUBEFILES)
$(MKGOPATH)
ifeq ($(GOOS),linux)
CGO_ENABLED=1 go build -ldflags=$(LDFLAGS) -o $(BUILD_DIR)/localkube ./cmd/localkube
CGO_ENABLED=1 go build -ldflags=$(LOCALKUBE_LDFLAGS) -o $(BUILD_DIR)/localkube ./cmd/localkube
else
docker run -w /go/src/$(REPOPATH) -e IN_DOCKER=1 -v $(shell pwd):/go/src/$(REPOPATH) $(BUILD_IMAGE) make out/localkube
endif
out/minikube-$(GOOS)-$(GOARCH): $(MINIKUBEFILES) pkg/minikube/cluster/localkubecontents.go
$(MKGOPATH)
CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build --installsuffix cgo -a -o $(BUILD_DIR)/minikube-$(GOOS)-$(GOARCH) ./cmd/minikube
CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build --installsuffix cgo -ldflags="$(MINIKUBE_LDFLAGS)" -a -o $(BUILD_DIR)/minikube-$(GOOS)-$(GOARCH) ./cmd/minikube
.PHONY: integration
integration: out/minikube
......
......@@ -41,6 +41,7 @@ func NewLocalkubeServer() *localkube.LocalkubeServer {
APIServerInsecureAddress: net.ParseIP("127.0.0.1"),
APIServerInsecurePort: 8080,
ShouldGenerateCerts: true,
ShowVersion: false,
}
}
......@@ -57,6 +58,7 @@ func AddFlags(s *localkube.LocalkubeServer) {
flag.IPVar(&s.APIServerInsecureAddress, "apiserver-insecure-address", s.APIServerInsecureAddress, "The address the apiserver will listen insecurely on")
flag.IntVar(&s.APIServerInsecurePort, "apiserver-insecure-port", s.APIServerInsecurePort, "The port the apiserver will listen insecurely on")
flag.BoolVar(&s.ShouldGenerateCerts, "generate-certs", s.ShouldGenerateCerts, "If localkube should generate it's own certificates")
flag.BoolVar(&s.ShowVersion, "version", s.ShowVersion, "If localkube should just print the version and exit.")
// These two come from vendor/ packages that use flags. We should hide them
flag.CommandLine.MarkHidden("google-json-key")
......
......@@ -26,13 +26,12 @@ import (
var RootCmd = &cobra.Command{
Use: "localkube",
Short: "localkube is a all-in-one kubernetes binary.",
Long: `localkube is a all-in-one kubernetes binary that runs all servers at the same time.`,
Long: `localkube is a all-in-one kubernetes binary that runs all Kubernetes server binaries.`,
Run: func(command *cobra.Command, args []string) {
StartLocalkube()
},
}
func init() {
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
cobra.OnInitialize(initConfig)
}
func initConfig() {
}
......@@ -21,39 +21,34 @@ import (
"os"
"os/signal"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/minikube/pkg/localkube"
"k8s.io/minikube/pkg/version"
)
// The main instance of the current localkube server that is started
var Server *localkube.LocalkubeServer
var StartCmd = &cobra.Command{
Use: "start",
Short: "Start the localkube server.",
Long: `Start the localkube server.`,
Run: func(command *cobra.Command, args []string) {
func StartLocalkube(){
// TODO: Require root
if Server.ShowVersion {
fmt.Println("localkube version:", version.GetVersion())
os.Exit(0)
}
SetupServer(Server)
Server.StartAll()
// TODO: Require root
defer Server.StopAll()
SetupServer(Server)
Server.StartAll()
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt)
defer Server.StopAll()
<-interruptChan
fmt.Println("Shutting down...")
},
}
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt)
func init() {
Server = NewLocalkubeServer()
RootCmd.AddCommand(StartCmd)
<-interruptChan
fmt.Println("Shutting down...")
}
func SetupServer(s *localkube.LocalkubeServer) {
......
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 cmd
import (
"fmt"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/version"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version of localkube.",
Long: `Print the version of localkube.`,
Run: func(command *cobra.Command, args []string) {
fmt.Println("Version: ", version.Version)
},
}
func init() {
RootCmd.AddCommand(versionCmd)
}
......@@ -25,6 +25,8 @@ import (
func main() {
// Create the localkube server and parse the flags
cmd.Server = cmd.NewLocalkubeServer()
cmd.AddFlags(cmd.Server)
if err := cmd.RootCmd.Execute(); err != nil {
......
......@@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{
Long: `Print the version of minikube.`,
Run: func(command *cobra.Command, args []string) {
fmt.Println("Version: ", version.Version)
fmt.Println("minikube version:", version.GetVersion())
},
}
......
......@@ -48,6 +48,7 @@ type LocalkubeServer struct {
APIServerInsecureAddress net.IP
APIServerInsecurePort int
ShouldGenerateCerts bool
ShowVersion bool
}
func (lk *LocalkubeServer) AddServer(server Server) {
......
......@@ -34,7 +34,7 @@ var stopCommand = "sudo killall localkube | true"
var startCommandFmtStr = `
# Run with nohup so it stays up. Redirect logs to useful places.
PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube start %s --generate-certs=false > %s 2> %s < /dev/null &
PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/localkube %s --generate-certs=false > %s 2> %s < /dev/null &
`
var logsCommand = fmt.Sprintf("tail -n +1 %s %s", remoteLocalKubeErrPath, remoteLocalKubeOutPath)
......
......@@ -17,4 +17,9 @@ limitations under the License.
package version
// The current version of the minikube and localkube
const Version = "0.0.1-developing"
// This is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.version=vX.Y.Z"
var version = "v0.0.0-unset"
func GetVersion() string {
return version
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册