-
Notifications
You must be signed in to change notification settings - Fork 4.8k
NO-ISSUE: Add claude md file for using the node_utils and export util functions #31078
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
Open
ngopalak-redhat
wants to merge
1
commit into
openshift:main
Choose a base branch
from
ngopalak-redhat:ngopalak/util_function_node_help_claude
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # OpenShift Node E2E Tests - Tribal Knowledge | ||
|
|
||
| ## Core Principle | ||
|
|
||
| **ALWAYS use the utility functions in `node_utils.go`** instead of implementing your own. Read that file to discover available helpers. | ||
|
|
||
| ## Key Functions & Context | ||
|
|
||
| ### Node Selection | ||
|
|
||
| - **GetNodesByLabel** - Use this for getting a subset of the nodes. The labels must be carefully chosen. | ||
| - **GetControlPlaneNodes** - These are the master nodes or the control plane nodes. In most clusters it will return 3 of them. | ||
| - **GetPureWorkerNodes** - Use this to make sure that the node returned is not a control plane node. | ||
|
|
||
| ### Node Command Execution | ||
|
|
||
| - **ExecOnNodeWithChroot** - Use this for all the root command executions inside a debug container. This can change the state of the node. Use it with caution. | ||
|
|
||
| ### Kubelet Configuration & Lifecycle | ||
|
|
||
| - **GetKubeletConfigFromNode** - Use this to check if a kubelet configuration made at the API level has been applied to the node. | ||
| - **CleanupDropInAndRestartKubelet** - Kubelet supports drop-in directory. If you manually drop-in a config use this to clean up. | ||
| - **IsNodeInReadyState** - Use this to find out if the node has completed its restart and back to ready state. | ||
| - **WaitForNodeToBeReady** - If any kubelet config is applied, use this to wait for the node to reach a ready state. | ||
| - **RestartKubeletOnNode** - Use this when testing kubelet restarts and also in cases when there are some issues that's outside the context. | ||
|
|
||
| ### MachineConfig Operations | ||
|
|
||
| - **WaitForMCP** - This is used when you create a new machine config and wait for it to be applied. Although parallel, if multiple nodes are involved it can take more time. | ||
|
|
||
| ## Common Mistakes to Avoid | ||
|
|
||
| 1. **Don't manually construct `oc debug` commands** - use `ExecOnNodeWithChroot()` or `ExecOnNodeWithNsenter()` | ||
|
|
||
| 2. **Don't forget to handle SNO clusters** - use `GetPureWorkerNodes()` to filter out nodes with dual roles | ||
|
|
||
| 3. **Don't skip context propagation** - always pass `ctx` to utility functions | ||
|
|
||
| 4. **Don't forget cleanup** - use `defer` or `g.AfterEach` with `CleanupDropInAndRestartKubelet()` | ||
|
|
||
| 5. **Don't ignore MCP rollouts** - after MachineConfig changes, use `WaitForMCP()` to ensure stability | ||
|
|
||
| 6. **Don't assume swap operations work with chroot** - use `ExecOnNodeWithNsenter()` for swap commands | ||
|
|
||
| ## Getting Help | ||
|
|
||
| - Read the function documentation in `node_utils.go` | ||
| - Look at existing tests in this directory for patterns | ||
| - Check testdata files in `testdata/node/` for config examples | ||
| - See `node_swap_cnv.go` for a complete example | ||
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,37 @@ | ||
| #!/bin/bash | ||
| # Check if node_utils.go has functions not mentioned in CLAUDE.md | ||
|
|
||
| set -e | ||
|
|
||
| NODE_UTILS="test/extended/node/node_utils.go" | ||
| CLAUDE_MD="test/extended/node/CLAUDE.md" | ||
|
|
||
| # Extract ONLY exported function names from node_utils.go (start with uppercase) | ||
| # Lowercase (unexported) helpers are intentionally not documented in CLAUDE.md | ||
| # Matches both standalone functions and receiver methods, including digits in names | ||
| UTILS_FUNCS=$( | ||
| grep -E '^[[:space:]]*func([[:space:]]+\([^)]*\))?[[:space:]]+[A-Z][A-Za-z0-9_]*[[:space:]]*\(' "$NODE_UTILS" \ | ||
| | sed -E 's/^[[:space:]]*func([[:space:]]+\([^)]*\))?[[:space:]]+([A-Z][A-Za-z0-9_]*)[[:space:]]*\(.*/\2/' \ | ||
| | sort -u | ||
| ) | ||
|
|
||
| # Read CLAUDE.md once for efficiency | ||
| CLAUDE_CONTENT=$(cat "$CLAUDE_MD") | ||
|
|
||
| # Check each function is mentioned in CLAUDE.md (word-boundary match to avoid false positives) | ||
| MISSING=() | ||
| for func in $UTILS_FUNCS; do | ||
| if ! echo "$CLAUDE_CONTENT" | grep -Fqw "$func"; then | ||
| MISSING+=(" - $func()") | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#MISSING[@]} -gt 0 ]; then | ||
| echo "⚠️ Warning: node_utils.go functions not documented in CLAUDE.md:" | ||
| printf '%s\n' "${MISSING[@]}" | ||
| echo "" | ||
| echo "Please update CLAUDE.md to document these utility functions." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ All node_utils.go functions are documented in CLAUDE.md" |
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.