Skip to content

feat(tools/k8s-discovery): complete resource discovery coverage, multi-container workload preservation, and generic cluster support - #2288

Open
utkarsh-devops wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
utkarsh-devops:main
Open

utkarsh-devops wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
utkarsh-devops:main

Conversation

@utkarsh-devops

Copy link
Copy Markdown
Contributor

PR Title

feat(tools/k8s-discovery): complete resource discovery coverage, multi-container workload preservation, and generic cluster support


PR Description

Summary of Changes

This Pull Request enhances tools/k8s-discovery to eliminate data truncation, expand Kubernetes resource inventory coverage, and add generic cluster support across AWS EKS, Azure AKS, Google GKE, and local/on-premise environments.

Key Enhancements:

  1. Expanded Resource Inventory (k8s_resources.py):

    • StorageClasses: Added get_storageclass_details() to collect provisioners, reclaim policies, volume binding modes, expansion flags, parameters, and annotations.
    • Cluster-Wide RBAC: Added get_cluster_role_details() and get_cluster_role_binding_details() for cluster-scoped access review.
    • CRDs & Custom Resources: Added get_crd_details() and get_custom_resource_details() to automatically inspect installed CRDs (e.g., Karpenter, cert-manager, Istio, AWS LB Controller) and list custom resource instances.
    • Identity & Annotations: Preserved metadata.annotations on ServiceAccounts (enabling EKS IRSA eks.amazonaws.com/role-arn tracking), Services (AWS Load Balancer controller annotations), Namespaces, and RBAC roles.
    • Workload & Security Contexts: Extracted container privileged flags, pod service_account_name, host_network, and owner_references.
    • Persistent Volumes: Extracted volume_handle, ebs_volume_id, csi_driver, volume_mode, and node_affinity.
  2. Data Preservation & Relational CSV Export (common.py):

    • Multi-Container Workload Flattening: Refactored _flatten_workloads() to iterate over 100% of workload containers, preventing multi-container pod specs from being truncated.
    • DaemonSet Replicas: Extracted desired_scheduled / current_scheduled metrics when standard replicas count is unpopulated.
    • Header Retention for Empty CSVs: Implemented DEFAULT_CSV_HEADERS mapping to ensure all 26 CSV exports write complete header rows even when resource counts are zero.
  3. Cloud & Generic Cluster Enhancements (eks_discovery.py, generic_discovery.py, main.py):

    • EKS Managed Add-ons: Added _get_addons() to inspect EKS add-ons, versions, health status, and IAM roles.
    • Generic K8s Support: Enabled standard kubeconfig scanning via python main.py generic for MicroK8s, Minikube, K3s, Rancher, and on-prem clusters.
  4. Testing & Documentation (test_k8s_discovery.py, README.md):

    • Added unit tests verifying multi-container preservation, DaemonSet replica handling, IRSA annotation output, and deterministic empty-file CSV header generation.
    • Updated README.md with complete documentation for all 26 CSV export files, setup prerequisites, and CLI sub-commands (aws, azure, gke, generic).

Verification & Testing

  • Syntax & Compilation: Verified code syntax and AST parsing (python3 -m py_compile).
  • Unit Tests: Executed unit test suite covering container flattening and CSV exporter logic:
    python3 test_k8s_discovery.py
    Output:
    SUCCESS: test_flatten_workloads_multi_container passed!
    SUCCESS: test_save_to_csvs_and_empty_headers passed!
    

PR Checklist

  • PR is not a duplicate.
  • Code conforms to Google Python Style Guide.
  • Unit tests added and passing cleanly.
  • Accompanying README.md updated with full usage instructions and output schema tables.
  • License headers and files verified in accordance with repository standards.

Updated k8s_resources.py for k8s-discovery
Updated common.py for k8s-discovery
Updated eks_discovery.py for k8s-discovery
Update generic_discovery.py for k8s-discovery
Update main.py for k8s-discovery
Update README.md for k8s-discovery
@pull-request-size pull-request-size Bot added the size/XXL Denotes a PR that changes 1000+ lines. label Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 1000+ lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant