forked from TrueCloudLab/frostfs-sdk-go
[#162] netmap: Allow to parse single unnamed selectors
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
0a0b590df3
commit
ac8fc6d440
5 changed files with 63 additions and 8 deletions
|
@ -852,6 +852,7 @@ func (p *policyVisitor) VisitExpr(ctx *parser.ExprContext) any {
|
|||
// validatePolicy checks high-level constraints such as filter link in SELECT
|
||||
// being actually defined in FILTER section.
|
||||
func validatePolicy(p PlacementPolicy) error {
|
||||
canOmitNames := len(p.selectors) == 1 && len(p.replicas) == 1
|
||||
seenFilters := map[string]bool{}
|
||||
expectedFilters := map[string]struct{}{}
|
||||
for i := range p.filters {
|
||||
|
@ -865,7 +866,7 @@ func validatePolicy(p PlacementPolicy) error {
|
|||
|
||||
seenSelectors := map[string]*netmap.Selector{}
|
||||
for i := range p.selectors {
|
||||
if p.selectors[i].GetName() == "" {
|
||||
if p.selectors[i].GetName() == "" && !canOmitNames {
|
||||
return errUnnamedSelector
|
||||
}
|
||||
if flt := p.selectors[i].GetFilter(); flt != mainFilterName {
|
||||
|
@ -886,7 +887,7 @@ func validatePolicy(p PlacementPolicy) error {
|
|||
expectedSelectors := map[string]struct{}{}
|
||||
for i := range p.replicas {
|
||||
selName := p.replicas[i].GetSelector()
|
||||
if selName != "" {
|
||||
if selName != "" || canOmitNames {
|
||||
expectedSelectors[selName] = struct{}{}
|
||||
if seenSelectors[selName] == nil {
|
||||
return fmt.Errorf("%w: '%s'", errUnknownSelector, selName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue