-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup.go
59 lines (50 loc) · 1.9 KB
/
up.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package zone
import (
"fmt"
_ "github.com/joho/godotenv/autoload"
"github.com/spf13/cobra"
"github.com/nicklasfrahm/infrastructure/pkg/kraut/zone"
)
var (
zoneConfig = zone.Zone{
Router: &zone.ZoneRouter{},
}
configFile string
)
var upCmd = &cobra.Command{
Use: "up <host>",
Short: "Bootstrap a new availability zone",
Long: `This command will bootstrap a new zone by connecting
to the specified IP and setting up a k3s cluster on
the host that will then set up the required services
for managing the lifecycle of the zone.
To manage a zone, the CLI needs credentials for the
DNS provider that is used to manage the DNS records
for the zone. These credentials can only be provided
via the environment variable DNS_PROVIDER_CREDENTIAL
and DNS_PROVIDER or via a ".env" file in the current
working directory.`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"host"},
ValidArgs: []string{"host"},
RunE: func(cmd *cobra.Command, args []string) error {
// This should be safe because of the ExactArgs(1) constraint,
// but we still need to check it to avoid panics.
if len(args) != 1 {
return fmt.Errorf("accepts 1 arg(s), received %d", len(args))
}
host := args[0]
if err := zone.Up(host, &zoneConfig); err != nil {
return err
}
return nil
},
}
func init() {
upCmd.Flags().StringVarP(&zoneConfig.Name, "name", "n", "", "name of the zone")
upCmd.Flags().StringVarP(&zoneConfig.Domain, "domain", "d", "", "domain that will contain the DNS records for the zone")
upCmd.Flags().StringVarP(&zoneConfig.Router.Hostname, "hostname", "H", "", "hostname of the router serving the zone")
upCmd.Flags().IPVarP(&zoneConfig.Router.ID, "router-id", "r", nil, "IPv4 address of the router serving the zone")
upCmd.Flags().Uint32VarP(&zoneConfig.Router.ASN, "asn", "a", 0, "autonomous system number of the zone")
upCmd.Flags().StringVarP(&configFile, "config", "c", "", "path to the configuration file")
}