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

Add custom field in global options #1098

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an elegant way.

Copy link
Member Author

@lucklove lucklove Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you have a better idea? We must define an extra field because we use yaml.UnmarshalStrict, which will report error when user define custom field outside the Custom

}

// 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:
lucklove marked this conversation as resolved.
Show resolved Hide resolved
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)
}