mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-11 13:58:53 +00:00
Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries This commit splits off the cli into 3 binaries: - agent - cli - provider The provider now is a separate component that can be tested by itself and have its own lifecycle. This paves the way to a ligher c3os variant, HA support and other features that can be provided on runtime. This is working, but still there are low hanging fruit to care about. Fixes #14 * 🤖 Add provider bin to releases * ⚙️ Handle signals * ⚙️ Reduce buildsize footprint * 🎨 Scan for providers also in /system/providers * 🤖 Run goreleaser * 🎨 Refactoring
This commit is contained in:
committed by
Itxaka
parent
74bfd373db
commit
63cd28d1cb
141
internal/cmd/commands.go
Normal file
141
internal/cmd/commands.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
config "github.com/c3os-io/c3os/pkg/config"
|
||||
edgeVPNClient "github.com/mudler/edgevpn/api/client"
|
||||
"github.com/mudler/edgevpn/api/client/service"
|
||||
"github.com/mudler/edgevpn/pkg/node"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func CommonCommand(cmds ...cli.Command) []cli.Command {
|
||||
return append(commonCommands, cmds...)
|
||||
}
|
||||
|
||||
var commonCommands = []cli.Command{
|
||||
{
|
||||
Name: "get-kubeconfig",
|
||||
Usage: "Return a deployment kubeconfig",
|
||||
UsageText: "Retrieve a c3os network kubeconfig (only for automated deployments)",
|
||||
Description: `
|
||||
Retrieve a network kubeconfig and prints out to screen.
|
||||
|
||||
If a deployment was bootstrapped with a network token, you can use this command to retrieve the master node kubeconfig of a network id.
|
||||
|
||||
For example:
|
||||
|
||||
$ c3os get-kubeconfig --network-id c3os
|
||||
`,
|
||||
Flags: networkAPI,
|
||||
Action: func(c *cli.Context) error {
|
||||
cc := service.NewClient(
|
||||
c.String("network-id"),
|
||||
edgeVPNClient.NewClient(edgeVPNClient.WithHost(c.String("api"))))
|
||||
str, _ := cc.Get("kubeconfig", "master")
|
||||
b, _ := base64.RawURLEncoding.DecodeString(str)
|
||||
masterIP, _ := cc.Get("master", "ip")
|
||||
fmt.Println(strings.ReplaceAll(string(b), "127.0.0.1", masterIP))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "role",
|
||||
Usage: "Set or list node roles",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Flags: networkAPI,
|
||||
Name: "set",
|
||||
Usage: "Set a node role",
|
||||
UsageText: "c3os role set <UUID> master",
|
||||
Description: `
|
||||
Sets a node role propagating the setting to the network.
|
||||
|
||||
A role must be set prior to the node joining a network. You can retrieve a node UUID by running "c3os uuid".
|
||||
|
||||
Example:
|
||||
|
||||
$ (node A) c3os uuid
|
||||
$ (node B) c3os role set <UUID of node A> master
|
||||
`,
|
||||
Action: func(c *cli.Context) error {
|
||||
cc := service.NewClient(
|
||||
c.String("network-id"),
|
||||
edgeVPNClient.NewClient(edgeVPNClient.WithHost(c.String("api"))))
|
||||
return cc.Set("role", c.Args()[0], c.Args()[1])
|
||||
},
|
||||
},
|
||||
{
|
||||
Flags: networkAPI,
|
||||
Name: "list",
|
||||
Description: "List node roles",
|
||||
Action: func(c *cli.Context) error {
|
||||
cc := service.NewClient(
|
||||
c.String("network-id"),
|
||||
edgeVPNClient.NewClient(edgeVPNClient.WithHost(c.String("api"))))
|
||||
advertizing, _ := cc.AdvertizingNodes()
|
||||
fmt.Println("Node\tRole")
|
||||
for _, a := range advertizing {
|
||||
role, _ := cc.Get("role", a)
|
||||
fmt.Printf("%s\t%s\n", a, role)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "create-config",
|
||||
Aliases: []string{"c"},
|
||||
UsageText: "Create a config with a generated network token",
|
||||
|
||||
Usage: "Creates a pristine config file",
|
||||
Description: `
|
||||
Prints a vanilla YAML configuration on screen which can be used to bootstrap a c3os network.
|
||||
`,
|
||||
ArgsUsage: "Optionally takes a token rotation interval (seconds)",
|
||||
|
||||
Action: func(c *cli.Context) error {
|
||||
l := int(^uint(0) >> 1)
|
||||
args := c.Args()
|
||||
if len(args) > 0 {
|
||||
if i, err := strconv.Atoi(args[0]); err == nil {
|
||||
l = i
|
||||
}
|
||||
}
|
||||
cc := &config.Config{C3OS: &config.C3OS{NetworkToken: node.GenerateNewConnectionData(l).Base64()}}
|
||||
y, _ := yaml.Marshal(cc)
|
||||
fmt.Println(string(y))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "generate-token",
|
||||
Aliases: []string{"g"},
|
||||
UsageText: "Generate a network token",
|
||||
Usage: "Creates a new token",
|
||||
Description: `
|
||||
Generates a new token which can be used to bootstrap a c3os network.
|
||||
`,
|
||||
ArgsUsage: "Optionally takes a token rotation interval (seconds)",
|
||||
|
||||
Action: func(c *cli.Context) error {
|
||||
l := int(^uint(0) >> 1)
|
||||
args := c.Args()
|
||||
if len(args) > 0 {
|
||||
if i, err := strconv.Atoi(args[0]); err == nil {
|
||||
l = i
|
||||
}
|
||||
}
|
||||
fmt.Println(node.GenerateNewConnectionData(l).Base64())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user