Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for creating stand-alone dc filter #4061

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions v3/pkg/util/inexlist/dcfilter/dcfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ func Apply(dcMap map[string][]string, filters []string) ([]string, error) {
return filtered, nil
}

// Filter that lets you filter datacenters.
type Filter struct {
filters []string
inex inexlist.InExList
}

func NewFilter(filters []string) (*Filter, error) {
// Decorate filters and create inexlist
inex, err := inexlist.ParseInExList(decorate(filters))
if err != nil {
return nil, errors.Wrapf(err, "parse dc filter %v", filters)
}
return &Filter{
filters: filters,
inex: inex,
}, nil
}

// Check returns true iff dc matches filter.
func (f *Filter) Check(dc string) bool {
return len(f.inex.Filter([]string{dc})) > 0
}

func decorate(filters []string) []string {
if len(filters) == 0 {
filters = append(filters, "*")
Expand Down
Loading