Skip to content

Commit

Permalink
[YUNIKORN-697]: Enforce partition name uniqueness in core (apache#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
manirajv06 committed Sep 13, 2021
1 parent 66cdb3d commit ab6fa20
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
28 changes: 28 additions & 0 deletions pkg/common/configs/config_test.go
Expand Up @@ -413,12 +413,40 @@ partitions:
queues:
- name: root
- name: default
queues:
- name: root
- name: part1
queues:
- name: root
`
// validate the config and check after the update
conf, err = CreateConfig(data)
assert.Error(t, err, "duplicate partition name found with name default")
if err == nil {
t.Errorf("multiple default partitions parsing should have failed: %v", conf)
}

data = `
partitions:
- name: default
queues:
- name: root
- name: part1
queues:
- name: root
- name: part1
queues:
- name: root
- name: part2
queues:
- name: root
`
// validate the config and check after the update
conf, err = CreateConfig(data)
assert.Error(t, err, "duplicate partition name found with name part1")
if err == nil {
t.Errorf("duplicate partitions parsing should have failed: %v", conf)
}
}

func TestParseQueue(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/common/configs/configvalidator.go
Expand Up @@ -372,16 +372,16 @@ func Validate(newConfig *SchedulerConfig) error {
return fmt.Errorf("scheduler config is not set")
}

// check for the default partition, if the partion is unnamed set it to default
var defaultPartition bool
// check uniqueness
partitionMap := make(map[string]bool)
for i, partition := range newConfig.Partitions {
if partition.Name == "" || strings.ToLower(partition.Name) == DefaultPartition {
if defaultPartition {
return fmt.Errorf("multiple default partitions defined")
}
defaultPartition = true
partition.Name = DefaultPartition
}
if partitionMap[strings.ToLower(partition.Name)] {
return fmt.Errorf("duplicate partition name found with name %s", partition.Name)
}
partitionMap[strings.ToLower(partition.Name)] = true
// check the queue structure
err := checkQueuesStructure(&partition)
if err != nil {
Expand Down

0 comments on commit ab6fa20

Please sign in to comment.