Commit Graph

47 Commits

Author SHA1 Message Date
Andy Zhou
d63f7d4bf2 Rename bash command to shell
@iwilltry42 suggested to group all shell support under and single
subcommand -- shell.
2019-05-27 17:14:43 -07:00
Andy Zhou
2971dd6845 Add the ability to execute commands directly with the bash subcommand
In addition to provide an interactive shell, this patch adds the
'--command' and '-c' options to allow user to issue a command in the
context of a cluster.

For example:

$ k3d bash -c 'kubectl cluster-info'
2019-05-24 17:16:12 -07:00
Andy Zhou
4ef6710e22 Add basic bashShell() function
Add the basic frame work for supporting spawning a bash shell by cli
command.

With this change, we can spawn a bash shell in the context of a cluster

$ k3d create -n my-cluster
$ k3d bash -n my-cluster
[my-cluster] $>

// execute commands with KUBECONFIG already set up
[my-cluster] $> kubectl get pods
2019-05-24 17:16:12 -07:00
Andy Zhou
9f276a68f3 Add getKubeConfig()
Move the logic of retrive per cluster kube config file into
cli/cluster.go. Simplify the CLI handling code.
2019-05-24 17:16:12 -07:00
Andy Zhou
cdcc5e1de6 Add createKubeconfigFile()
Refactoring. Make createKubeconfigFile() a stand along function, so we
don't have to recreate the file every time we look up the file name.
2019-05-24 17:16:12 -07:00
Andy Zhou
1eff974064 Add getClusterKubeConfigPath()
Minor refactor. Add getClusterKubeConfigOath() to make logic reusable
for later changes.
2019-05-24 17:16:12 -07:00
Andy Zhou
175ccbe3cd Improve error handling for CreateCluster()
Co-authored-by: Thorsten Klein <iwilltry42@gmail.com>

@iwilltry42 pointed out that currnet error path calls os.Exit(1), which
does follow the normal CLI framework. This patch implements this
suggestion.

Add a closure fucntion deleteCluster() to reduce code duplication.
2019-05-21 14:10:11 -07:00
Andy Zhou
6dfb1e054b
Merge pull request #61 from andyz-dev/always-on
[Feature] Implement --always-on flag for the create command
2019-05-21 10:46:00 -07:00
Andy Zhou
b9713c4ac4 Add --auto-restart flag for the create command
When creating clusters with the --auto-restart flag, any running cluster
will remain "running" up on docker daemon restart.

By default, without this flag, a "running" cluster becomes "stopped"
after docker daemon restart.

Clusters stopped with 'k3d stop' command will remain stopped after
docker daemon restart regardless the settings of this flag.
2019-05-21 09:31:45 -07:00
Andy Zhou
5028f2882f
Merge pull request #60 from andyz-dev/atomic-create
[Enhancement] Atomic create
2019-05-20 23:21:19 -07:00
Andy Zhou
490b7cd864 Atomic create
Before this commit, when creating a cluster was not successful, some
resource may be lingering behind. This commit fixes those cases.

Now the cluster creation model is easier to understand. Either a cluster
is successfully created, or all resources created will be cleaned up.

The intention is to keep the "atomic create" model going forward for
k3d.
2019-05-20 19:03:32 -07:00
Andy Zhou
3683eeb181 Deprecate the --timeout option
Use --wait <timeout> instead
2019-05-20 14:07:12 -07:00
Andy Zhou
01931b5894 Make list command always show all clusters. Remove --all option
It feels more natural to have the list command show all clusters by
default.
2019-05-18 22:25:24 -07:00
Andy Zhou
3c3c72b4af Check for cluster existence before using a name to create a new cluster
This change improve the error message. It also avoids the tricky situation of
potentially destroying an existing clusters when the same name cluster
creation fails. For more details see issue #42.
2019-05-15 09:56:48 -07:00
Andy Zhou
b48debb176 Refactor getClusters() to make the API easier to use
Simplify the caller of this function in the code base. Also remove
getCluster() since there is no caller of this function any more.
2019-05-15 09:56:48 -07:00
Andy Zhou
a0eb69b73e Allow the volume argument to be specified multiple times
Most k3d arguments are using in "stringSlice" style, allowing the
argument to supplied multiple times. Currently "volume" is an exception
to this style, require multiple arguments to be supplied in a single
argument, separated by comma.

