Skip to content

Commit

Permalink
feat: new fields with singular name.
Browse files Browse the repository at this point in the history
Deprecate plural forms
  • Loading branch information
adityathebe committed Jan 3, 2025
1 parent aea3534 commit 23fcde9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
14 changes: 7 additions & 7 deletions query/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ func SetResourceSelectorClause(ctx context.Context, resourceSelector types.Resou
query = query.Where("namespace = ?", resourceSelector.Namespace)
}
}
if len(resourceSelector.Types) != 0 {
query = query.Where("type IN ?", resourceSelector.Types)
if types := resourceSelector.GetTypes(); len(types) != 0 {
query = query.Where("type IN ?", types)
}
if len(resourceSelector.Statuses) != 0 {
query = query.Where("status IN ?", resourceSelector.Statuses)
if statuses := resourceSelector.GetStatuses(); len(statuses) != 0 {
query = query.Where("status IN ?", statuses)
}
if len(resourceSelector.Healths) != 0 {
if healths := resourceSelector.GetHealths(); len(healths) != 0 {
switch table {
case "checks":
query = query.Where("status IN ?", resourceSelector.Healths)
query = query.Where("status IN ?", healths)
default:
query = query.Where("health IN ?", resourceSelector.Healths)
query = query.Where("health IN ?", healths)
}
}

Expand Down
45 changes: 45 additions & 0 deletions types/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,61 @@ type ResourceSelector struct {
LabelSelector string `json:"labelSelector,omitempty" yaml:"labelSelector,omitempty"`
FieldSelector string `json:"fieldSelector,omitempty" yaml:"fieldSelector,omitempty"`

// Type filters resources by the type.
// Multiple types can be provided separated by comma.
Type string `json:"type,omitempty"`

// Status filters resources by the status.
// Multiple statuses can be provided separated by comma.
Status string `json:"status,omitempty"`

// Health filters resources by the health.
// Multiple healths can be provided separated by comma.
Health string `json:"health,omitempty"`

// Types filter resources by the type
// Deprecated: Use Type
Types Items `yaml:"types,omitempty" json:"types,omitempty"`

// Statuses filter resources by the status
// Deprecated: Use Status
Statuses Items `yaml:"statuses,omitempty" json:"statuses,omitempty"`

// Healths filter resources by the health
// Deprecated: Use Health
Healths Items `yaml:"healths,omitempty" json:"healths,omitempty"`
}

func (t *ResourceSelector) GetTypes() Items {
types := make([]string, len(t.Types))
copy(types, t.Types)
if t.Type != "" {
types = append(types, strings.Split(t.Type, ",")...)
}

return types
}

func (t *ResourceSelector) GetHealths() Items {
result := make([]string, len(t.Healths))
copy(result, t.Healths)
if t.Health != "" {
result = append(result, strings.Split(t.Health, ",")...)
}

return result
}

func (t *ResourceSelector) GetStatuses() Items {
result := make([]string, len(t.Statuses))
copy(result, t.Statuses)
if t.Status != "" {
result = append(result, strings.Split(t.Status, ",")...)
}

return result
}

// ParseFilteringQuery parses a filtering query string.
// It returns four slices: 'in', 'notIN', 'prefix', and 'suffix'.
func ParseFilteringQuery(query string, decodeURL bool) (in []interface{}, notIN []interface{}, prefix, suffix []string, err error) {
Expand Down

0 comments on commit 23fcde9

Please sign in to comment.