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

Implement stdlib 9 compatibility #657

Merged
merged 4 commits into from
Aug 23, 2023
Merged

Conversation

bastelfreak
Copy link
Collaborator

@bastelfreak bastelfreak commented Jul 6, 2023

stdlib 9 dropped the is_function_available() function. I reworked the code to check if pe_anchor is defined. The code now works with Puppet core functions and is compatible with Puppet 7/8, probably 6, and does not rely on stdlib.

# Instead check for the `is_pe` fact or if a PE provided function is available
$_is_pe = (getvar('::is_pe') or is_function_available('pe_compiling_server_version'))
if $_is_pe {
if $facts['is_pe'] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah derp, the fact is only available on PE primaries/compilers.

@bastelfreak bastelfreak force-pushed the stdlib9 branch 3 times, most recently from 7d73255 to e969c7c Compare July 10, 2023 10:42
Copy link
Contributor

@smortex smortex left a comment

Choose a reason for hiding this comment

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

Some in-line comments. I will push some local changes to your branch to see if it helps.

Comment on lines 47 to 45
$_is_pe = (getvar('::is_pe') or is_function_available('pe_compiling_server_version'))
# To determine if this is a PE installation or not, we check if the `pe_anchor` resource type exists
# it's provided by the puppet_enterprise module
$_is_pe = defined('pe_anchor')
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the test suite rely on the is_pe variable and removing it from the condition break the test suite. This PR being about updating dependencies, I think we can ignore this compatibility thing for now (assuming we trust the comments), and only focus on supporting recent stdlib?

puppetlabs/puppetlabs-stdlib#1386 might be useful to keep the current behavior (see bellow).

@@ -237,7 +237,7 @@ def global_facts(facts, os)
before(:each) do
Puppet::Parser::Functions.newfunction(:pe_build_version, type: :rvalue) { |_args| '2000.0.0' }
Puppet::Parser::Functions.newfunction(:pe_compiling_server_aio_build, type: :rvalue) { |_args| '1.10.100' }
Puppet::Parser::Functions.newfunction(:pe_compiling_server_version, type: :rvalue) { |_args| '2.20.200' }
Puppet::Parser::Functions.newfunction(:defined, type: :rvalue) { |_args| true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Mocking defined to return true might break things. According to the tests I did with the module it seems to be fine, but it feel fragile 😨.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why this is getting mocked here; @bastelfreak can you shed some light?

@@ -44,7 +44,7 @@
# and greping for "puppet enterprise". With Puppet 4 and PE 2015.2, there
# is no longer a "PE Puppet", and so that fact will no longer work.
# Instead check for the `is_pe` fact or if a PE provided function is available
$_is_pe = (getvar('::is_pe') or is_function_available('pe_compiling_server_version'))
$_is_pe = (getvar('::is_pe') or stdlib::has_function('pe_compiling_server_version'))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm fine with this, but we need to keep in mind that it now requires stdlib 9.3. with my defined() it works on all stdlib versions

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I am not happy with this neither… 😭

I am currently fighting with bolt to use apply with modules that support stdlib ">= 9" but Bolt's apply rely on this module which currently only support stdlib "< 9".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI I rolled out my code with defined() at a few customers and that works fine as expected

Copy link
Contributor

Choose a reason for hiding this comment

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

It is fragile but avoids the need for bumping the minimum version of stdlib. I have no PE anywhere around, so I am not really concerned about this fragility, if it is okay, then it is fine! I'll rework the commits I added to take this into account. If it fix CI and you can test this in the field to validate the change, I think we will be good to go.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll rework the commits I added to take this into account. If it fix CI and you can test this in the field to validate the change, I think we will be good to go.

Code pushed. CI failures are related to my commit messages on the commits that need merging, so if you can confirm it fix your issue on PE, you can merge the commits (fixup/squash) and I think CI will be all green 😁

@smortex smortex force-pushed the stdlib9 branch 2 times, most recently from 18b09d1 to 669bfc0 Compare August 2, 2023 02:39
@smortex
Copy link
Contributor

smortex commented Aug 2, 2023

I have squashed my changes in your commits, and CI seems happy with it.

@bastelfreak had you the opportunity to check that the behavior was not broken by my change in the real world with PE? Is this PR ready for review 😁 😉 😉?

@bastelfreak bastelfreak marked this pull request as ready for review August 2, 2023 07:11
@bastelfreak bastelfreak requested a review from a team as a code owner August 2, 2023 07:11
@bastelfreak
Copy link
Collaborator Author

@smortex yes it's working fine :)

Copy link
Contributor

@smortex smortex left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me: the minor "issues" are not blockers and given the bad situation of the module (prevent usage of latest stdlib), this is a move in the right direction. As it is now, it is still compatible with previous versions of stdlib so AFAIAC this is 💯!

:shipit:

Copy link
Contributor

@joshcooper joshcooper left a comment

Choose a reason for hiding this comment

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

Thank you @bastelfreak! We're heads down working on upcoming releases and can take a look at this next week. In the meantime could you update the summary to describe why this change is needed? I think I understand, but I admit I haven't been paying complete attention to the strict & stdlib deprecated functions issues.

stdlib 9 dropped the is_function_available() function. I reworked the
code to check if `pe_anchor` is defined. The code now works with Puppet
core functions and is compatible with Puppet 7/8, probably 6, and does
not rely on stdlib.
@bastelfreak
Copy link
Collaborator Author

@joshcooper I updated the git commit with the description and added it to the PR title as well.

I want to point out that puppetlabs/stdlib 9 was released almost 2 months ago. PE customers were not able to upgrade because this module isn't compatible. The CAT team worked hard to upgrade all of their modules. I still don't understand why the puppetdb and puppet_agent module are not owned by them / the CAT team isn't listed as code owners. From my point of view (also also from the PE customers I represent) this doesn't make sense. I pointed it out multiple times in the past years and never got a proper explanation for this. Also this wasn't changed. There was zero activity from the current owners about making puppet_agent compatible with stdlib 9. It took quite a long time to get a response here. I fail to understand why some modules are not maintained at all / maintained by other teams instead of the module with the main focus on maintaining modules. I would love to see a migration to the CAT team to ship enhancements faster to customers and to have a single source of configuration/guidelines/team for modules.

@joshcooper
Copy link
Contributor

Hi @bastelfreak, I understand your frustration, the current approach is not working for anyone. I've been advocating for moving these and *_core modules to the Modules, IAC and CAT teams for literally years. But as usual, there are too many things to do and not enough people. I am hopeful this will change in the near future though. I'll have a chat with folks on my end.

@tvpartytonight tvpartytonight merged commit f9554d9 into puppetlabs:main Aug 23, 2023
16 checks passed
@bastelfreak bastelfreak deleted the stdlib9 branch August 23, 2023 19:03
@bastelfreak
Copy link
Collaborator Author

@tvpartytonight thanks for merging <3

@AriaXLi AriaXLi added the enhancement New feature or request label Sep 20, 2023
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.

5 participants