-
Notifications
You must be signed in to change notification settings - Fork 81
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
DRAFT: RFC for Resource#current_value #143
Conversation
@@ -1,11 +1,10 @@ | |||
--- | |||
RFC: unassigned | |||
Author: Alan Smithee <asmithee@example.com> | |||
Author: John Keiser <jkeiser@chef.io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not intended to commit this.
I don't know if this should be a global API. I agree the general idea is useful, but I'm not sure this needs to be in core. The examples with core resources feel kind of contrived, this really seems to come up more in super-advanced use cases like chef-provisioning and poise-ruby/python (if we extend this to the general case of "resources having output data". For the example using Basically this feels like a footgun unless we drop down a level and come up with a more general solution for resources having output data, of which current state will be a specific use case. |
Copying from IRC for the future:
|
Also a list of use cases we should map out:
|
I'd like to be able to say: package package_installable?("git-core") ? "git-core" : "git"
|
Type: Standards Track | ||
--- | ||
|
||
# Allow Current Value To Be Read From Resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you decide to call this current_resource
instead of current_value
after writing this title and the paragraph of text under it? I think these might just need to be updated to:
# Allow Current Resource to be Created from Resource Collection
Resources get a `current_resource` method, which discovers an existing resource in the resource collection and loads a new copy of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent is to read the actual value from the system, not from the resource collection, actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you say current_value
here when the examples further down call the new DSL current_resource
, right? Or is this proposing both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just current_value--which corresponds to the new load_current_value
API. current_resource might be the right word, but in that case it would still correspond to Provider.load_current_resource
, an existing API which lets you load the current value of the resource from the system.
Just reading the other comments here, and catching up. I think my use case is a little less elaborate than @coderanger's described one. I'd simply like to see what parameters were set on a resource, by looking it up. For example, if a resource installs some files at a particular path, I'd love to fetch that path later in a recipe in order to some additional work on it. Regarding @lamont-granquist's example, I couldn't tell if Overall, I'd be happy with this RFC being implemented, FWIW. 👍 for writing it @jkeiser! |
So And querying state like that is perfectly idempotent. But instead of having awful case statements around platform and platform_version (and having to take into account debian, ubuntu and linuxmint and where exactly the pv on all of those uniquely change) you just duck-type the operating system. In pseudo-code it has this kind of shape:
For any given platform and platform_version the boolean value it returns is deterministic, and overall its idempotent and convergent, but it allows you to query the operating system to find out how it behaves rather than having to manage a case statement with knowledge about how every platform and platform_version behaves. Because ultimately I really don't care. If I have a platform which lets me install 'git-core' then I know I'm on old-debian where 'git' is really 'gnu interactive toolset' and I need to use 'git-core', otherwise I just use 'git' and that works for every case I'm aware of. If we discover a new platform and platform_versions which have a similar lineage to debian then it'll just work without modification (although the better win is that we already have that platform, which is linuxmint, and i think i'm the only person in the Chef community who ever bothers to convert ubuntu versions to linuxmint versions whenever i find them). |
Also -dev vs -devel vs none for header files gets a lot easier: package "foo"
package "foo-dev" if package_installable?("foo-dev")
package "foo-devel" if package_installable?("foo-devel") That'll support fedora, amazon, all the rhels, debian, ubuntu, raspbian, linuxmint and arch at least right out of the box, and has a good shot of solaris, gentoo, etc i think. All without a stupid case statement around the platform. |
There's another use case here, which is minitest-chef-handler. It already implements this kind of behavior using resources and load_current_resource in the provider in order to generate matchers for minitest. So if you're writing a rule that a file should have mode 0644 or whatever, internally minitest will create a file resource and call load_current_resource and then pull the mode out. If we turn this into a public API it will create less breakage for minitest-chef-handler and we should be able to integrate similar chef resources based matchers with rspec. |
Maybe idempotent is a poor word choice on my part, but something about that example does not feel declarative about the state of the system. In any case, I withdraw the comment since I can't really justify why it strikes me that way. My use case would be to look at the desired state of a resource that has already been declared, not the current state of the resource, so I'd love to see a way for us to look up both. I would think that if we looked up the resource in the resource collection, it would contain both the result of load_current_resource data as well as the desired state (new_resource.params). |
Perhaps I should just use the existing |
Its still also declarative, but it is giving you a much better if-then language to use: "if you can install git-core then it should be installed" or "if you can install zlib-devel, then it should be installed". Rather than "if you are on ubuntu older than X, or linuxmint older than Y, or debian older than X, then git-core should be installed", which is tedious. |
seems this snuck into the code: should probably close this RFC, we could open the RFC again if there were issues with the current_value implementation there. |
Agreed. |
We have load_current_value and current_value, and this RFC is inaccurate as to how they've worked now for years. |
CC @coderanger @danielsdeleo @someara @lamont-granquist @jaym
Until we've worked through the use cases @coderanger has brought up (I haven't had time this week), this is on hold.