Skip to content

Commit

Permalink
Allow no nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jan 10, 2021
1 parent 49050e0 commit c439d80
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
24 changes: 18 additions & 6 deletions config/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,36 @@ func (cfg *Config) buildComponents() error {
func (cfg *Config) buildClusters() error {
for _, n := range cfg.Nodes {
for _, c := range n.rawClusters {
cluster, err := cfg.parseClusterLabel(c)
cluster, err := cfg.parseAndCollectCluster(c)
if err != nil {
return err
}
cluster.Nodes = append(cluster.Nodes, n)
n.Clusters = append(n.Clusters, cluster)
}
}
for _, rel := range cfg.rawRelations {
for _, r := range rel.Components {
if sepCount(r) != 2 {
continue
}
splited := sepSplit(r)
clusterId := sepJoin(splited[:2])
if _, err := cfg.parseAndCollectCluster(clusterId); err != nil {
return err
}
}
}
return nil
}

func (cfg *Config) parseClusterLabel(label string) (*Cluster, error) {
if !strings.Contains(label, Sep) {
return nil, fmt.Errorf("invalid cluster id: %s", label)
func (cfg *Config) parseAndCollectCluster(clusterId string) (*Cluster, error) {
if !sepContains(clusterId) {
return nil, fmt.Errorf("invalid cluster id: %s", clusterId)
}
splitted := sepSplit(label)
splitted := sepSplit(clusterId)
if len(splitted) != 2 {
return nil, fmt.Errorf("invalid cluster id: %s", label)
return nil, fmt.Errorf("invalid cluster id: %s", clusterId)
}
layerStr := splitted[0]
name := splitted[1]
Expand Down
13 changes: 13 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ func TestLoadConfigAndRealNodes(t *testing.T) {
wantNEdgeLen: 6,
wantLabelLen: 1,
},
{
desc: "No nodes",
configFile: "6_ndiag.yml",
nodeListFiles: []string{},
wantNodeLen: 0,
wantRealNodeLen: 0,
wantClusterLen: 1,
wantGlobalComponentLen: 1,
wantClusterComponentLen: 1,
wantNodeComponentLen: 0,
wantNEdgeLen: 1,
wantLabelLen: 0,
},
}
for i, tt := range tests {
func() {
Expand Down
6 changes: 6 additions & 0 deletions testdata/6_ndiag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
networks:
-
route:
- "internet"
- "group:lb:vip"

0 comments on commit c439d80

Please sign in to comment.