filter.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package helm
  2. import (
  3. "helm.sh/helm/v3/pkg/action"
  4. )
  5. // ListFilter is a struct that represents the various filter options used for
  6. // retrieving the releases
  7. type ListFilter struct {
  8. Namespace string `json:"namespace"`
  9. Limit int `json:"limit"`
  10. Skip int `json:"skip"`
  11. ByDate bool `json:"byDate"`
  12. StatusFilter []string `json:"statusFilter"`
  13. }
  14. // listStatesFromNames accepts the following list of names:
  15. //
  16. // "deployed", "uninstalled", "uninstalling", "pending-install", "pending-upgrade",
  17. // "pending-rollback", "superseded", "failed"
  18. //
  19. // It returns an action.ListStates to be used in an action.List as filters for
  20. // releases in a certain state.
  21. func (h *ListFilter) listStatesFromNames() action.ListStates {
  22. var res action.ListStates = 0
  23. for _, name := range h.StatusFilter {
  24. res = res | res.FromName(name)
  25. }
  26. return res
  27. }
  28. // apply sets the ListFilter options for an action.List
  29. func (h *ListFilter) apply(list *action.List) {
  30. if h.Namespace == "" {
  31. list.AllNamespaces = true
  32. }
  33. list.Limit = h.Limit
  34. list.Offset = h.Skip
  35. list.StateMask = h.listStatesFromNames()
  36. if h.ByDate {
  37. list.ByDate = true
  38. }
  39. }