Skip to content

Conversation

xbulat
Copy link
Contributor

@xbulat xbulat commented Sep 8, 2025

Summary

This PR fixes the Puppet case expression that selects the correct Kubernetes API template version based on $kubernetes_version
Previously, the regex patterns were too permissive and matched unintended substrings (e.g., 1.31.12 was incorrectly matching /1.12/).

The updated implementation ensures that matching occurs strictly on the major.minor portion of the version string, following the format X.Y.Z.

Changes

Anchored regex patterns with ^ to ensure the version string starts with 1.

Improved readability by grouping valid minor versions explicitly.

Example of the updated logic:

$template = $kubernetes_version ? {
  /^1\.12(\.|$)/                   => 'v1alpha3',
  /^1\.(13|14|15)(\.|$)/           => 'v1beta1',
  /^1\.(16|17|18|19|20|21)(\.|$)/  => 'v1beta2',
  default                          => 'v1beta3',
}

Additional Context

Root cause: Regex patterns were too broad, leading to false positives when the patch version contained substrings like 12.

Steps to reproduce:

Set $kubernetes_version = '1.31.12' → previously matched v1alpha3.

After fix → correctly resolves to v1beta3.

Thought process:

Instead of substring matches, I anchor on start-of-string ^ to ensure the regex only evaluates against major.minor.

@xbulat xbulat requested review from bastelfreak, deric and a team as code owners September 8, 2025 07:27
@CLAassistant
Copy link

CLAassistant commented Sep 8, 2025

CLA assistant check
All committers have signed the CLA.

@deric deric merged commit b4b7e4d into puppetlabs:main Sep 8, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants