Skip to content

Commit

Permalink
cluster/spec: tag editable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed Jul 20, 2020
1 parent 55cd70e commit ec7f801
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 73 deletions.
122 changes: 118 additions & 4 deletions pkg/cluster/edit/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ type sampleDataMeta struct {
}

type sampleDataElem struct {
StrElem1 string `yaml:"str1" validate:"editable"`
StrElem2 string `yaml:"str2,omitempty" validate:"editable"`
IntElem int `yaml:"int"`
InterfaceElem interface{} `yaml:"interface,omitempty" validate:"editable"`
StrElem1 string `yaml:"str1" validate:"editable"`
StrElem2 string `yaml:"str2,omitempty" validate:"editable"`
IntElem int `yaml:"int"`
InterfaceElem interface{} `yaml:"interface,omitempty" validate:"editable"`
InterfaceSlice []map[string]interface{} `yaml:"mapslice,omitempty" validate:"editable"`
}

type sampleDataEditable struct {
Expand Down Expand Up @@ -314,3 +315,116 @@ slice3:
err = ValidateSpecDiff(d1, d2)
c.Assert(err, IsNil)
}

func (d *diffSuite) TestValidateSpecDiff5(c *C) {
var d1 sampleDataMeta
var d2 sampleDataMeta
var err error

err = yaml.Unmarshal([]byte(`
ints: [11, 12, 13]
slice1:
- str1: strv11
str2: strv21
interslice:
- key0: 0
- str1: strv12
str2: strv22
slice2:
- str1: strv13
str2: strv14
interslice:
- key0: 0
`), &d1)
c.Assert(err, IsNil)

// Modify item of editable slice in item of editable slice
err = yaml.Unmarshal([]byte(`
ints: [11, 12, 13]
slice1:
- str1: strv11
str2: strv21
interslice:
- key0: 0.1
- str1: strv12
str2: strv22
interslice:
- key1: 1
- key2: "v2"
slice2:
- str1: strv13
str2: strv14
interslice:
- key0: 0
`), &d2)
c.Assert(err, IsNil)
err = ValidateSpecDiff(d1, d2)
c.Assert(err, IsNil)

// Modify item of editable slice in item of editable slice
err = yaml.Unmarshal([]byte(`
ints: [11, 12, 13]
slice1:
- str1: strv11
str2: strv21
interslice:
- key0: 0
- str1: strv12
str2: strv22
interslice:
- key1: 1
- key2: "v2"
slice2:
- str1: strv13
str2: strv14
interslice:
- key0: 0.2
`), &d2)
c.Assert(err, IsNil)
err = ValidateSpecDiff(d1, d2)
c.Assert(err, IsNil)

// Add item to editable slice to item of editable slice
err = yaml.Unmarshal([]byte(`
ints: [11, 12, 13]
slice1:
- str1: strv11
str2: strv21
interslice:
- key0: 0
- str1: strv12
str2: strv22
interslice:
- key1: 1
- key2: "v2"
slice2:
- str1: strv13
str2: strv14
interslice:
- key0: 0
`), &d2)
c.Assert(err, IsNil)
err = ValidateSpecDiff(d1, d2)
c.Assert(err, IsNil)

// Add item to editable slice to item of immutable slice
err = yaml.Unmarshal([]byte(`
ints: [11, 12, 13]
slice1:
- str1: strv11
str2: strv21
interslice:
- key0: 0
- str1: strv12
str2: strv22
slice2:
- str1: strv13
str2: strv14
interslice:
- key0: 0
- key3: 3.0
`), &d2)
c.Assert(err, IsNil)
err = ValidateSpecDiff(d1, d2)
c.Assert(err, IsNil)
}
6 changes: 3 additions & 3 deletions pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (
// AlertManagerSpec represents the AlertManager topology specification in topology.yaml
type AlertManagerSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
WebPort int `yaml:"web_port" default:"9093"`
ClusterPort int `yaml:"cluster_port" default:"9094"`
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
// CDCSpec represents the Drainer topology specification in topology.yaml
type CDCSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"8300"`
DeployDir string `yaml:"deploy_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
Offline bool `yaml:"offline,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ import (
// DrainerSpec represents the Drainer topology specification in topology.yaml
type DrainerSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"8249"`
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
CommitTS int64 `yaml:"commit_ts,omitempty"`
Offline bool `yaml:"offline,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
// GrafanaSpec represents the Grafana topology specification in topology.yaml
type GrafanaSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"3000"`
DeployDir string `yaml:"deploy_dir,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type PDSpec struct {
Host string `yaml:"host"`
ListenHost string `yaml:"listen_host,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
// Use Name to get the name with a default value if it's empty.
Name string `yaml:"name"`
Expand All @@ -40,9 +40,9 @@ type PDSpec struct {
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
// PrometheusSpec represents the Prometheus Server topology specification in topology.yaml
type PrometheusSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"9090"`
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Retention string `yaml:"storage_retention,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Retention string `yaml:"storage_retention,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import (
// PumpSpec represents the Pump topology specification in topology.yaml
type PumpSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"8250"`
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
Offline bool `yaml:"offline,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type (
// specification in topology.yaml
GlobalOptions struct {
User string `yaml:"user,omitempty" default:"tidb"`
SSHPort int `yaml:"ssh_port,omitempty" default:"22"`
SSHPort int `yaml:"ssh_port,omitempty" default:"22" validate:"editable"`
DeployDir string `yaml:"deploy_dir,omitempty" default:"deploy"`
DataDir string `yaml:"data_dir,omitempty" default:"data"`
LogDir string `yaml:"log_dir,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
OS string `yaml:"os,omitempty" default:"linux"`
Arch string `yaml:"arch,omitempty" default:"amd64"`
}
Expand All @@ -72,27 +72,27 @@ type (
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
}

// ServerConfigs represents the server runtime configuration
ServerConfigs struct {
TiDB map[string]interface{} `yaml:"tidb"`
TiKV map[string]interface{} `yaml:"tikv"`
PD map[string]interface{} `yaml:"pd"`
TiFlash map[string]interface{} `yaml:"tiflash"`
TiFlashLearner map[string]interface{} `yaml:"tiflash-learner"`
Pump map[string]interface{} `yaml:"pump"`
Drainer map[string]interface{} `yaml:"drainer"`
CDC map[string]interface{} `yaml:"cdc"`
TiDB map[string]interface{} `yaml:"tidb" validate:"editable"`
TiKV map[string]interface{} `yaml:"tikv" validate:"editable"`
PD map[string]interface{} `yaml:"pd" validate:"editable"`
TiFlash map[string]interface{} `yaml:"tiflash" validate:"editable"`
TiFlashLearner map[string]interface{} `yaml:"tiflash-learner" validate:"editable"`
Pump map[string]interface{} `yaml:"pump" validate:"editable"`
Drainer map[string]interface{} `yaml:"drainer" validate:"editable"`
CDC map[string]interface{} `yaml:"cdc" validate:"editable"`
}

// Specification represents the specification of topology.yaml
Specification struct {
GlobalOptions GlobalOptions `yaml:"global,omitempty"`
MonitoredOptions MonitoredOptions `yaml:"monitored,omitempty"`
ServerConfigs ServerConfigs `yaml:"server_configs,omitempty"`
GlobalOptions GlobalOptions `yaml:"global,omitempty" validate:"editable"`
MonitoredOptions MonitoredOptions `yaml:"monitored,omitempty" validate:"editable"`
ServerConfigs ServerConfigs `yaml:"server_configs,omitempty" validate:"editable"`
TiDBServers []TiDBSpec `yaml:"tidb_servers"`
TiKVServers []TiKVSpec `yaml:"tikv_servers"`
TiFlashServers []TiFlashSpec `yaml:"tiflash_servers"`
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import (
type TiDBSpec struct {
Host string `yaml:"host"`
ListenHost string `yaml:"listen_host,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"4000"`
StatusPort int `yaml:"status_port" default:"10080"`
DeployDir string `yaml:"deploy_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cluster/spec/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// TiFlashSpec represents the TiFlash topology specification in topology.yaml
type TiFlashSpec struct {
Host string `yaml:"host"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
TCPPort int `yaml:"tcp_port" default:"9000"`
HTTPPort int `yaml:"http_port" default:"8123"`
Expand All @@ -47,10 +47,10 @@ type TiFlashSpec struct {
LogDir string `yaml:"log_dir,omitempty"`
TmpDir string `yaml:"tmp_path,omitempty"`
Offline bool `yaml:"offline,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
LearnerConfig map[string]interface{} `yaml:"learner_config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
LearnerConfig map[string]interface{} `yaml:"learner_config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/spec/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ import (
type TiKVSpec struct {
Host string `yaml:"host"`
ListenHost string `yaml:"listen_host,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty"`
SSHPort int `yaml:"ssh_port,omitempty" validate:"editable"`
Imported bool `yaml:"imported,omitempty"`
Port int `yaml:"port" default:"20160"`
StatusPort int `yaml:"status_port" default:"20180"`
DeployDir string `yaml:"deploy_dir,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
LogDir string `yaml:"log_dir,omitempty"`
Offline bool `yaml:"offline,omitempty"`
NumaNode string `yaml:"numa_node,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty"`
NumaNode string `yaml:"numa_node,omitempty" validate:"editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
Loading

0 comments on commit ec7f801

Please sign in to comment.