This commit improve the k3d usability by improve the consistency of its
argument style.
2019-05-15 09:35:07 -07:00
iwilltry42
107700dc98 update log messages 2019-05-14 13:12:10 +02:00
iwilltry42
a68d9e7042 generate container names in a func and use it to determine if node-specifier is valid 2019-05-14 11:33:10 +02:00
iwilltry42
a0c0c3ff9d add --api-port and --port-auto-offset 2019-05-13 09:08:32 +02:00
iwilltry42
7d6ae201e9 make node-specifier mandatory 2019-05-13 08:12:09 +02:00
iwilltry42
58b1682e32 Merge branch 'master' of https://github.com/rancher/k3d into new-publish 2019-05-13 07:54:07 +02:00
Rishabh Gupta
787d6608ba Delete a cluster if it is not started due to port conflicts or any other unforseen error
Signed-off-by: Rishabh Gupta <r.g.gupta@outlook.com>
2019-05-10 13:10:55 +05:30
iwilltry42
0c8cdc004a Merge branch 'master' of https://github.com/rancher/k3d into new-publish 2019-05-09 15:36:27 +02:00
Andy Zhou
32cc70b599
Merge pull request #32 from andyz-dev/publish
[Feature] Add --publish/--add-port flag for port mappings
2019-05-09 01:09:40 -07:00
iwilltry42
fd720b0887 move hostname check to util 2019-05-09 08:05:39 +02:00
Andy Zhou
93f72e672a Make sure the culster name is valid before creating it.
MAke sure the cluster name is a RFC 1123 compliant host name, since the
cluster name is used as base for expanding into a auto generated
host names for k3s nodes.
2019-05-08 15:57:32 -07:00
iwilltry42
124a45688f working version 2019-05-08 15:29:57 +02:00
iwilltry42
d35f12a77e init 2019-05-08 13:37:24 +02:00
Andy Zhou
65f2820b3f Support publishing ports for the worker nodes
All ports exposed by --publish will also be exported for all worker
nodes. The host port will be auto indexed based worker id.

For example: with the following command option:

k3d create --publish  80:80  --publish 90:90/udp --workers 1

The exposed ports will be:

host TCP port 80  -> k3s server TCP 80
host TCP port 90  -> k3s server TCP 90
host UDP port 81 -> k3s worker 0 UDP 80
host UDP port 91 -> k3s worker 0 UDP 90
2019-05-08 01:45:16 -07:00
Andy Zhou
988fbdbdc5 Refactor createWorker() API
Use postfix as int instead string. This make the following patch easier
to read.
2019-05-08 01:45:16 -07:00
Andy Zhou
f70a8b42f7 Add support for the --publish option for create subcommand
Inspired by the docker CLI, --publish take same input as docker CLI and
provides similar functions. For the k3s cluster server node, it behaves
the same as docker cli; it exports the k3d server ports to the host
ports.

Handling for worker nodes will be added in the subsequent patches.

This option can be used mutiple times for exposing more ports.

--add-port is an alias to this option.
2019-05-08 01:45:16 -07:00
iwilltry42
40fb583160 better image and version flags 2019-05-07 09:09:05 +02:00
iwilltry42
e78a548da2 [Feature] add --image/-i flag to specify custom k3s image 2019-05-06 08:13:11 +02:00
iwilltry42
1294b5b3a6 Merge branch 'imporve-error-message' of https://github.com/andyz-dev/k3d into andyz-dev-imporve-error-message 2019-05-03 07:59:25 +02:00
Andy Zhou
2267924578 cli: Improve error message for 'k3d get-kubeconfig'
Before this change, command:
 $ k3d create -name test
 $ k3d get-kubeconfig

Produces the following error message:

	panic: runtime error: index out of range

	goroutine 1 [running]:
	github.com/rancher/k3d/cli.GetKubeConfig(0xc00031a160, 0x0, 0x0)
		/Users/azhou/projs/k3d/cli/commands.go:335 +0x105d
	github.com/urfave/cli.HandleAction(0x13e7ca0, 0x148f0b0, 0xc00031a160, 0xc000304000, 0x0)
		/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:490 +0xc8
	github.com/urfave/cli.Command.Run(0x1477cb5, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1480cd8, 0x23, 0x0, ...)
		/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/command.go:210 +0x996
	github.com/urfave/cli.(*App).Run(0xc0000bc1a0, 0xc00000e060, 0x2, 0x2, 0x0, 0x0)
		/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:255 +0x6af
	main.main()
		/Users/azhou/projs/k3d/main.go:185 +0x11e0

This patch improve the error message by avoid the panic. Now the output
becomes:

	019/05/02 12:05:30 No server container for cluster k3s_default
2019-05-02 12:17:36 -07:00
iwilltry42
942e667b24 add some comments 2019-04-29 08:19:01 +02:00
iwilltry42
068172aa1a fix output order for logs 2019-04-23 15:20:06 +02:00
iwilltry42
e9206a74b2 make start/stop functions start/stop workers as well 2019-04-23 11:22:59 +02:00
iwilltry42
9142529c62 get-kubeconfig using docker sdk 2019-04-23 10:51:02 +02:00
iwilltry42
6c072fb6d9 connect workers and server via own docker network 2019-04-18 16:08:15 +02:00
iwilltry42
7d5964c3b9 fix image not being pulled if reader is not being used 2019-04-18 14:42:41 +02:00
iwilltry42
b0b08d2119 bring back env vars, enable booting workers and base list output on docker data instead of dirs 2019-04-16 11:12:05 +02:00
iwilltry42
7eec5b061b use docker sdk wherever possible 2019-04-15 15:48:43 +02:00
iwilltry42
65b5f06bfc add server-arg and env flags 2019-04-11 14:31:46 +02:00
iwilltry42
65c0bf9e5c better errors 2019-04-10 08:38:54 +02:00
iwilltry42
0b35d7c138 get back --all function for all commands 2019-04-09 15:12:38 +02:00
Rishabh Gupta
29fced4ef7 Added version tags, separated command implementaitons, added wait and timeout
Signed-off-by: Rishabh Gupta <r.g.gupta@outlook.com>
2019-04-09 13:47:47 +05:30