Skip to content

refactor: centralize credential and param extraction for eks workload list#1089

Merged
VaibhavUpreti merged 2 commits intoTracer-Cloud:mainfrom
cokerrd:issue/895-eks-listing-tool-refactor
Apr 29, 2026
Merged

refactor: centralize credential and param extraction for eks workload list#1089
VaibhavUpreti merged 2 commits intoTracer-Cloud:mainfrom
cokerrd:issue/895-eks-listing-tool-refactor

Conversation

@cokerrd
Copy link
Copy Markdown
Contributor

@cokerrd cokerrd commented Apr 29, 2026

Fixes #
#895

Describe the changes you have made in this PR -

  • Created a shared helper module in app/tools/utils/eks_workload_helper.py that centralizes the repeated credential and parameter extraction.
  • Removed the repeated _list_pods_extract_params function from EKSListPodsTool,EKSListDeploymentsTool and EKSListClustersTool.
  • Removed the _eks_creds definition from EKSListClustersTool and imported from helper to EKSListPodsTool and EKSListDeploymentsTool.
  • Added tests for helper module

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR centralizes repeated credential and parameter extraction across EKSListPodsTool and EKSListDeploymentsTool into a shared extract_workload_params helper, which is a good DRY improvement. However, EKSListClustersTool was also switched to this helper even though it needs different parameters.

  • P1 — broken cluster filtering: The old _list_clusters_extract_params extracted cluster_names (a list used to filter results in list_eks_clusters). The new extract_workload_params only extracts cluster_name (singular), so cluster_names is never passed to the function and the filter is silently skipped — all clusters are always returned regardless of source config. EKSListClustersTool should keep its own extractor (or extract_workload_params should be extended with a clusters variant).

Confidence Score: 4/5

Not safe to merge as-is — cluster name filtering is silently broken for EKSListClustersTool

One P1 logic bug: extract_workload_params omits cluster_names (plural) extraction, causing list_eks_clusters to ignore any configured name filter and always return all clusters. The refactor is correct for pods and deployments. Remaining findings are minor (dead code, test style).

app/tools/utils/eks_workload_helper.py and app/tools/EKSListClustersTool/__init__.py need attention for the missing cluster_names parameter

Important Files Changed

Filename Overview
app/tools/utils/eks_workload_helper.py New shared helper — correct for pods/deployments, but missing cluster_names extraction needed by EKSListClustersTool
app/tools/EKSListClustersTool/init.py Switched to extract_workload_params which drops cluster_names filtering; _eks_creds is now dead code
app/tools/EKSListDeploymentsTool/init.py Clean refactor — removed duplicate _list_deployments_extract_params and replaced with shared helper correctly
app/tools/EKSListPodsTool/init.py Clean refactor — removed duplicate _list_pods_extract_params and replaced with shared helper correctly
tests/tools/utils/test_eks_workload_helper.py Good coverage of the new helper; one non-idiomatic try/except pattern instead of pytest.raises

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[sources dict] --> B[extract_workload_params]
    B --> C{eks key present?}
    C -- No --> D[raise ValueError]
    C -- Yes --> E[Extract cluster_name, namespace, eks_backend]
    E --> F[Extract creds via _eks_creds\nrole_arn, external_id, region, credentials]
    F --> G[Return merged params dict]

    G --> H[list_eks_pods]
    G --> I[list_eks_deployments]
    G --> J[list_eks_clusters ⚠️]

    J --> K[cluster_names always None\nfiltering never applied]

    style J fill:#ff9999
    style K fill:#ff9999
Loading

Comments Outside Diff (1)

  1. app/tools/EKSListClustersTool/__init__.py, line 21-27 (link)

    P2 _eks_creds is now dead code

    After removing _list_clusters_extract_params and replacing it with extract_workload_params, _eks_creds is no longer referenced anywhere in this file. It was previously imported by EKSListDeploymentsTool and EKSListPodsTool, but those imports have been removed. The duplicate can be deleted.

Reviews (1): Last reviewed commit: "refactor: centralize credential and para..." | Re-trigger Greptile

Comment on lines +19 to +31
def extract_workload_params(sources: dict[str, dict]) -> dict[str, Any]:
"""Extract common parameters for workload list operations (pods/deployments)"""

eks = sources.get("eks")
if eks is None:
raise ValueError("Sources dictionary must contain an 'eks' key with cluster configuration")

return {
"cluster_name": eks.get("cluster_name", ""),
"namespace": eks.get("namespace") or "all",
"eks_backend": eks.get("_backend"),
**_eks_creds(eks),
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 cluster_names filtering silently dropped for EKSListClustersTool

extract_workload_params is now used as extract_params for all three tools including EKSListClustersTool, but it never extracts cluster_names (plural). The old _list_clusters_extract_params returned cluster_names: eks.get("cluster_names", []), which list_eks_clusters uses to filter results (if cluster_names: clusters = [c for c in clusters if c in cluster_names]). With this helper, that parameter is never populated, so the filter is always skipped and all clusters are returned regardless of any configured cluster_names in the EKS source.

extract_workload_params is correctly shared for pods and deployments, but EKSListClustersTool needs its own extractor (or the helper needs a cluster_names variant).

Comment on lines +52 to +60
def test_missing_eks_raises_error():
"""Test ValueError when 'eks' key is missing"""
sources = {"other": {}}

try:
extract_workload_params(sources)
raise AssertionError("Should have raised ValueError")
except ValueError as e:
assert "must contain an 'eks' key" in str(e)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Use pytest.raises instead of manual try/except

The manual try/except/AssertionError pattern works but is non-idiomatic pytest. Prefer pytest.raises for exception assertions.

Suggested change
def test_missing_eks_raises_error():
"""Test ValueError when 'eks' key is missing"""
sources = {"other": {}}
try:
extract_workload_params(sources)
raise AssertionError("Should have raised ValueError")
except ValueError as e:
assert "must contain an 'eks' key" in str(e)
def test_missing_eks_raises_error():
"""Test ValueError when 'eks' key is missing"""
sources = {"other": {}}
with pytest.raises(ValueError, match="must contain an 'eks' key"):
extract_workload_params(sources)

Don't forget to add import pytest at the top of the file.

Context Used: Testing conventions and patterns (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member

@VaibhavUpreti VaibhavUpreti left a comment

Choose a reason for hiding this comment

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

Great job @cokerrd !! Welcome to the OpenSRE community

@VaibhavUpreti VaibhavUpreti merged commit eb18202 into Tracer-Cloud:main Apr 29, 2026
7 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🔥 Another one. @cokerrd said "here's a PR" and maintainers said "ship it". That's how it's done.


👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome.

@cokerrd cokerrd deleted the issue/895-eks-listing-tool-refactor branch May 1, 2026 13:50
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.

2 participants