Skip to content

Fix undefined variable error in Quotas component#68

Merged
JoshuaAFerguson merged 10 commits into
mainfrom
claude/fix-quotas-undefined-error-01B8LUMPnqJXSuXb6qryZLAr
Nov 17, 2025
Merged

Fix undefined variable error in Quotas component#68
JoshuaAFerguson merged 10 commits into
mainfrom
claude/fix-quotas-undefined-error-01B8LUMPnqJXSuXb6qryZLAr

Conversation

@JoshuaAFerguson

Copy link
Copy Markdown
Member

No description provided.

- Add defensive checks to ensure quotas array is never undefined
- Use optional chaining (?.) and nullish coalescing (??) for all quota properties
- Set empty array as fallback when API returns undefined or on error
- Apply same defensive pattern as QuotaCard component
- Prevents "TypeError: can't access property 'length', k is undefined" error

Fixes error occurring at Quotas.tsx:322 when API returns undefined data.
- Add defensive checks to ensure templates array is never undefined
- Use optional chaining (?.) for template property access
- Set empty array as fallback when API returns undefined or on error
- Add fallback values for totalPages to prevent undefined errors
- Apply same defensive pattern as other components

Fixes error occurring at EnhancedCatalog.tsx:308 when API returns undefined data.
- Add defensive error handling for 404 responses from node APIs
- Return empty arrays/null when API endpoints not implemented
- Ensure nodes array is never undefined to prevent crashes
- Handle Promise.all rejections individually with .catch()

The node management APIs (/admin/nodes, /admin/nodes/stats) haven't been
implemented in the backend yet. This fix allows the UI to load without
errors while those endpoints are being developed.
Add comprehensive node management API for cluster administrators with
full CRUD operations for node labels, taints, and scheduling.

Backend Implementation:
- Create NodeHandler with 10 admin-only endpoints
- List all nodes with detailed status and resource info
- Get cluster-wide statistics (ready/not ready nodes, aggregate capacity)
- Add/remove node labels for pod scheduling affinity
- Add/remove node taints for workload isolation
- Cordon/uncordon nodes to control scheduling
- Drain nodes with graceful pod eviction

K8s Client Extensions:
- Add GetNode() for fetching individual node details
- Add PatchNode() for strategic merge patches
- Add UpdateNodeTaints() for taint management
- Add CordonNode()/UncordonNode() for scheduling control
- Add DrainNode() with graceful pod eviction and DaemonSet filtering

API Routes (all require admin role):
- GET    /admin/nodes - List all cluster nodes
- GET    /admin/nodes/stats - Get aggregate cluster statistics
- GET    /admin/nodes/:name - Get specific node details
- PUT    /admin/nodes/:name/labels - Add node label
- DELETE /admin/nodes/:name/labels/:key - Remove node label
- POST   /admin/nodes/:name/taints - Add node taint
- DELETE /admin/nodes/:name/taints/:key - Remove node taint
- POST   /admin/nodes/:name/cordon - Mark node unschedulable
- POST   /admin/nodes/:name/uncordon - Mark node schedulable
- POST   /admin/nodes/:name/drain - Evict all pods from node

Features:
- Admin-only authentication required for all operations
- Comprehensive node metadata (OS, kernel, kubelet version, runtime)
- Cloud provider info extraction (region, zone, instance type)
- Safe pod eviction during drain (skips DaemonSets and static pods)
- Configurable grace period for pod eviction
- Detailed error handling and validation

Related UI fix:
- Fix 404 errors in AdminNodes page by providing graceful fallbacks
- UI will now load without errors even before backend deployment

Fixes #AdminNodes 404 errors in UI
- Add defensive error handling for 404 responses from compliance APIs
- Ensure frameworks, policies, and violations arrays are never undefined
- Set default metrics object when API fails
- Fix typo: loadMetrics() → loadDashboard()
- Return empty arrays/default objects when endpoints not implemented

The compliance APIs (/compliance/frameworks, /compliance/policies,
/compliance/violations, /compliance/dashboard) are handled by the
streamspace-compliance plugin. This fix allows the UI to load without
errors when the plugin is not installed.

Fixes compliance 404 errors in admin UI
- Add defensive checks for all data loading functions
- Ensure lbPolicies, nodes, asPolicies, and scalingHistory are never undefined
- Set empty arrays as fallback when API returns undefined or on error
- Apply same defensive pattern as other admin pages

Fixes error at Scaling.tsx:427 when trying to access nodes.length
on undefined value.

Related APIs:
- /scaling/load-balancing/policies
- /scaling/load-balancing/nodes
- /scaling/autoscaling/policies
- /scaling/autoscaling/history
- Add defensive checks for loadWebhooks() and loadIntegrations()
- Ensure webhooks and integrations arrays are never undefined
- Set empty arrays as fallback when API returns undefined or on error
- Apply same defensive pattern as other admin pages

Fixes error at Integrations.tsx:374 when trying to access webhooks.length
on undefined value.

Related APIs:
- /integrations/webhooks
- /integrations/external
- Add defensive check in loadPlugins() to ensure array is never undefined
- Add optional chaining to stats calculation for extra safety
- Set empty array as fallback when API returns undefined or on error
- Apply same defensive pattern as other admin pages

Fixes error at Plugins.tsx:263 when trying to access plugins.length
on undefined value.

Related API:
- /plugins/installed
…shboard error handling

- Fixed AdminDashboard.tsx error handling bug where setError was called but error is not a state variable
- Added defensive checks in AdminDashboard.tsx to handle undefined or incorrect metrics data structure
- Implemented proper GetMetrics API handler that returns cluster metrics (nodes, sessions, resources, users)
- GetMetrics now queries Kubernetes for node status and resource allocation
- GetMetrics queries database for session counts (running, hibernated, terminated) and user counts (total, active)
- Added fmt import to stubs.go for proper int64 to string conversion
- Resource usage estimation based on running session counts (1000m CPU, 2GiB memory per session)

This fixes the "Failed to load Metrics" error on /admin/dashboard that was caused by GetMetrics
returning connection tracker stats instead of the expected cluster metrics structure.

Related to: undefined array error fixes across admin pages
- Added Users menu item to admin navigation (/admin/users)
- Added Groups menu item to admin navigation (/admin/groups)
- Imported Groups icon from Material-UI
- Menu items positioned after Admin Dashboard for easy access
- Routes already exist in App.tsx, pages are implemented and working
- Both Users.tsx and Groups.tsx already have defensive error handling

This fixes the issue where user and group management pages existed but were not accessible
from the navigation menu, requiring manual URL entry to access.

Related to: admin page navigation improvements
@JoshuaAFerguson JoshuaAFerguson merged commit 89cf6ec into main Nov 17, 2025
9 of 23 checks passed
@JoshuaAFerguson JoshuaAFerguson deleted the claude/fix-quotas-undefined-error-01B8LUMPnqJXSuXb6qryZLAr branch November 18, 2025 00:11
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.

2 participants