diff --git a/cmd/jpictl/dns.go b/cmd/jpictl/dns.go index 9ce62ec..4431801 100644 --- a/cmd/jpictl/dns.go +++ b/cmd/jpictl/dns.go @@ -3,6 +3,7 @@ package main import ( "context" "os" + "time" "github.com/spf13/cobra" @@ -10,6 +11,12 @@ import ( "git.jpi.io/amery/jpictl/pkg/dns" ) +const ( + // DNSSyncTimeout specifies how long are we willing to wait for a DNS + // synchronization + DNSSyncTimeout = 10 * time.Second +) + func newDNSManager(m *cluster.Cluster, provider dns.Provider) (*dns.Manager, error) { domain := m.Domain if m.Name != "" { @@ -90,8 +97,36 @@ var dnsWriteCmd = &cobra.Command{ }, } +var dnsSyncCmd = &cobra.Command{ + Use: "sync", + Short: "dns sync updates public DNS records", + PreRun: setVerbosity, + RunE: func(_ *cobra.Command, _ []string) error { + cred, err := dns.DefaultDNSProvider() + if err != nil { + return err + } + + m, err := cfg.LoadZones(true) + if err != nil { + return err + } + + mgr, err := newDNSManager(m, cred) + if err != nil { + return err + } + + ctx, cancel := context.WithTimeout(context.Background(), DNSSyncTimeout) + defer cancel() + + return mgr.Sync(ctx) + }, +} + func init() { rootCmd.AddCommand(dnsCmd) dnsCmd.AddCommand(dnsWriteCmd) + dnsCmd.AddCommand(dnsSyncCmd) }