jpictl: introduce jpictl dns sync to update public DNS records

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-12 20:29:18 +00:00
parent c33d0dab16
commit 5d82de5535
+35
View File
@@ -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)
}