From 9cab9b944602aadbdc95b58901a75ff54109d074 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Tue, 26 Apr 2016 09:50:28 -0700 Subject: [PATCH] Add a flag to control whether the kubelet runs in "containerized" mode or not. This also adds a build mode for "dynamic" compilation instead of static. This is required for cAdvisor to run in the "non-containerized" kubelet. --- Makefile | 11 +++++++++++ cmd/localkube/main.go | 2 +- kubelet.go | 2 +- localkube.go | 27 ++++++++++++++++++--------- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 61ae4d62..4c4c4771 100644 --- a/Makefile +++ b/Makefile @@ -51,11 +51,19 @@ integration: build-image .PHONY: build build: build/localkube-$(GOOS) +.PHONY: build-dynamic +build-dynamic: build/localkube-dynamic-$(GOOS) + .PHONY: docker-build docker-build: validate mkdir build $(DOCKER) run -w $(DOCKER_DIR) $(DOCKER_OPTS) $(MNT_REPO) $(DOCKER_DEV_IMAGE) make build +.PHONY: docker-build-dynamic +docker-build-dynamic: validate + mkdir build + $(DOCKER) run -w $(DOCKER_DIR) $(DOCKER_OPTS) $(MNT_REPO) $(DOCKER_DEV_IMAGE) make build-dynamic + .PHONY: clean clean: rm -rf ./build @@ -63,6 +71,9 @@ clean: build/localkube-$(GOOS): $(GO) build -o $@ $(GOBUILD_FLAGS) $(GOBUILD_LDFLAGS) $(EXEC_PKG) +build/localkube-dynamic-$(GOOS): + CGO_ENABLED=1 $(GO) build -o $@ $(EXEC_PKG) + .PHONY: build-image build-image: context $(DOCKER) build $(DOCKER_OPTS) -t $(DOCKER_IMAGE_NAME) ./build/context diff --git a/cmd/localkube/main.go b/cmd/localkube/main.go index e24f5edf..1599554e 100644 --- a/cmd/localkube/main.go +++ b/cmd/localkube/main.go @@ -68,7 +68,7 @@ func main() { // if first load() - err := LK.Run(os.Args, os.Stderr) + err := LK.Run(os.Stderr) if err != nil { fmt.Printf("localkube errored: %v\n", err) os.Exit(1) diff --git a/kubelet.go b/kubelet.go index 81f81935..3bd4ff1e 100644 --- a/kubelet.go +++ b/kubelet.go @@ -35,7 +35,7 @@ func StartKubeletServer(clusterDomain, clusterDNS string) func() { config.APIServerList = []string{APIServerURL} // Docker - config.Containerized = true + config.Containerized = *containerized config.DockerEndpoint = WeaveProxySock // Networking diff --git a/localkube.go b/localkube.go index f42a1073..b9ded7b5 100644 --- a/localkube.go +++ b/localkube.go @@ -2,6 +2,7 @@ package localkube import ( "errors" + "flag" "fmt" "io" ) @@ -15,20 +16,28 @@ func (lk *LocalKube) Add(server Server) { lk.Servers = append(lk.Servers, server) } -func (lk *LocalKube) Run(args []string, out io.Writer) error { - if len(args) < 2 { +var containerized = flag.Bool("containerized", true, "Whether localkube is inside a container or not") + +func init() { + flag.Parse() +} + +func (lk *LocalKube) Run(out io.Writer) error { + if len(flag.Args()) < 1 { return errors.New("you must choose start , stop , or status") } - switch args[1] { + args := flag.Args() + fmt.Fprintln(out, "Got args: %s", args) + switch args[0] { case "start": // check if just start - if len(args) == 2 { + if len(args) == 1 { fmt.Fprintln(out, "Starting LocalKube...") lk.StartAll() return nil - } else if len(args) == 3 { - serverName := args[2] + } else if len(args) == 2 { + serverName := args[1] fmt.Fprintf(out, "Starting `%s`...\n", serverName) return lk.Start(serverName) @@ -37,12 +46,12 @@ func (lk *LocalKube) Run(args []string, out io.Writer) error { } case "stop": // check if just stop - if len(args) == 2 { + if len(args) == 1 { fmt.Fprintln(out, "Stopping LocalKube...") lk.StopAll() return nil - } else if len(args) == 3 { - serverName := args[2] + } else if len(args) == 2 { + serverName := args[1] fmt.Fprintf(out, "Stopping `%s`...\n", serverName) return lk.Stop(serverName) }