fix
This commit is contained in:
1 file changed
+25
-1
@@ -337,10 +337,35 @@ func (c *Client) ApplyChanges(ctx context.Context, creds provider.Credentials, z
|
|||||||
}
|
}
|
||||||
|
|
||||||
base := "/zones/" + url.PathEscape(zoneID) + "/rrset"
|
base := "/zones/" + url.PathEscape(zoneID) + "/rrset"
|
||||||
|
applied := 0
|
||||||
for _, d := range cs.Diffs {
|
for _, d := range cs.Diffs {
|
||||||
if d.ReadOnly || d.Kind == diff.InSync {
|
if d.ReadOnly || d.Kind == diff.InSync {
|
||||||
continue
|
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 {
|
switch d.Kind {
|
||||||
case diff.Add:
|
case diff.Add:
|
||||||
if d.Desired == nil {
|
if d.Desired == nil {
|
||||||
@@ -372,7 +397,6 @@ func (c *Client) ApplyChanges(ctx context.Context, creds provider.Credentials, z
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user