pod.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package kubemodel
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type Pod struct {
  7. UID string `json:"uid"`
  8. NamespaceUID string `json:"namespaceUid"`
  9. OwnerUID string `json:"ownerUid"` // Reference to Owner (Deployment, StatefulSet, etc.)
  10. NodeUID string `json:"nodeUid"`
  11. Name string `json:"name"`
  12. Labels map[string]string `json:"labels,omitempty"`
  13. Annotations map[string]string `json:"annotations,omitempty"`
  14. DurationSeconds Measurement `json:"durationSeconds"`
  15. NetworkTransferBytes Measurement `json:"networkTransferBytes"`
  16. NetworkReceiveBytes Measurement `json:"networkReceiveBytes"`
  17. Start time.Time `json:"start,omitempty"` // Pod creation/start timestamp
  18. End time.Time `json:"end,omitempty"` // Pod deletion/end timestamp (nil if still running)
  19. }
  20. func (kms *KubeModelSet) RegisterPod(uid, name, namespace string) error {
  21. if uid == "" {
  22. err := fmt.Errorf("UID is nil for Pod '%s'", name)
  23. kms.Error(err)
  24. return err
  25. }
  26. if _, ok := kms.Pods[uid]; !ok {
  27. namespaceUID := ""
  28. if ns, ok := kms.idx.namespaceByName[namespace]; !ok {
  29. kms.Warnf("RegisterPod(%s, %s, %s): missing namespace '%s'", uid, name, namespace, namespace)
  30. } else {
  31. namespaceUID = ns.UID
  32. }
  33. kms.Pods[uid] = &Pod{
  34. UID: uid,
  35. Name: name,
  36. NamespaceUID: namespaceUID,
  37. }
  38. kms.Metadata.ObjectCount++
  39. }
  40. return nil
  41. }