Skip to content

Commit

Permalink
Merge pull request #128 from invidian/flexkube-cli
Browse files Browse the repository at this point in the history
Add "flexkube" CLI and some other improvements
  • Loading branch information
invidian authored May 24, 2020
2 parents f9dfa93 + 6aa2d00 commit f900fab
Show file tree
Hide file tree
Showing 30 changed files with 576 additions and 235 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ builds:
- CGO_ENABLED=0
ldflags:
- -extldflags '-static'
- -s
- -w
flags:
- -buildmode=exe
goarch:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GORUN=$(GOCMD) run
GOBUILD=CGO_ENABLED=$(CGO_ENABLED) $(GOCMD) build -v -buildmode=exe -ldflags $(LD_FLAGS)

CC_TEST_REPORTER_ID=6e107e510c5479f40b0ce9166a254f3f1ee0bc547b3e48281bada1a5a32bb56d
GOLANGCI_LINT_VERSION=v1.26.0
GOLANGCI_LINT_VERSION=v1.27.0
BIN_PATH=$$HOME/bin

GO_PACKAGES=./...
Expand Down
13 changes: 0 additions & 13 deletions cli/apiloadbalancers/apiloadbalancers.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/apiloadbalancers/apiloadbalancers_test.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/controlplane/controlplane.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/controlplane/controlplane_test.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/etcdcluster/etcdcluster.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/etcdcluster/etcdcluster_test.go

This file was deleted.

125 changes: 125 additions & 0 deletions cli/flexkube/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package flexkube

import (
"fmt"

"github.com/urfave/cli/v2"
)

// Run executes flexkube CLI binary with given arguments (usually os.Args).
func Run(args []string) int {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "kubelet-pool",
Usage: "executes kubelet pool configuration",
ArgsUsage: "[POOL NAME]",
Action: withResource(kubeletPoolAction),
},
{
Name: "apiloadbalancer-pool",
Usage: "executes API Load Balancer pool configuration",
ArgsUsage: "[POOL NAME]",
Action: withResource(apiLoadBalancerPoolAction),
},
{
Name: "etcd",
Usage: "execute etcd configuration",
Action: withResource(etcdAction),
},
{
Name: "pki",
Usage: "execute PKI configuration",
Action: withResource(pkiAction),
},
{
Name: "controlplane",
Usage: "execute controlplane configuration",
Action: withResource(controlplaneAction),
},
{
Name: "kubeconfig",
Usage: "prints admin kubeconfig for cluster",
Action: withResource(kubeconfigAction),
},
},
}

err := app.Run(args)
if err != nil {
fmt.Println(err.Error())

return 1
}

return 0
}

// apiLoadBalancerPoolAction implements 'apiloadbalancer-pool' subcommand.
func apiLoadBalancerPoolAction(r *Resource) func(*cli.Context) error {
return func(c *cli.Context) error {
poolName, err := getPoolName(c)
if err != nil {
return err
}

return r.RunAPILoadBalancerPool(poolName)
}
}

// controlplaneAction implements 'controlplane' subcommand.
func controlplaneAction(r *Resource) func(*cli.Context) error {
return func(c *cli.Context) error {
return r.RunControlplane()
}
}

// etcdAction implements 'etcd' subcommand.
func etcdAction(r *Resource) func(*cli.Context) error {
return func(c *cli.Context) error {
return r.RunEtcd()
}
}

func kubeconfigAction(r *Resource) func(*cli.Context) error {
return func(c *cli.Context) error {
k, err := r.Kubeconfig()
if err != nil {
return fmt.Errorf("failed generating kubeconfig: %w", err)
}

fmt.Println(k)

return nil
}
}

func kubeletPoolAction(r *Resource) func(*cli.Context) error {
return func(c *cli.Context) error {
poolName, err := getPoolName(c)
if err != nil {
return err
}

return r.RunKubeletPool(poolName)
}
}

func pkiAction(r *Resource) func(*cli.Context) error {
return func(c *cli.Context) error {
return r.RunPKI()
}
}

func getPoolName(c *cli.Context) (string, error) {
if c.NArg() > 1 {
return "", fmt.Errorf("only one pool can be managed at a time")
}

poolName := c.Args().Get(0)
if poolName == "" {
return "", fmt.Errorf("pool name must be specified")
}

return poolName, nil
}
2 changes: 2 additions & 0 deletions cli/flexkube/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package flexkube contains logic of 'flexkube' CLI.
package flexkube
Loading

0 comments on commit f900fab

Please sign in to comment.