Browse Source

jpictl: introduce `jpictl dns sync` to update public DNS records

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/25/head
Alejandro Mery 10 months ago
parent
commit
5d82de5535
  1. 35
      cmd/jpictl/dns.go

35
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)
}

Loading…
Cancel
Save