getFreshClusterStatusInternal is the shared implementation for cluster status retrieval. When enrichVMs is true, running VMs are enriched with guest agent data (slower but more complete).
(enrichVMs bool)
| 434 | // getFreshClusterStatusInternal is the shared implementation for cluster status retrieval. |
| 435 | // When enrichVMs is true, running VMs are enriched with guest agent data (slower but more complete). |
| 436 | func (c *Client) getFreshClusterStatusInternal(enrichVMs bool) (*Cluster, error) { |
| 437 | // Selectively clear cluster-level cache entries rather than the entire cache. |
| 438 | // Node-level data (disks, updates) is invalidated per-node during enrichment, |
| 439 | // so clearing everything here wastes cached data that is still valid. |
| 440 | c.ClearClusterCache() |
| 441 | |
| 442 | // Create a fresh cluster with minimal cache TTL for resources |
| 443 | cluster := &Cluster{ |
| 444 | Nodes: make([]*Node, 0), |
| 445 | StorageManager: NewStorageManager(), |
| 446 | lastUpdate: time.Now(), |
| 447 | } |
| 448 | |
| 449 | // 1. Get basic cluster status |
| 450 | if err := c.getClusterBasicStatus(cluster); err != nil { |
| 451 | return nil, err |
| 452 | } |
| 453 | |
| 454 | // 2. Get cluster resources without cache (TTL = 0) |
| 455 | if err := c.processClusterResourcesWithCache(cluster, 0); err != nil { |
| 456 | return nil, err |
| 457 | } |
| 458 | |
| 459 | // 3. Enrich VMs with detailed status information (skipped for light refresh) |
| 460 | if enrichVMs { |
| 461 | if err := c.EnrichVMs(cluster); err != nil { |
| 462 | // Log error but continue |
| 463 | c.logger.Debug("[CLUSTER] Error enriching VM data: %v", err) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // 4. Calculate cluster-wide totals |
| 468 | c.calculateClusterTotals(cluster) |
| 469 | |
| 470 | c.Cluster = cluster |
| 471 | |
| 472 | return cluster, nil |
| 473 | } |
| 474 | |
| 475 | // RefreshNodeData refreshes data for a specific node by clearing its cache entries and fetching fresh data. |
| 476 | func (c *Client) RefreshNodeData(nodeName string) (*Node, error) { |
no test coverage detected