Skip to content

Commit

Permalink
diff2: Add a "hints" when change is TTL-only (#2249)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Limoncelli <tal@whatexit.org>
tlimoncelli and TomOnTime authored Mar 29, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 6ac1961 commit f676c49
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/diff2/analyze.go
Original file line number Diff line number Diff line change
@@ -170,10 +170,12 @@ func findTTLChanges(existing, desired []targetConfig) ([]targetConfig, []targetC

if ecomp == dcomp && er.TTL != dr.TTL {
m := color.YellowString("± MODIFY-TTL %s %s %s", dr.NameFQDN, dr.Type, humanDiff(existing[ei], desired[di]))
instructions = append(instructions, mkChange(dr.NameFQDN, dr.Type, []string{m},
v := mkChange(dr.NameFQDN, dr.Type, []string{m},
models.Records{er},
models.Records{dr},
))
)
v.HintOnlyTTL = true
instructions = append(instructions, v)
ei++
di++
} else if ecomp < dcomp {
2 changes: 1 addition & 1 deletion pkg/diff2/analyze_test.go
Original file line number Diff line number Diff line change
@@ -670,7 +670,7 @@ func Test_splitTTLOnly(t *testing.T) {
},
wantExistDiff: nil,
wantDesireDiff: nil,
wantChanges: "ChangeList: len=1\n00: Change: verb=CHANGE\n key={laba.f.com A}\n old=[1.2.3.4]\n new=[1.2.3.4]\n msg=[\"± MODIFY-TTL laba.f.com A 1.2.3.4 ttl=(300->700)\"]\n",
wantChanges: "ChangeList: len=1\n00: Change: verb=CHANGE\n key={laba.f.com A}\n Hints=OnlyTTL\n{laba.f.com A} old=[1.2.3.4]\n new=[1.2.3.4]\n msg=[\"± MODIFY-TTL laba.f.com A 1.2.3.4 ttl=(300->700)\"]\n",
},

{
7 changes: 7 additions & 0 deletions pkg/diff2/diff2.go
Original file line number Diff line number Diff line change
@@ -39,6 +39,10 @@ type Change struct {
Msgs []string // Human-friendly explanation of what changed
MsgsJoined string // strings.Join(Msgs, "\n")
MsgsByKey map[models.RecordKey][]string // Messages for a given key

// HintOnlyTTL is true only if (.Type == diff2.CHANGE) && (there is
// exactly 1 record being updated) && (the only change is the TTL)
HintOnlyTTL bool
}

/*
@@ -223,6 +227,9 @@ func (c Change) String() string {

fmt.Fprintf(b, "Change: verb=%v\n", c.Type)
fmt.Fprintf(b, " key=%v\n", c.Key)
if c.HintOnlyTTL {
fmt.Fprint(b, " Hints=OnlyTTL\n", c.Key)
}
if len(c.Old) != 0 {
fmt.Fprintf(b, " old=%v\n", c.Old)
}

0 comments on commit f676c49

Please sign in to comment.