Skip to content

Commit

Permalink
Add custom field in global options (#1098)
Browse files Browse the repository at this point in the history
* Add custom field in global options

Fix #571

* Add test

Co-authored-by: Allen Zhong <zhongbenli@pingcap.com>
Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 2, 2021
1 parent 4d93059 commit 5876ac3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type (
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"`
OS string `yaml:"os,omitempty" default:"linux"`
Arch string `yaml:"arch,omitempty" default:"amd64"`
Custom interface{} `yaml:"custom,omitempty" validate:"custom:ignore"`
}

// MonitoredOptions represents the monitored node configuration
Expand Down
39 changes: 39 additions & 0 deletions pkg/cluster/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package spec

import (
"bytes"
"strings"
"testing"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -682,3 +683,41 @@ tiflash_servers:
c.Check(err, NotNil)
}
}

func (s *metaSuiteTopo) TestYAMLAnchor(c *C) {
topo := Specification{}
err := yaml.UnmarshalStrict([]byte(`
global:
custom:
tidb_spec: &tidb_spec
deploy_dir: "test-deploy"
log_dir: "test-deploy/log"
tidb_servers:
- <<: *tidb_spec
host: 172.16.5.138
deploy_dir: "fake-deploy"
`), &topo)
c.Assert(err, IsNil)
c.Assert(topo.TiDBServers[0].Host, Equals, "172.16.5.138")
c.Assert(topo.TiDBServers[0].DeployDir, Equals, "fake-deploy")
c.Assert(topo.TiDBServers[0].LogDir, Equals, "test-deploy/log")
}

func (s *metaSuiteTopo) TestYAMLAnchorWithUndeclared(c *C) {
topo := Specification{}
err := yaml.UnmarshalStrict([]byte(`
global:
custom:
tidb_spec: &tidb_spec
deploy_dir: "test-deploy"
log_dir: "test-deploy/log"
undeclared: "some stuff"
tidb_servers:
- <<: *tidb_spec
host: 172.16.5.138
`), &topo)
c.Assert(err, NotNil)
c.Assert(strings.Contains(err.Error(), "not found"), IsTrue)
}

0 comments on commit 5876ac3

Please sign in to comment.