Skip to content

refactor(gcpcommon,caik8s): extract shared CAI task library to gcpcommon and refactor caik8s - #1011

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-zppyovoyuytx
Sep 16, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-zppyovoyuytx

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

This PR extracts a shared Cloud Asset Inventory (CAI) task definition library layer into pkg/task/inspection/googlecloud/gcpcommon and refactors the Kubernetes cluster resources (k8s.io/*, apps.k8s.io/*) and GKE cluster/nodepool resources (container.googleapis.com/Cluster, NodePool) pipelines in pkg/task/inspection/googlecloud/caik8s onto the shared layer.

Key Changes

  • Shared CAI Task Library (gcpcommon):
    • Introduced CAITaskSuite, CAIFetcher, CAITimelineStagingStore, and generic CAI body extraction helpers (cai_types.go, cai_fetcher.go, cai_extractor.go, cai_timeline_staging.go, cai_task_suite.go).
    • Standardized active asset state extraction, log ingestion, timeline staging, and batch history fetching across CAI resource types.
  • K8s & GKE CAI Refactoring (caik8s & caik8s/impl):
    • Refactored K8s cluster resource and GKE resource suites onto gcpcommon.CAITaskSuite without retaining legacy shims, wrappers, or dead code.
    • Unified task IDs under ClusterResourceTaskIDs and GKEResourceTaskIDs.
    • Separated and hardened GKE resource identity validation (identity_gke_resource.go), enforcing non-empty cluster names on node pool identities.
  • Test Coverage:
    • Added comprehensive table-driven unit tests across gcpcommon and caik8s/impl covering suite registration, active asset extraction, log ingestion, timeline mapping, error handling, and identity parsing.
@kyasbal kyasbal added area:backend-core Core backend frameworks, DAG task runner, and server API area:backend-parser Log parsers and log timeline mapper tasks type:refactor Code refactoring without behavioral change labels Sep 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors the Cloud Asset Inventory (CAI) pipeline by consolidating common fetching, log conversion, grouping, ingesting, and timeline mapping logic into a generic CAITaskSuite under gcpcommon. Specific implementations for Kubernetes cluster resources and GKE resources in caik8s are updated to use this new generic suite, significantly reducing code duplication. The review feedback correctly suggests retrieving the APIClientCallOptionsInjectorTaskID dependency using coretask.GetTaskResultOptional instead of coretask.GetTaskResult in cai_task_suite.go to maintain backwards-compatibility with lightweight unit test fixtures that do not mock the injector.

…mon and refactor caik8s

Extract a shared Cloud Asset Inventory (CAI) task definition library layer into pkg/task/inspection/googlecloud/gcpcommon to consolidate duplicated pipeline code between Kubernetes cluster resources (k8s.io/*, apps.k8s.io/*) and GKE cluster/nodepool resources (container.googleapis.com/Cluster, NodePool):

- Introduce CAITaskSuite, CAIFetcher, CAITimelineStagingStore, and generic CAI body extraction helpers in gcpcommon.
- Refactor caik8s and caik8s/impl onto gcpcommon without backward compatibility shims or dead wrappers.
- Unify resource identity helpers and task IDs (ClusterResourceTaskIDs, GKEResourceTaskIDs).
- Enforce GKE cluster name validation on node pool identities and expand table-driven unit tests across gcpcommon and caik8s.
@kyasbal
kyasbal added this pull request to the merge queue Sep 16, 2026
Merged via the queue into GoogleCloudPlatform:main with commit 06fb618 Sep 16, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-zppyovoyuytx branch September 16, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API area:backend-parser Log parsers and log timeline mapper tasks type:refactor Code refactoring without behavioral change

1 participant