-
Notifications
You must be signed in to change notification settings - Fork 0
Decoupled and organized formatters, updated workload handlers to use … #14
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR decouples workload formatting logic into dedicated domain-specific formatters and updates workload handlers to use the new formatter architecture. This refactoring improves code organization, maintainability, and testability by separating formatting concerns from handler logic.
- Introduces a new
formatters
package with domain-specific formatter modules for workloads, networking, storage, configuration, RBAC, and cluster resources - Updates workload handlers to use the new
WorkloadsFormatter
instead of embedded formatter methods - Adds comprehensive test coverage for the new formatter functions
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
internal/api/v1/formatters/workloads.go |
Core workloads formatter with pod, deployment, and job formatting functions |
internal/api/v1/formatters/workloads_test.go |
Comprehensive tests for workloads formatter functions |
internal/api/v1/formatters/storage.go |
Storage formatter for PVs, PVCs, and storage classes |
internal/api/v1/formatters/networking.go |
Networking formatter for services, ingresses, and endpoints |
internal/api/v1/formatters/cluster.go |
Cluster formatter for nodes, namespaces, and API resources |
internal/api/v1/formatters/config.go |
Configuration formatter for ConfigMaps and ResourceQuotas |
internal/api/v1/formatters/common.go |
Common formatting utilities shared across formatters |
internal/api/handlers_workloads.go |
Updated workload handlers to use new formatters |
internal/api/handlers_cluster.go |
Updated cluster handlers to use new formatters |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
age := "unknown" | ||
if !sc.CreationTimestamp.IsZero() { | ||
age = time.Since(sc.CreationTimestamp.Time).String() |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent age calculation method. This should use the calculateAge
function like other formatters for consistent formatting.
age := "unknown" | |
if !sc.CreationTimestamp.IsZero() { | |
age = time.Since(sc.CreationTimestamp.Time).String() | |
age = calculateAge(sc.CreationTimestamp.Time) |
Copilot uses AI. Check for mistakes.
age := "unknown" | ||
if !csi.CreationTimestamp.IsZero() { | ||
age = time.Since(csi.CreationTimestamp.Time).String() |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent age calculation method. This should use the calculateAge
function like other formatters for consistent formatting.
age := "unknown" | |
if !csi.CreationTimestamp.IsZero() { | |
age = time.Since(csi.CreationTimestamp.Time).String() | |
age = calculateAge(csi.CreationTimestamp.Time) |
Copilot uses AI. Check for mistakes.
age := "unknown" | ||
if !creationTimestamp.IsZero() { | ||
age = time.Since(creationTimestamp).String() | ||
} |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent age calculation method. This should use the calculateAge
function like other formatters for consistent formatting.
Copilot uses AI. Check for mistakes.
// CalculateAge calculates a human-readable age string from a creation time | ||
func CalculateAge(creationTime time.Time) string { |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This public function duplicates the private calculateAge
function used throughout the formatters. Either use this public version consistently or remove the duplication.
Copilot uses AI. Check for mistakes.
// Calculate age | ||
age := "unknown" | ||
if !namespace.CreationTimestamp.IsZero() { | ||
age = time.Since(namespace.CreationTimestamp.Time).String() | ||
} | ||
|
||
// Count labels and annotations | ||
labelsCount := 0 | ||
annotationsCount := 0 | ||
if namespace.Labels != nil { | ||
labelsCount = len(namespace.Labels) | ||
} | ||
if namespace.Annotations != nil { | ||
annotationsCount = len(namespace.Annotations) | ||
} | ||
|
||
return map[string]interface{}{ | ||
"name": namespace.Name, | ||
"status": string(namespace.Status.Phase), | ||
"age": age, | ||
"labelsCount": labelsCount, | ||
"annotationsCount": annotationsCount, | ||
"creationTimestamp": namespace.CreationTimestamp.Time, | ||
"labels": namespace.Labels, | ||
"annotations": namespace.Annotations, | ||
} |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FormatNamespaceSummary
function duplicates logic from the NamespaceToResponse
method but uses inconsistent age calculation. Consider removing this duplicate or making it consistent.
// Calculate age | |
age := "unknown" | |
if !namespace.CreationTimestamp.IsZero() { | |
age = time.Since(namespace.CreationTimestamp.Time).String() | |
} | |
// Count labels and annotations | |
labelsCount := 0 | |
annotationsCount := 0 | |
if namespace.Labels != nil { | |
labelsCount = len(namespace.Labels) | |
} | |
if namespace.Annotations != nil { | |
annotationsCount = len(namespace.Annotations) | |
} | |
return map[string]interface{}{ | |
"name": namespace.Name, | |
"status": string(namespace.Status.Phase), | |
"age": age, | |
"labelsCount": labelsCount, | |
"annotationsCount": annotationsCount, | |
"creationTimestamp": namespace.CreationTimestamp.Time, | |
"labels": namespace.Labels, | |
"annotations": namespace.Annotations, | |
} | |
formatter := NewClusterFormatter() | |
return formatter.NamespaceToResponse(namespace) |
Copilot uses AI. Check for mistakes.
…them