Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed May 31, 2023
1 parent 334c6af commit b2369bd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
args: --timeout 5000s
skip-cache: true
8 changes: 4 additions & 4 deletions pkg/roles/discovery/api_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestDeviceApplyDHCPWithDNS(t *testing.T) {
"test",
"A",
),
dns.Record{
dnsTypes.Record{
Data: "192.0.2.1",
},
)
Expand All @@ -224,7 +224,7 @@ func TestDeviceApplyDHCPWithDNS(t *testing.T) {
"1.2",
"PTR",
),
dns.Record{
dnsTypes.Record{
Data: "test.gravity.beryju.io.",
},
)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestDeviceApplyDNSWithReverse(t *testing.T) {
"test",
"A",
),
dns.Record{
dnsTypes.Record{
Data: "192.0.2.1",
},
)
Expand All @@ -305,7 +305,7 @@ func TestDeviceApplyDNSWithReverse(t *testing.T) {
"1.2",
"PTR",
),
dns.Record{
dnsTypes.Record{
Data: "test.gravity.beryju.io.",
},
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/roles/dns/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (r *Role) eventCreateForward(ev *roles.Event) {
r.log.Warn("failed to parse address to add dns record", zap.Error(err))
return
}
var rec *Record
var rec *RecordContext
if ip.Is4() {
rec = forwardZone.newRecord(hostname, types.DNSRecordTypeA)
} else {
Expand Down
12 changes: 6 additions & 6 deletions pkg/roles/dns/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const TXTSeparator = "\n"

type Record struct {
type RecordContext struct {
*types.Record

inst roles.Instance
Expand All @@ -26,7 +26,7 @@ type Record struct {
recordKey string
}

func (z *ZoneContext) recordFromKV(kv *mvccpb.KeyValue) (*Record, error) {
func (z *ZoneContext) recordFromKV(kv *mvccpb.KeyValue) (*RecordContext, error) {
fullRecordKey := string(kv.Key)
// Relative key compared to zone, format of
// host/A[/...]
Expand Down Expand Up @@ -56,8 +56,8 @@ func (z *ZoneContext) recordFromKV(kv *mvccpb.KeyValue) (*Record, error) {
return rec, nil
}

func (z *ZoneContext) newRecord(name string, t string) *Record {
return &Record{
func (z *ZoneContext) newRecord(name string, t string) *RecordContext {
return &RecordContext{
Record: &types.Record{
Name: strings.ToLower(name),
Type: t,
Expand All @@ -67,7 +67,7 @@ func (z *ZoneContext) newRecord(name string, t string) *Record {
}
}

func (r *Record) ToDNS(qname string, t uint16) dns.RR {
func (r *RecordContext) ToDNS(qname string, t uint16) dns.RR {
hdr := dns.RR_Header{
Name: qname,
Rrtype: t,
Expand Down Expand Up @@ -111,7 +111,7 @@ func (r *Record) ToDNS(qname string, t uint16) dns.RR {
return rr
}

func (r *Record) put(ctx context.Context, expiry int64, opts ...clientv3.OpOption) error {
func (r *RecordContext) put(ctx context.Context, expiry int64, opts ...clientv3.OpOption) error {
raw, err := proto.Marshal(r.Record)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/roles/dns/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
type ZoneContext struct {
*types.Zone
inst roles.Instance
records map[string]map[string]*Record
records map[string]map[string]*RecordContext
recordsWatchCtx context.CancelFunc
log *zap.Logger
etcdKey string
Expand Down Expand Up @@ -127,7 +127,7 @@ func (r *Role) newZone(name string) *ZoneContext {
},
inst: r.i,
h: make([]Handler, 0),
records: make(map[string]map[string]*Record),
records: make(map[string]map[string]*RecordContext),
recordsSync: sync.RWMutex{},
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func (z *ZoneContext) watchZoneRecords(ctx context.Context) {
defer z.recordsSync.Unlock()
rec, err := z.recordFromKV(ev.Kv)
if _, ok := z.records[rec.recordKey]; !ok {
z.records[rec.recordKey] = make(map[string]*Record)
z.records[rec.recordKey] = make(map[string]*RecordContext)
}
if ev.Type == clientv3.EventTypeDelete {
delete(z.records[rec.recordKey], rec.uid)
Expand Down

0 comments on commit b2369bd

Please sign in to comment.