Skip to content

[High] kubernetes.go repetitive CRUD (1,631 lines) needs generic helper #973

@piwi3910

Description

@piwi3910

Codebase Review Round 2 — Finding #12

Severity: High
Location: kubernetes.go (1,631 lines)

Problem

The Kubernetes client code implements 5 CRUD methods (Create, Get, Update, Delete, List) for each of 10 CRD types, following an identical pattern each time. This results in ~1,600 lines of nearly identical boilerplate code.

Impact

  • Any change to error handling, logging, or retry logic must be replicated across 50 methods
  • High risk of inconsistency (some methods may have fixes that others missed)
  • New CRD types require copying and modifying 5 methods

Fix

  • Extract a generic crudResource[T] helper using Go generics
  • Each CRD type registers once with the generic helper
  • Reduces ~1,600 lines to ~200 lines + type registrations
  • Example pattern:
    func crudResource[T runtime.Object](ctx context.Context, client dynamic.Interface, gvr schema.GroupVersionResource, ...) error

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureArchitecture and design issuescodebase-reviewFrom codebase reviewtech-debtTechnical debt and code quality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions