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

cluster: validate topo changes after edit-config #609

Merged
merged 6 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions components/cluster/command/edit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/fatih/color"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/edit"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/logger"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"
tiuputils "github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -93,7 +93,7 @@ func editTopo(clusterName string, metadata *spec.ClusterMeta) error {
return perrs.AddStack(err)
}

err = edit.OpenFileInEditor(name)
err = tiuputils.OpenFileInEditor(name)
if err != nil {
return perrs.AddStack(err)
}
Expand All @@ -116,7 +116,11 @@ func editTopo(clusterName string, metadata *spec.ClusterMeta) error {
return nil
}

edit.ShowDiff(string(data), string(newData), os.Stdout)
// report error if immutable field has been changed
if err := tiuputils.ValidateSpecDiff(metadata.Topology, newTopo); err != nil {
return err
}
tiuputils.ShowDiff(string(data), string(newData), os.Stdout)

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
Expand Down
5 changes: 2 additions & 3 deletions components/dm/command/edit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/fatih/color"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/edit"
"github.com/pingcap/tiup/pkg/cluster/meta"
"github.com/pingcap/tiup/pkg/logger"
"github.com/pingcap/tiup/pkg/logger/log"
Expand Down Expand Up @@ -87,7 +86,7 @@ func editTopo(clusterName string, metadata *meta.DMMeta) error {
return perrs.AddStack(err)
}

err = edit.OpenFileInEditor(name)
err = tiuputils.OpenFileInEditor(name)
if err != nil {
return perrs.AddStack(err)
}
Expand All @@ -110,7 +109,7 @@ func editTopo(clusterName string, metadata *meta.DMMeta) error {
return nil
}

edit.ShowDiff(string(data), string(newData), os.Stdout)
tiuputils.ShowDiff(string(data), string(newData), os.Stdout)

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/pingcap/kvproto v0.0.0-20200518112156-d4aeb467de29
github.com/pingcap/pd/v4 v4.0.0
github.com/pingcap/tidb-insight v0.3.1
github.com/r3labs/diff v0.0.0-20200627101315-aecd9dd05dd2
github.com/relex/aini v1.1.3
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44
github.com/shirou/gopsutil v2.20.3+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa
github.com/prometheus/procfs v0.0.6 h1:0qbH+Yqu/cj1ViVLvEWCP6qMQ4efWUj6bQqOEA0V0U4=
github.com/prometheus/procfs v0.0.6/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/r3labs/diff v0.0.0-20200627101315-aecd9dd05dd2 h1:786HUIrynbbk5PzUf9Rp3aAUkNRksUiiipSAlyJ68As=
github.com/r3labs/diff v0.0.0-20200627101315-aecd9dd05dd2/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6Xig=
github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/relex/aini v1.1.3 h1:xooajfI84UYB+jWdxKe2w1zXXdi89Fc+L6W4CjHb0wg=
Expand Down
31 changes: 0 additions & 31 deletions pkg/cluster/edit/diff.go

This file was deleted.

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:"ssh_port: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:"numa_node:editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Retention string `yaml:"storage_retention,omitempty" validate:"storage_retention:editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
14 changes: 7 additions & 7 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:"ssh_port: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:"resource_control:editable"`
OS string `yaml:"os,omitempty" default:"linux"`
Arch string `yaml:"arch,omitempty" default:"amd64"`
}
Expand All @@ -72,8 +72,8 @@ 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:"numa_node:editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"`
}

// ServerConfigs represents the server runtime configuration
Expand All @@ -90,9 +90,9 @@ type (

// 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:"global:editable"`
MonitoredOptions MonitoredOptions `yaml:"monitored,omitempty" validate:"monitored:editable"`
ServerConfigs ServerConfigs `yaml:"server_configs,omitempty" validate:"server_configs:ignore"`
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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
LearnerConfig map[string]interface{} `yaml:"learner_config,omitempty" validate:"learner_config:editable"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control: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:"ssh_port: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:"numa_node:editable"`
Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"`
ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"`
Arch string `yaml:"arch,omitempty"`
OS string `yaml:"os,omitempty"`
}
Expand Down
Loading