-
Notifications
You must be signed in to change notification settings - Fork 38
Fix events RBAC and automate Helm ClusterRole generation from markers #292
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env python3 | ||
| """Sync rules from config/rbac/role.yaml into the Helm ClusterRole template. | ||
|
|
||
| The Helm template must contain: | ||
| # GENERATED RULES BEGIN | ||
| ... | ||
| # GENERATED RULES END | ||
| markers inside its ClusterRole rules section. Everything between the markers | ||
| is replaced with the rules from config/rbac/role.yaml (indented by two spaces). | ||
| """ | ||
| import re | ||
| import sys | ||
|
|
||
| ROLE_YAML = "config/rbac/role.yaml" | ||
| HELM_RBAC = "helm/temporal-worker-controller/templates/rbac.yaml" | ||
| BEGIN_MARKER = " # GENERATED RULES BEGIN" | ||
| END_MARKER = " # GENERATED RULES END" | ||
|
|
||
|
|
||
| def extract_rules_text(path): | ||
| with open(path) as f: | ||
| content = f.read() | ||
| idx = content.find("\nrules:\n") | ||
| if idx == -1: | ||
| print(f"ERROR: 'rules:' not found in {path}", file=sys.stderr) | ||
| sys.exit(1) | ||
| rules_body = content[idx + len("\nrules:\n"):] | ||
| # Indent lines relative to the `rules:` key in the Helm template. | ||
| # controller-gen emits two indentation levels: | ||
| # col 0: outer list items (e.g. "- apiGroups:") → add 2 spaces | ||
| # col 2: inner list values (e.g. " - events") → add 4 spaces | ||
| # col 2: mapping keys (e.g. " resources:") → add 2 spaces | ||
| # The extra indent on inner list values matches the style used by the | ||
| # hand-authored rules in the Helm template. | ||
| lines = rules_body.splitlines(keepends=True) | ||
| result = [] | ||
| for line in lines: | ||
| if not line.strip(): | ||
| result.append(line) | ||
| elif line.startswith(" - "): | ||
| result.append(" " + line) # inner list value: 2 global + 2 extra | ||
| else: | ||
| result.append(" " + line) # outer list item or mapping key: 2 global | ||
| return "".join(result) | ||
|
|
||
|
|
||
| def update_helm(path, rules_text): | ||
| with open(path) as f: | ||
| content = f.read() | ||
| pattern = re.compile( | ||
| r"(" + re.escape(BEGIN_MARKER) + r"[^\n]*\n)(.*?)(" + re.escape(END_MARKER) + r")", | ||
| re.DOTALL, | ||
| ) | ||
| if not pattern.search(content): | ||
| print(f"ERROR: markers not found in {path}", file=sys.stderr) | ||
| sys.exit(1) | ||
| updated = pattern.sub(r"\g<1>" + rules_text + r"\g<3>", content) | ||
| with open(path, "w") as f: | ||
| f.write(updated) | ||
| print(f"Synced RBAC rules from {ROLE_YAML} → {HELM_RBAC}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| rules = extract_rules_text(ROLE_YAML) | ||
| update_helm(HELM_RBAC, rules) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.