Skip to content

Commit e2fe54b

Browse files
authored
feat: branded install, start and stop commands (#18)
1 parent 5196840 commit e2fe54b

File tree

11 files changed

+529
-127
lines changed

11 files changed

+529
-127
lines changed

Makefile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ include hack/tools/Makefile.variables
44
include embedded-bins/Makefile.variables
55
include inttest/Makefile.variables
66

7-
ARCH ?= $(shell go env GOARCH)
87

98
BIN_DIR := $(shell pwd)/bin
109
export PATH := $(BIN_DIR):$(PATH)
@@ -19,16 +18,17 @@ help: ## Display this help
1918

2019
# runs on linux even if it's built on mac or windows
2120
TARGET_OS ?= linux
21+
TARGET_ARCH ?= $(shell go env GOARCH)
2222
BUILD_GO_FLAGS := -tags osusergo
2323
BUILD_GO_FLAGS += -asmflags "all=-trimpath=$(shell dirname $(PWD))"
2424
BUILD_GO_FLAGS += -gcflags "all=-trimpath=$(shell dirname $(PWD))"
2525
BUILD_GO_LDFLAGS_EXTRA := -extldflags=-static
26-
ifeq ($(shell go env GOOS),darwin)
26+
ifeq ($(TARGET_OS),darwin)
2727
BUILD_GO_LDFLAGS_EXTRA =
2828
endif
2929

30-
LD_FLAGS := -X main.goos=$(shell go env GOOS)
31-
LD_FLAGS += -X main.goarch=$(shell go env GOARCH)
30+
LD_FLAGS := -X main.goos=$(TARGET_OS)
31+
LD_FLAGS += -X main.goarch=$(TARGET_ARCH)
3232
LD_FLAGS += -X main.gitCommit=$(shell git rev-parse HEAD)
3333
LD_FLAGS += -X main.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
3434
LD_FLAGS += $(BUILD_GO_LDFLAGS_EXTRA)
@@ -49,17 +49,16 @@ clean: ## Clean the bin directory
4949
build: static bin/helmbin ## Build helmbin binaries
5050

5151
bin/helmbin: BIN = bin/helmbin
52-
bin/helmbin: TARGET_OS = linux
5352
bin/helmbin: BUILD_GO_CGO_ENABLED = 0
5453
bin/helmbin: $(GO_SRCS) go.sum
5554
@mkdir -p bin
56-
CGO_ENABLED=$(BUILD_GO_CGO_ENABLED) GOOS=$(TARGET_OS) go build $(BUILD_GO_FLAGS) -ldflags='$(LD_FLAGS)' -o $(BIN) ./cmd/helmbin
55+
CGO_ENABLED=$(BUILD_GO_CGO_ENABLED) GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build $(BUILD_GO_FLAGS) -ldflags='$(LD_FLAGS)' -o $(BIN) ./cmd/helmbin
5756

5857
static: static/bin/k0s static/helm/000-admin-console-$(admin_console_version).tgz ## Build static assets
5958

6059
static/bin/k0s:
6160
@mkdir -p static/bin
62-
curl -fsSL -o static/bin/k0s https://github.com/k0sproject/k0s/releases/download/$(k0s_version)/k0s-$(k0s_version)-$(ARCH)
61+
curl -fsSL -o static/bin/k0s https://github.com/k0sproject/k0s/releases/download/$(k0s_version)/k0s-$(k0s_version)-$(TARGET_ARCH)
6362
chmod +x static/bin/k0s
6463

6564
static/helm/000-admin-console-$(admin_console_version).tgz: helm

README.md

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ Use "helmbin [command] --help" for more information about a command.
3030

3131
```bash
3232
$ make build
33-
go build -gcflags "all=-trimpath=/home/ethan/go/src/github.com/replicatedhq" -asmflags "all=-trimpath=/home/ethan/go/src/github.com/replicatedhq" -ldflags " -X main.goos=linux -X main.goarch=amd64 -X main.gitCommit=1a6e487bb4bcb5049c448983758912afbdb9d1c2 -X main.buildDate=2023-05-24T21:42:34Z " -tags='' -o bin/helmbin ./cmd/helmbin
33+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags osusergo -asmflags "all=-trimpath=/Users/ethan/go/src/github.com/replicatedhq" -gcflags "all=-trimpath=/Users/ethan/go/src/github.com/replicatedhq" -ldflags='-X main.goos=linux -X main.goarch=amd64 -X main.gitCommit=5196840140ccbb3fdf9394eec7d8bea9169aae84 -X main.buildDate=2023-07-12T19:33:16Z -extldflags=-static' -o bin/helmbin ./cmd/helmbin
3434
```
3535

3636
## Running
3737

3838
```bash
39-
./bin/helmbin server --help
39+
./bin/helmbin run --help
4040
Runs a controller+worker node
4141

4242
Usage:
@@ -48,38 +48,64 @@ Available Commands:
4848
worker Runs a worker node
4949

5050
Flags:
51-
-c, --config string k0s config file, use '-' to read the config from stdin (default "/etc/k0s/k0s.yaml")
52-
--data-dir string Data Directory. DO NOT CHANGE for an existing setup, things will break! (default "/var/lib/replicated")
53-
-d, --debug Debug logging (default: false)
54-
--enable-worker enable worker (default true)
55-
-h, --help help for run
56-
--no-taints disable default taints for controller node (default true)
57-
--token-file string Path to the file containing join-token.
51+
-c, --config string k0s config file, use '-' to read the config from stdin (default "/etc/k0s/k0s.yaml")
52+
--data-dir string Data Directory. DO NOT CHANGE for an existing setup, things will break! (default "/var/lib/replicated")
53+
-d, --debug Debug logging (default: false)
54+
--enable-worker enable worker (default true)
55+
-h, --help help for run
56+
-l, --logging stringToString Logging Levels for the different components (default [kube-proxy=1,etcd=info,containerd=info,konnectivity-server=1,kube-apiserver=1,kube-controller-manager=1,kube-scheduler=1,kubelet=1])
57+
--no-taints disable default taints for controller node (default true)
58+
--token-file string Path to the file containing join-token.
5859

5960
Use "helmbin run [command] --help" for more information about a command.
6061
```
6162

6263
```bash
63-
$ ./bin/helmbin install --help
64-
Installs and starts a controller+worker as a systemd service
64+
Install helmbin on a brand-new system. Must be run as root (or with sudo)
6565

6666
Usage:
6767
helmbin install [flags]
6868
helmbin install [command]
6969

70+
Examples:
71+
With the install command you can setup a single node cluster by running:
72+
73+
helmbin install
74+
75+
7076
Available Commands:
71-
controller Installs and starts a controller as a systemd service
72-
controller Installs and starts a worker as a systemd service
77+
controller Install helmbin controller on a brand-new system. Must be run as root (or with sudo)
78+
worker Install helmbin worker on a brand-new system. Must be run as root (or with sudo)
7379

7480
Flags:
75-
-c, --config string k0s config file, use '-' to read the config from stdin (default "/etc/k0s/k0s.yaml")
76-
--data-dir string Data Directory. DO NOT CHANGE for an existing setup, things will break! (default "/var/lib/replicated")
77-
-d, --debug Debug logging (default: false)
78-
--enable-worker enable worker (default true)
79-
-h, --help help for install
80-
--no-taints disable default taints for controller node (default true)
81-
--start Start the service after installation (default true)
82-
--token-file string Path to the file containing join-token.
81+
--api-server string HACK: api-server for the windows worker node
82+
--cidr-range string HACK: cidr range for the windows worker node (default "10.96.0.0/12")
83+
--cluster-dns string HACK: cluster dns for the windows worker node (default "10.96.0.10")
84+
-c, --config string config file, use '-' to read the config from stdin (default "/etc/k0s/k0s.yaml")
85+
--cri-socket string container runtime socket to use, default to internal containerd. Format: [remote|docker]:[path-to-socket]
86+
--data-dir string Data Directory for k0s (default: /var/lib/k0s). DO NOT CHANGE for an existing setup, things will break!
87+
-d, --debug Debug logging (default: false)
88+
--debugListenOn string Http listenOn for Debug pprof handler (default ":6060")
89+
--disable-components strings disable components (valid items: autopilot,control-api,coredns,csr-approver,endpoint-reconciler,helm,konnectivity-server,kube-controller-manager,kube-proxy,kube-scheduler,metrics-server,network-provider,node-role,system-rbac,worker-config)
90+
--enable-cloud-provider Whether or not to enable cloud provider support in kubelet
91+
--enable-dynamic-config enable cluster-wide dynamic config based on custom resource
92+
--enable-k0s-cloud-provider enables the k0s-cloud-provider (default false)
93+
--enable-metrics-scraper enable scraping metrics from the controller components (kube-scheduler, kube-controller-manager)
94+
-e, --env stringArray set environment variable
95+
--force force init script creation
96+
-h, --help help for install
97+
--iptables-mode string iptables mode (valid values: nft, legacy, auto). default: auto
98+
--k0s-cloud-provider-port int the port that k0s-cloud-provider binds on (default 10258)
99+
--k0s-cloud-provider-update-frequency duration the frequency of k0s-cloud-provider node updates (default 2m0s)
100+
--kube-controller-manager-extra-args string extra args for kube-controller-manager
101+
--kubelet-extra-args string extra args for kubelet
102+
--labels strings Node labels, list of key=value pairs
103+
-l, --logging stringToString Logging Levels for the different components (default [etcd=info,containerd=info,konnectivity-server=1,kube-apiserver=1,kube-controller-manager=1,kube-scheduler=1,kubelet=1,kube-proxy=1])
104+
--profile string worker profile to use on the node (default "default")
105+
--status-socket string Full file path to the socket file. (default "status.sock")
106+
--taints strings Node taints, list of key=value:effect strings
107+
--token-file string Path to the file containing join-token.
108+
-v, --verbose Verbose logging (default: false)
83109

84110
Use "helmbin install [command] --help" for more information about a command.
85111
```

pkg/cli/cli.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ package cli
55

66
import (
77
"os"
8+
"path/filepath"
9+
"strings"
810

11+
"github.com/spf13/cobra"
912
"k8s.io/cli-runtime/pkg/genericclioptions"
1013
)
1114

1215
// CLI is the main CLI struct
1316
type CLI struct {
1417
genericclioptions.IOStreams
18+
Name string
1519
Args []string
1620
}
1721

1822
// NewCLI creates a new CLI
1923
func NewCLI() *CLI {
2024
return &CLI{
25+
Name: executableName(os.Args),
2126
Args: os.Args,
2227
IOStreams: genericclioptions.IOStreams{
2328
In: os.Stdin,
@@ -26,3 +31,15 @@ func NewCLI() *CLI {
2631
},
2732
}
2833
}
34+
35+
func (c *CLI) cmdReplaceK0s(cmd *cobra.Command) {
36+
replacer := strings.NewReplacer("k0s", c.Name)
37+
cmd.Use = replacer.Replace(cmd.Use)
38+
cmd.Short = replacer.Replace(cmd.Short)
39+
cmd.Long = replacer.Replace(cmd.Long)
40+
cmd.Example = replacer.Replace(cmd.Example)
41+
}
42+
43+
func executableName(args []string) string {
44+
return filepath.Base(args[0])
45+
}

0 commit comments

Comments
 (0)