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

compilecatalog: Switch to new HTTP client implementation #61

Merged
merged 1 commit into from
Jun 8, 2022

Conversation

bastelfreak
Copy link
Member

@bastelfreak bastelfreak commented May 16, 2022

The new HTTP client was introduced in puppetlabs/puppet#7826. First released in Puppet 6.11.0. The old HTTP client is deprecated. The new implementation makes it quite easy to configure additional/custom TLS certificates. I
plan to implement that in another PR.

@bastelfreak bastelfreak marked this pull request as draft May 16, 2022 11:23
@bastelfreak bastelfreak force-pushed the httpclient branch 4 times, most recently from e557c96 to 2f55c10 Compare May 17, 2022 07:57
@bastelfreak bastelfreak marked this pull request as ready for review May 17, 2022 07:58
@bastelfreak bastelfreak force-pushed the httpclient branch 3 times, most recently from e56e0f0 to 62bfd85 Compare May 17, 2022 08:01
Comment on lines -52 to -54
port = server_url.port
use_ssl = port != 8080
connection = Puppet::Network::HttpPool.http_instance(server_url.host, port, use_ssl)
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously we checked the port. PuppetDB uses 8080 for HTTP and 8081 for HTTPS. But the config always returns a full URI: https://puppet.com/docs/puppetdb/7/puppetdb_connection.html#server-urls
Instead of hardcoding the Port/protocol here I think we should use what the config file returns.

@@ -58,7 +58,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.10.0 < 7.0.0"
"version_requirement": ">= 6.11.0 < 7.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

One of the main use cases of catalog-diff is to help people upgrade from old/unsupported versions of puppet. It may be counterproductive to break it for Puppet 4 and 5.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the README.md to clarify this. Only the system that runs catalog-diff needs to be Puppet 6.11 or newer. You can still get catalogs from ancient Puppetserver/Puppetdb. I think this is fine. Nobody should run this on a box with Puppet Agent 5 or older.

rescue PSON::ParserError => e
raise "Error parsing json output of puppet catalog query for #{node_name}: #{e.message}. Content: #{ret}"
raise "Error parsing json output of puppet catalog query for #{node_name}: #{e.message}. Content: #{ret.body}"

Choose a reason for hiding this comment

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

Just of a general comment, unrelated to this PR. Puppet switched from PSON to JSON by default in Puppet 5, we'd like to drop PSON at some point (https://tickets.puppetlabs.com/browse/PUP-9648), and PSON is not suitable to encoding rich data (https://tickets.puppetlabs.com/browse/PUP-10928). Alternatively, you could simplify this code to "get a catalog the same way the agent does without using the indirector". Something like:

http = Puppet.runtime[:http]
session = http.create_session
compiler = session.route_to(:compiler)
catalog = compiler.post_catalog(...)

Here is documentation about the arguments to post_catalog

Also this is how the agent calls the same method to get a catalog

There is also a post_catalog4

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the note. I will keep that in mind for further refactoring.

@bastelfreak
Copy link
Member Author

@alexjfisher any objections on merging this?

The new HTTP client was introduced in
puppetlabs/puppet#7826. First released in
Puppet 6.11.0. The old HTTP client is deprecated. The new implementation
makes it quite easy to configure additional/custom TLS certificates. I
plan to implement that in another PR.
@alexjfisher
Copy link
Member

I think it's ok.

@bastelfreak bastelfreak merged commit 233c2f5 into voxpupuli:master Jun 8, 2022
@bastelfreak bastelfreak deleted the httpclient branch June 8, 2022 11:14
@bastelfreak bastelfreak added the enhancement New feature or request label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants