Browse Source

jpictl: refactor dns.Manager factory to support Provider data

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/25/head
Alejandro Mery 1 year ago
parent
commit
c33d0dab16
  1. 33
      cmd/jpictl/dns.go

33
cmd/jpictl/dns.go

@ -10,9 +10,7 @@ import (
"git.jpi.io/amery/jpictl/pkg/dns"
)
func newDNSManager(m *cluster.Cluster) (*dns.Manager, error) {
ctx := context.TODO()
func newDNSManager(m *cluster.Cluster, provider dns.Provider) (*dns.Manager, error) {
domain := m.Domain
if m.Name != "" {
domain = m.Name + "." + domain
@ -23,6 +21,26 @@ func newDNSManager(m *cluster.Cluster) (*dns.Manager, error) {
return nil, err
}
if provider != nil {
// set provider only if specified
err = dns.WithProvider(provider)(mgr)
if err != nil {
return nil, err
}
}
if err := populateDNSManager(mgr, m); err != nil {
return nil, err
}
return mgr, nil
}
func populateDNSManager(mgr *dns.Manager, m *cluster.Cluster) error {
var err error
ctx := context.TODO()
m.ForEachZone(func(z *cluster.Zone) bool {
z.ForEachMachine(func(p *cluster.Machine) bool {
err = mgr.AddHost(ctx, z.Name, p.ID, true, p.PublicAddresses...)
@ -32,7 +50,7 @@ func newDNSManager(m *cluster.Cluster) (*dns.Manager, error) {
return err != nil
})
if err != nil {
return nil, err
return err
}
m.ForEachRegion(func(r *cluster.Region) bool {
@ -43,11 +61,8 @@ func newDNSManager(m *cluster.Cluster) (*dns.Manager, error) {
return err != nil
})
if err != nil {
return nil, err
}
return mgr, nil
return err
}
// Command
@ -65,7 +80,7 @@ var dnsWriteCmd = &cobra.Command{
return err
}
mgr, err := newDNSManager(m)
mgr, err := newDNSManager(m, nil)
if err != nil {
return err
}

Loading…
Cancel
Save