Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,29 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion cmd/localkube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions localkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package localkube

import (
"errors"
"flag"
"fmt"
"io"
)
Expand All @@ -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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we auto-detect this by looking at some env vars or inspecting /proc/self/ns?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like inspecting /proc/1/cgroup should work, but I'd kind of prefer to keep this explicit to match the behavior of the kubelet itself.

Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. We can revisit this once, kubelet stops exposing the same flag.


func init() {
flag.Parse()
}

func (lk *LocalKube) Run(out io.Writer) error {
if len(flag.Args()) < 1 {
return errors.New("you must choose start <name>, stop <name>, 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)

Expand All @@ -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)
}
Expand Down