Skip to content

Conversation

aaronlmathis
Copy link
Owner

…them

@Copilot Copilot AI review requested due to automatic review settings September 1, 2025 10:51
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines +196 to +198
age := "unknown"
if !sc.CreationTimestamp.IsZero() {
age = time.Since(sc.CreationTimestamp.Time).String()
Copy link

Copilot AI Sep 1, 2025

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.

Suggested change
age := "unknown"
if !sc.CreationTimestamp.IsZero() {
age = time.Since(sc.CreationTimestamp.Time).String()
age = calculateAge(sc.CreationTimestamp.Time)

Copilot uses AI. Check for mistakes.

Comment on lines +265 to +267
age := "unknown"
if !csi.CreationTimestamp.IsZero() {
age = time.Since(csi.CreationTimestamp.Time).String()
Copy link

Copilot AI Sep 1, 2025

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.

Suggested change
age := "unknown"
if !csi.CreationTimestamp.IsZero() {
age = time.Since(csi.CreationTimestamp.Time).String()
age = calculateAge(csi.CreationTimestamp.Time)

Copilot uses AI. Check for mistakes.

Comment on lines +458 to +461
age := "unknown"
if !creationTimestamp.IsZero() {
age = time.Since(creationTimestamp).String()
}
Copy link

Copilot AI Sep 1, 2025

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.

Comment on lines +11 to +12
// CalculateAge calculates a human-readable age string from a creation time
func CalculateAge(creationTime time.Time) string {
Copy link

Copilot AI Sep 1, 2025

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.

Comment on lines +267 to +292
// 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,
}
Copy link

Copilot AI Sep 1, 2025

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.

Suggested change
// 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.

@aaronlmathis aaronlmathis merged commit a8e4a2f into main Sep 1, 2025
4 checks passed
@aaronlmathis aaronlmathis deleted the refactorformatter branch September 1, 2025 10:58
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.

1 participant