This commit is contained in:
vasyansk committed 2026-11-02 18:01:26 +07:00
1 parent 8417a144d6
commit b924923358
1 file changed
+25 -1
+25 -1
View File
@@ -337,10 +337,35 @@ func (c *Client) ApplyChanges(ctx context.Context, creds provider.Credentials, z
}
base := "/zones/" + url.PathEscape(zoneID) + "/rrset"
applied := 0
for _, d := range cs.Diffs {
if d.ReadOnly || d.Kind == diff.InSync {
continue
}
if err := c.applyOne(ctx, base, tok, idByKey, d); err != nil {
// Apply is not atomic: name the failing record and how many
// diffs already went through, so the operator can see the state.
return fmt.Errorf("%s (применено до ошибки: %d): %w", describeDiff(d), applied, err)
}
applied++
}
return nil
}
// describeDiff renders a diff for error messages: "add CNAME mail.x. [value]".
func describeDiff(d diff.RecordDiff) string {
rec := d.Desired
if rec == nil {
rec = d.Actual
}
out := fmt.Sprintf("%s %s", d.Kind, d.Key())
if rec != nil {
out += fmt.Sprintf(" ttl=%d %q", rec.TTL, rec.Values)
}
return out
}
func (c *Client) applyOne(ctx context.Context, base, tok string, idByKey map[string]string, d diff.RecordDiff) error {
switch d.Kind {
case diff.Add:
if d.Desired == nil {
@@ -372,7 +397,6 @@ func (c *Client) ApplyChanges(ctx context.Context, creds provider.Credentials, z
return err
}
}
}
return nil
}