node.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package kubemodel
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type Node struct {
  7. UID string `json:"uid"`
  8. ClusterUID string `json:"clusterUid"`
  9. ProviderResourceUID string `json:"providerResourceUid"`
  10. Name string `json:"name"`
  11. Labels map[string]string `json:"labels,omitempty"`
  12. Annotations map[string]string `json:"annotations,omitempty"`
  13. Start time.Time `json:"start"`
  14. End time.Time `json:"end"`
  15. CpuMillicoreSecondsAllocated uint64 `json:"cpuMillicoreSecondsAllocated"`
  16. RAMByteSecondsAllocated uint64 `json:"ramByteSecondsAllocated"`
  17. // PublicIPSeconds represents the cumulative public IP allocation (count × seconds) for this node.
  18. // Calculated as: number of ExternalIP addresses from Kubernetes node Status.Addresses × window duration in seconds.
  19. // Used for cost attribution of public IP addresses associated with the node.
  20. PublicIPSecondsAllocated uint64 `json:"publicIpSecondsAllocated"`
  21. CpuMillicoreUsageAverage uint64 `json:"cpuMillicoreUsageAverage"`
  22. CpuMillicoreUsageMax uint64 `json:"cpuMillicoreUsageMax"`
  23. RAMByteUsageAverage uint64 `json:"ramByteUsageAverage"`
  24. RAMByteUsageMax uint64 `json:"ramByteUsageMax"`
  25. }
  26. func (kms *KubeModelSet) RegisterNode(uid, name string) error {
  27. if uid == "" {
  28. err := fmt.Errorf("UID is nil for Node '%s'", name)
  29. kms.Error(err)
  30. return err
  31. }
  32. if _, ok := kms.Nodes[uid]; !ok {
  33. clusterUID := ""
  34. if kms.Cluster == nil {
  35. kms.Warnf("RegisterNode(%s, %s): Cluster is nil", uid, name)
  36. } else {
  37. clusterUID = kms.Cluster.UID
  38. }
  39. kms.Nodes[uid] = &Node{
  40. UID: uid,
  41. ClusterUID: clusterUID,
  42. Name: name,
  43. }
  44. kms.Metadata.ObjectCount++
  45. }
  46. return nil
  47. }