Skip to content

feat(template): Check that Helm defined templates carry the chart name - #647

Open
lfrancke wants to merge 2 commits into
mainfrom
push-uxpqnklnznyt
Open

feat(template): Check that Helm defined templates carry the chart name#647
lfrancke wants to merge 2 commits into
mainfrom
push-uxpqnklnznyt

Conversation

@lfrancke

@lfrancke lfrancke commented Sep 3, 2026

Copy link
Copy Markdown
Member

Adds a script called by prek which walks our charts and checks whether all defines/calls use a namespaced name

I tested it locally:

❯ python3 scripts/check_namespaced_defines.py deploy/helm/trino-operator/templates/*
  deploy/helm/trino-operator/templates/_helpers.tpl: defined templates and the calls to them must be prefixed with 'trino-operator.'
    operator.appname
    operator.chart
    operator.fullname
    operator.image
    operator.labels
    operator.name
    operator.selectorLabels
    operator.serviceAccountName
    operator.testLabels
  deploy/helm/trino-operator/templates/_maintenance.tpl: defined templates and the calls to them must be prefixed with 'trino-operator.'
    maintenance.envVars
  deploy/helm/trino-operator/templates/_telemetry.tpl: defined templates and the calls to them must be prefixed with 'trino-operator.'
    operator.appname
    telemetry.envVars
  deploy/helm/trino-operator/templates/clusterrole-operator.yaml: defined templates and the calls to them must be prefixed with 'trino-operator.'
    operator.fullname
    operator.labels
    operator.name
  deploy/helm/trino-operator/templates/clusterrole-product.yaml: defined templates and the calls to them must be prefixed with 'trino-operator.'
    operator.labels
    operator.name
  deploy/helm/trino-operator/templates/deployment.yaml: defined templates and the calls to them must be prefixed with 'trino-operator.'
    maintenance.envVars
    operator.appname
    operator.fullname
    operator.image
    operator.labels
    operator.selectorLabels
    operator.serviceAccountName
    telemetry.envVars
  deploy/helm/trino-operator/templates/service.yaml: defined templates and the calls to them must be prefixed with 'trino-operator.'
    operator.fullname
    operator.labels
    operator.selectorLabels
  deploy/helm/trino-operator/templates/serviceaccount.yaml: defined templates and the calls to them must be prefixed with 'trino-operator.'
    operator.fullname
    operator.labels
    operator.serviceAccountName

This was a checkout before the rollout of #645
It succeeds on main now.

stackabletech/issues#882

Adds a script called by prek which walks our charts and checks whether
all defines/calls use a namespaced name

stackabletech/issues#882
@lfrancke lfrancke self-assigned this Sep 3, 2026
@lfrancke
lfrancke marked this pull request as ready for review September 3, 2026 10:08
@lfrancke lfrancke moved this to Development: Waiting for Review in Stackable Engineering Sep 3, 2026
@Maleware
Maleware self-requested a review September 4, 2026 07:13
@Maleware Maleware moved this from Development: Waiting for Review to Development: In Review in Stackable Engineering Sep 4, 2026
@Techassi
Techassi self-requested a review September 4, 2026 07:30
Comment thread template/.pre-commit-config.yaml.j2
Comment thread template/scripts/check_namespaced_defines.py Outdated
file=sys.stderr,
)
sys.exit(2)
names = unprefixed(Path(path).read_text(), chart)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does read_text do here? I think we should explain it, because at least I don't understand it just from context. It might be obvious for people used to Python, but it is not obvious for me (and potentially a bunch of other people).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it does what I assume it does - reading the file as text - this is even more surprising and should be documented. Usually, filesystem io goes through a file first: File::open(path).read() (pseudo code).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_text

This also exists in Java and in Rust, no? Shortcuts to just read the full file?
Honest question: What do you find surprising here? I read the code and thought "yup, makes sense"
So on this I'll push back and say: This is the normal way I learned.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mhm yeah. I find it very unintuitive personally, especially coming from Rust. In Rust we have this:

// The long form
let mut contents = String::new();
let file = std::fs::File::open("my-path")?;
let n = file.read(&mut contents)?;

// The short form
let contents = std::fs::read_to_string("my-path")?;

Both forms make it very obvious - in my opinion - what the code does.

When I saw the Python code, my mind didn't connect the dots at all before reading it multiple times and seeing how it is used by unprefixed(). I find the jump from a plain path to the contents of (a potential) file at that path very odd.

Comment thread template/scripts/check_namespaced_defines.py Outdated
return sorted({name for name in names if not name.startswith(f"{chart}.")})


class TestCoreMethods(unittest.TestCase):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is generally nice that there are some tests, but how exactly are they executed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's documented right at the beginning of the file. They are not executed automatically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

python3 -m unittest check_namespaced_defines.py

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But.... it might be relatively easy to add them to CI, I'll see about that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should be possible. Question is if it should go into the prek file and then tested indirectly via github actions or directly into github actions and leave the test out of prek. Opinions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's documented right at the beginning of the file. They are not executed automatically.

Ah I see. I kinda skipped that block of text. Could we maybe leave a simple comment here either stating the command or referring back to the top of the file?

Question is if it should go into the prek file and then tested indirectly via github actions or directly into github actions and leave the test out of prek. Opinions?

I would say add it to prek. For people who have it enabled locally to run on git commit, it will immediately be tested and validates that any potential change still passes. Additionally, we can more easily scope based on file paths.

Only having it in CI as a separate workflow delays the time one sees if the tests still pass - potentially leading to a follow-up fix commit.

* Rename vairable
* Fix the locale so it doesn't depend on the machine
* Switch to a named capture group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development: In Review

Development

Successfully merging this pull request may close these issues.

3 participants