node.go 2.5 KB

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