-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from invidian/flexkube-cli
Add "flexkube" CLI and some other improvements
- Loading branch information
Showing
30 changed files
with
576 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ builds: | |
- CGO_ENABLED=0 | ||
ldflags: | ||
- -extldflags '-static' | ||
- -s | ||
- -w | ||
flags: | ||
- -buildmode=exe | ||
goarch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package flexkube contains logic of 'flexkube' CLI. | ||
package flexkube |
Oops, something went wrong.