Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement in difference engine #325

Open
stevendborrelli opened this issue Sep 29, 2016 · 1 comment
Open

Improvement in difference engine #325

stevendborrelli opened this issue Sep 29, 2016 · 1 comment

Comments

@stevendborrelli
Copy link
Member

stevendborrelli commented Sep 29, 2016

  1. I propose adding a new method to status.go:
// Difference returns the Current value of a Difference by key
func (t *Status) Difference(key string) (string, bool) {
    diff, ok := t.Differences[key]
    if !ok {
        return "", ok
    }
    return diff.Current(), diff.Changes()
}

Usage would be like this in an Apply() phase to check if file content has been modified:

    if content, ok := status.Difference("content"); ok && f.Type == "file" {
        err = ioutil.WriteFile(f.Destination, content, f.FileMode)
  1. As part of this, the engine and Check() should use the status.go status.AnyChanges() method.

This means that a typical check would just AddDifference() for every field, and AnyChanges() is used to see if any of the defined differences indicate a change.

Instead of doing this in my Check() method:

    if f.State != actual.State {
        status.AddDifference("state", actual.State, f.State, "")
    }

I'd just do:

status.AddDifference("state", actual.State, f.State, "")

And expect anything else to call AnyChanges() for any change or Difference() to get the value of a specific change.

We'd have to be more aggressive about using Default values to fill in results when Original or Current is not defined.

For example of default, take the example of permissions. The logic would be:

  1. If mode is set in the hcl file, use that value
  2. if the mode is not set in the hcl file but the file exists, use the existing permissions
  3. if mode is not set & the file doesn't exist, use 0750
@ryane
Copy link
Contributor

ryane commented Sep 30, 2016

👍 The docker container resource already follows the pattern of calling status.AddDifference without comparing first which mostly works today. But, other parts of the system need updating. For example, the printer doesn't check if the diffs have changes so you end up with output like described in #317 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants