Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

debug/
target/
**/*.rs.bk
Expand Down
3 changes: 3 additions & 0 deletions .envrc.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

# vim: syntax=conf
#
# If you use direnv, you can autoload the nix shell:
Expand Down
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

nix/** linguist-generated
Cargo.nix linguist-generated
crate-hashes.json linguist-generated
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/01-normal-issue.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
name: Normal issue
about: This is just a normal empty issue with a simple checklist
title: ''
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/02-bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
name: "🐛 Bug Report"
description: "If something isn't working as expected 🤔."
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
blank_issues_enabled: true
contact_links:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
This file is automatically generated from the templates in stackabletech/operator-templating
DO NOT MANUALLY EDIT THIS FILE
-->

## Check and Update Getting Started Script

<!--
Expand Down
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/pre-release-rust-deps.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
This file is automatically generated from the templates in stackabletech/operator-templating
DO NOT MANUALLY EDIT THIS FILE
-->

## Bump Rust Dependencies for Stackable Release YY.M.X

<!--
Expand Down
2 changes: 2 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
self-hosted-runner:
# Ubicloud machines we are using
Expand Down
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
This file is automatically generated from the templates in stackabletech/operator-templating
DO NOT MANUALLY EDIT THIS FILE
-->

## Description

*Please add a description here. This will become the commit message of the merge request later.*
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration-test-custom.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
name: Integration Test (Custom)

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration-test-profile.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
name: Integration Test (Profile + Schedule)

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr_prek.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
name: prek

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

tests/_work/
debug/
target/
Expand Down
2 changes: 2 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
ignored:
# Warning: Use the -y switch to avoid manual input dnf install -y <package>
Expand Down
2 changes: 2 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
# All defaults or options can be checked here:
# https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
exclude: ^(Cargo\.nix|crate-hashes\.json|nix/.*)$

Expand Down Expand Up @@ -66,6 +68,19 @@ repos:

- repo: local
hooks:
- id: script-tests
name: script-tests
language: system
entry: python3 -m unittest discover --start-directory scripts --pattern '*.py'
pass_filenames: false
files: ^scripts/.*\.py$

- id: check-namespaced-defines
name: check-namespaced-defines
language: system
entry: python3 scripts/check_namespaced_defines.py
files: ^deploy/helm/[^/]+/templates/

- id: regenerate-charts
name: regenerate-charts
language: system
Expand Down
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

[MESSAGES CONTROL]

# These rules are for missing docstrings which doesn't matter much for most of our simple scripts
Expand Down
9 changes: 9 additions & 0 deletions .vscode/DO_NOT_EDIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# DO NOT EDIT

The files in this directory are automatically generated from the templates in stackabletech/operator-templating

DO NOT MANUALLY EDIT THESE FILES

> [!NOTE]
> This file only exists because VS Code currently doesn't support JSONC files.
> See <https://github.com/microsoft/vscode/issues/269824>
2 changes: 2 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
extends: default

Expand Down
3 changes: 3 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

# Load the metadata first, so that we immediately get access to the operator name
meta = read_json('nix/meta.json')
operator_name = meta['operator']['name']
Expand Down
5 changes: 4 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

# This file is the source of truth for all our repos!
# This includes repos not templated by operator-templating, please copy/paste the file for this repos.

#
# TIP: Use "cargo deny check" to check if everything is fine

[graph]
Expand Down
3 changes: 3 additions & 0 deletions nix/sources.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# DO NOT EDIT, this file is generated by operator-templating
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

[toolchain]
channel = "1.97.1"
profile = "default"
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

# This file includes unstable features, so you need to run "cargo +nightly fmt" to format your code.
# It's also ok to use the stable toolchain by simple running "cargo fmt", but using the nightly formatter is preferred.

Expand Down
4 changes: 4 additions & 0 deletions scripts/auto-retry-tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python3

# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

"""
Automated test suite runner with intelligent retry logic for flaky integration tests.

Expand Down
95 changes: 95 additions & 0 deletions scripts/check_namespaced_defines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""
Fails when a Helm defined template, or a call to one, is not prefixed with the
name of the chart it lives in.

To run tests for this script:
python3 -m unittest check_namespaced_defines.py
"""

import re
import unittest
from pathlib import Path

NAME_PATTERN = r'\b(?:define|include|template)\s+"([^"]+)"'
CHART_PATTERN = r"(?:^|/)deploy/helm/(?P<chart>[^/]+)/templates/"


def chart_of(path):
"""The chart whose templates directory holds path, or None if it is outside one."""
found = re.search(CHART_PATTERN, Path(path).as_posix())
return found.group("chart") if found else None


def unprefixed(file_contents, chart_name):
"""The defined template names in file_contents, and the calls to them, lacking the chart prefix."""
names = re.findall(NAME_PATTERN, file_contents)
return sorted({name for name in names if not name.startswith(f"{chart_name}.")})


# Run these with: python3 -m unittest check_namespaced_defines.py
class TestCoreMethods(unittest.TestCase):
def test_chart_of(self):
self.assertEqual(
chart_of("deploy/helm/trino-operator/templates/x.yaml"), "trino-operator"
)
# An absolute path has to give the same answer, or a manual run invents a chart name.
self.assertEqual(
chart_of("/tmp/wt/deploy/helm/secret-operator/templates/a/b.yaml"),
"secret-operator",
)
self.assertIsNone(chart_of("deploy/helm/trino-operator/values.yaml"))
self.assertIsNone(chart_of("README.md"))

def test_prefixed_is_accepted(self):
text = '{{- define "trino-operator.labels" -}}\n{{ include "trino-operator.chart" . }}\n'
self.assertEqual(unprefixed(text, "trino-operator"), [])

def test_unprefixed_define_is_reported(self):
self.assertEqual(
unprefixed('{{- define "helper.thing" -}}', "trino-operator"),
["helper.thing"],
)

def test_unprefixed_call_is_reported(self):
# A renamed definition whose call sites did not move with it stops the chart rendering.
text = (
'{{ include "operator.fullname" . }}\n{{ template "operator.labels" . }}\n'
)
self.assertEqual(
unprefixed(text, "trino-operator"), ["operator.fullname", "operator.labels"]
)

def test_keyword_must_stand_alone(self):
# Without a word boundary any identifier ending in the keyword matches.
self.assertEqual(
unprefixed('{{ .Values.xinclude "bar.baz" }}', "foo-operator"), []
)


if __name__ == "__main__":
import sys

if not sys.argv[1:]:
print(f"usage: {sys.argv[0]} deploy/helm/<chart>/templates/*", file=sys.stderr)
sys.exit(2)

failed = False
for path in sys.argv[1:]:
chart_name = chart_of(path)
if chart_name is None:
print(
f"{sys.argv[0]}: {path} is not inside deploy/helm/<chart>/templates/",
file=sys.stderr,
)
sys.exit(2)
file_contents = Path(path).read_text(encoding="utf-8")
unprefixed_names = unprefixed(file_contents, chart_name)
if unprefixed_names:
failed = True
print(
f"{path}: defined templates and the calls to them must be prefixed with '{chart_name}.'"
)
for name in unprefixed_names:
print(f" {name}")

sys.exit(1 if failed else 0)
4 changes: 4 additions & 0 deletions scripts/docs_templating.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash

# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

set -euo pipefail

# Reads a file with variables to insert into templates, and templates all .*.j2 files
Expand Down
3 changes: 3 additions & 0 deletions scripts/ensure_one_trailing_newline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

"""
Given the location of a file, trims all trailing blank lines and
places a single one. Used as post-processing step for README rendering.
Expand Down
4 changes: 4 additions & 0 deletions scripts/render_readme.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash

# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

set -euo pipefail

# Check if jinja2 is there
Expand Down
3 changes: 3 additions & 0 deletions scripts/run-tests
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# vim: filetype=python syntax=python tabstop=4 expandtab

# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

import argparse
import collections.abc
import contextlib
Expand Down
3 changes: 3 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash

# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

./scripts/run-tests "$@"
3 changes: 3 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE

let
self = import ./. {};
inherit (self) sources pkgs meta;
Expand Down
5 changes: 5 additions & 0 deletions tests/README-templating.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
This file is automatically generated from the templates in stackabletech/operator-templating
DO NOT MANUALLY EDIT THIS FILE
-->

# Test Scenario Templating

## Introduction
Expand Down
2 changes: 2 additions & 0 deletions tests/kuttl-test.yaml.jinja2
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
---
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
Expand Down
2 changes: 2 additions & 0 deletions tests/templates/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is automatically generated from the templates in stackabletech/operator-templating
# DO NOT MANUALLY EDIT THIS FILE
Loading