Skip to content

Commit

Permalink
Add support reuse k3d registry
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Aug 26, 2021
1 parent 5175e46 commit 3cc58c8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions kubectl-plugin/install/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ You can get more details from https://github.com/rancher/k3d/`,
"Specify how many servers you want to create")
flags.StringVarP(&opt.image, "image", "", "rancher/k3s:v1.18.20-k3s1",
"The image of k3s, get more images from https://hub.docker.com/r/rancher/k3s/tags")
flags.StringVarP(&opt.registry, "registry", "r", "registry",
"Connect to one or more k3d-managed registries running locally")

// TODO find a better way to reuse the flags from another command
flags.StringVarP(&opt.version, "version", "", types.KsVersion,
Expand All @@ -46,10 +48,11 @@ You can get more details from https://github.com/rancher/k3d/`,
type k3dOption struct {
installerOption

image string
name string
agents int
servers int
image string
name string
agents int
servers int
registry string
}

func (o *k3dOption) preRunE(cmd *cobra.Command, args []string) (err error) {
Expand Down Expand Up @@ -77,12 +80,16 @@ func (o *k3dOption) runE(cmd *cobra.Command, args []string) (err error) {
return
}

// always to create a registry to make sure it's exist
_ = common.ExecCommand("k3d", "registry", "create", o.registry)

k3dArgs := []string{"cluster", "create",
"-p", fmt.Sprintf(`%d:30880@agent[0]`, ports[0]),
"-p", fmt.Sprintf(`%d:30180@agent[0]`, ports[1]),
"--agents", fmt.Sprintf("%d", o.agents),
"--servers", fmt.Sprintf("%d", o.servers),
"--image", o.image}
"--image", o.image,
"--registry-use", o.registry}
if o.name != "" {
k3dArgs = append(k3dArgs, o.name)
}
Expand Down

0 comments on commit 3cc58c8

Please sign in to comment.