Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

schemas: add remote-manifest-v0 #106

Merged
merged 4 commits into from
May 15, 2018
Merged

Conversation

lucab
Copy link
Contributor

@lucab lucab commented Mar 26, 2018

This introduces a new schema to describe a remote via JSON manifest,
adding support for remote sources for addons.
This will be consumed in the future to automatically populate
the local store from a remote source.

@lucab lucab force-pushed the ups/remote-manifest branch 3 times, most recently from 9ef8c58 to 7c11f06 Compare April 24, 2018 14:58
@lucab lucab force-pushed the ups/remote-manifest branch 2 times, most recently from 9717624 to a5aece9 Compare May 9, 2018 13:18
@lucab lucab changed the title [WIP] schemas: add remote-manifest-v0 schemas: add remote-manifest-v0 May 9, 2018
@lucab
Copy link
Contributor Author

lucab commented May 9, 2018

Assuming #105 is at its final round, this is the next one queued to get in.

@squeed @euank rebased on latest profile-v1, PTAL.

@lucab lucab requested review from squeed and euank May 9, 2018 13:25
osMeta["COREOS_USR"] = usrMountpoint

url := r.TemplateURL
// TODO(lucab): this is suboptimal and repetitive, but I'm not sure about a compact yet idiomatic way.
Copy link
Contributor

@euank euank May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand if you don't want to add a dependency on a small unknown project, but I do think https://github.com/euank/gotmpl would be less repetitive feeling and fit this almost perfectly.

I think it would just end up as:

_, err := gotmpl.TemplateString(r.TemplateURL, gotmpl.MapLookup(map[string]string{}))
if err == nil {
   return r.TemplateURL, nil // no variables
}
if _, ok := err.(gotmpl.UnresolvedVariableError); !ok {
    return err // something wrong besides needing vars
}

return gotmpl.TemplateString(r.TemplateURL, gotmpl.MapLookup(templateVariableMap))

It also has the benefit of allowing users to escape $ characters if that's desirable, though realistically few urls will contain them anyways.

If you don't want to pull in a dependency that can do simple substitution, I do think this code would be shorter and more readable if it were generic (e.g. split into a pkg and just templated the k/v of a map, didn't go through the trouble of only substitution detected variables, etc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it's silly to keep this generic logic in here.

@euank
Copy link
Contributor

euank commented May 10, 2018

This looks reasonable to me, though I'm not much a fan of the templating code.

I think it may end up being easier to review this in conjunction with the 'fetch' logic for the well-known manifest at base url, especially if the majority template code were moved into its own package and handled separately.

if res != url {
t.Fatalf("expected %s, got %s", url, res)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would really like to see a template test here.

@lucab
Copy link
Contributor Author

lucab commented May 11, 2018

@squeed un-hardcoded the os-release path logic and added a test to exercise all template variables.

@euank vendored gotmpl and got rid of the previous poor substitution logic.

Rebased, PTAL.

@lucab
Copy link
Contributor Author

lucab commented May 14, 2018

@euank ping, I'm leaving this open for a chance in case you want to have a final pass on this. Let me know if otherwise.

if err != nil {
return "", errors.Wrapf(err, "failed to parse %s", osReleasePath)
}
osMeta["COREOS_USR"] = usrMountpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the value of exposing the usrMountpoint to the template logic.

I understand it's needed by this function to find the appropriate version (e.g. if /usr is mounted by update_engine at /tmp/au_postint_mount.xxx, it obviously needs to read os-release from there), but I don't see how the remote url would ever need to care about this detail.

Did you have any specific cases or use in mind? If there's not a specific use-case compelling this, I'd rather not support it.

Copy link
Contributor Author

@lucab lucab May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that I missed in the original design doc, so here is the full rationale. The current and upcoming USR partition both carry a local remote (com.coreos.cl). The manifest for that will contain a URL like file:///usr/share/torcx/remotes/.... Such URL works for the current USR, but at update-engine time we also need to inspect the remote coming with next-OS, which is mounted under a temporary dir. Options we have are:

  • introduce a template variable, and point the URL to file://${COREOS_USR}/share/torcx/...
  • manually replace /usr when processing the URL from com.coreos.cl

Both are a bit of corner cases, but I felt that the first one would be a bit less surprising.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, I think it makes sense to have that template variable now.

However, I think the base_url bit needs to also include file as a supported protocol, and ideally should have an example explaining this possibility (if only to say 'this is supported, but generally should only be used by pseudo-remotes distributed by the creator/vendor of /usr').

I think having that clarification could have also resolved my confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I'll fix and add a couple of explicit notes to remote-manifest-v0.md.

@euank
Copy link
Contributor

euank commented May 14, 2018

Other than the question above, this looks good to me, but I would like to resolve that question before merging.

This introduces a new schema to describe a remote via JSON manifest,
adding support for remote sources for addons.
This will be consumed in the future to automatically populate
the local store from a remote source.
@lucab
Copy link
Contributor Author

lucab commented May 15, 2018

@euank I've clarified the docs in that regard.

Copy link
Contributor

@euank euank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

A few more tests might be nice, but I think once the fetch logic is added it may be easier to test this code via testing fetch, so adding those in upcoming PRs seems fine to me.

@lucab lucab merged commit 0d97280 into coreos:master May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants