Skip to content

Commit

Permalink
Merge branch 'master' into local-exec
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis authored Jan 27, 2022
2 parents bec6bbc + 44ceb86 commit 9652ee0
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 21 deletions.
16 changes: 16 additions & 0 deletions pkg/cluster/manager/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/set"
"github.com/pingcap/tiup/pkg/tui"
"github.com/pingcap/tiup/pkg/utils"
"golang.org/x/mod/semver"
)

// EnableCluster enable/disable the service in a cluster
Expand Down Expand Up @@ -281,3 +283,17 @@ func getMonitorHosts(topo spec.Topology) (map[string]hostInfo, set.StringSet) {

return uniqueHosts, noAgentHosts
}

// checkTiFlashWithTLS check tiflash vserson
func checkTiFlashWithTLS(topo spec.Topology, version string) error {
if clusterSpec, ok := topo.(*spec.Specification); ok {
if clusterSpec.GlobalOptions.TLSEnabled {
if (semver.Compare(version, "v4.0.5") < 0 &&
len(clusterSpec.TiFlashServers) > 0) &&
version != utils.NightlyVersionAlias {
return fmt.Errorf("TiFlash %s is not supported in TLS enabled cluster", version)
}
}
}
return nil
}
37 changes: 37 additions & 0 deletions pkg/cluster/manager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ func checkSystemInfo(
applyFixTasks = append(applyFixTasks, tf.BuildAsStep(fmt.Sprintf(" - Applying changes on %s", host)))
}

checkResults = deduplicateCheckResult(checkResults)

if gOpt.DisplayMode == "json" {
checkResultStruct := make([]HostCheckResult, 0)

Expand Down Expand Up @@ -689,3 +691,38 @@ func checkConflict(m *Manager, clusterName string, topo spec.Topology) error {
err = spec.CheckClusterDirConflict(clusterList, clusterName, topo)
return err
}

// deduplicateCheckResult deduplicate check results
func deduplicateCheckResult(checkResults []HostCheckResult) (uniqueResults []HostCheckResult) {
// node: {name|status: set(msg)}
tmpResultMap := map[string]map[string]set.StringSet{}

// deduplicate
for _, result := range checkResults {
if tmpResultMap[result.Node] == nil {
tmpResultMap[result.Node] = make(map[string]set.StringSet)
}
// insert msg into set
msgKey := fmt.Sprintf("%s|%s", result.Name, result.Status)
if tmpResultMap[result.Node][msgKey] == nil {
tmpResultMap[result.Node][msgKey] = set.NewStringSet()
}
tmpResultMap[result.Node][msgKey].Insert(result.Message)
}

for node, msgMap := range tmpResultMap {
for checkInfo, msgSet := range msgMap {
nameAndstatus := strings.Split(checkInfo, "|")
for _, msg := range msgSet.Slice() {
uniqueResults = append(uniqueResults,
HostCheckResult{
Node: node,
Name: nameAndstatus[0],
Status: nameAndstatus[1],
Message: msg,
})
}
}
}
return
}
10 changes: 3 additions & 7 deletions pkg/cluster/manager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/pingcap/tiup/pkg/set"
"github.com/pingcap/tiup/pkg/tui"
"github.com/pingcap/tiup/pkg/utils"
"golang.org/x/mod/semver"
)

// DeployOptions contains the options for scale out.
Expand Down Expand Up @@ -88,12 +87,9 @@ func (m *Manager) Deploy(
if err := spec.ParseTopologyYaml(topoFile, topo); err != nil {
return err
}
if clusterSpec, ok := topo.(*spec.Specification); ok {
if clusterSpec.GlobalOptions.TLSEnabled &&
semver.Compare(clusterVersion, "v4.0.5") < 0 &&
len(clusterSpec.TiFlashServers) > 0 {
return fmt.Errorf("TiFlash %s is not supported in TLS enabled cluster", clusterVersion)
}

if err := checkTiFlashWithTLS(topo, clusterVersion); err != nil {
return err
}

instCnt := 0
Expand Down
21 changes: 21 additions & 0 deletions pkg/cluster/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,24 @@ pd_servers:
err = validateNewTopo(&topo)
assert.NotNil(err)
}

func TestDeduplicateCheckResult(t *testing.T) {
checkResults := []HostCheckResult{}

for i := 0; i <= 10; i++ {
checkResults = append(checkResults,
HostCheckResult{
Node: "127.0.0.1",
Status: "Warn",
Name: "disk",
Message: "mount point /home does not have 'noatime' option set",
},
)
}

checkResults = deduplicateCheckResult(checkResults)

if len(checkResults) != 1 {
t.Errorf("Deduplicate Check Result Failed")
}
}
9 changes: 2 additions & 7 deletions pkg/cluster/manager/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/pingcap/tiup/pkg/set"
"github.com/pingcap/tiup/pkg/tui"
"github.com/pingcap/tiup/pkg/utils"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -93,12 +92,8 @@ func (m *Manager) ScaleOut(
return err
}

if clusterSpec, ok := topo.(*spec.Specification); ok {
if clusterSpec.GlobalOptions.TLSEnabled &&
semver.Compare(base.Version, "v4.0.5") < 0 &&
len(clusterSpec.TiFlashServers) > 0 {
return fmt.Errorf("TiFlash %s is not supported in TLS enabled cluster", base.Version)
}
if err := checkTiFlashWithTLS(topo, base.Version); err != nil {
return err
}

if newPartTopo, ok := newPart.(*spec.Specification); ok {
Expand Down
11 changes: 4 additions & 7 deletions pkg/cluster/manager/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/pingcap/tiup/pkg/set"
"github.com/pingcap/tiup/pkg/tui"
"golang.org/x/mod/semver"
)

// TLS set cluster enable/disable encrypt communication by tls
Expand Down Expand Up @@ -129,13 +128,11 @@ func (m *Manager) TLS(name string, gOpt operator.Options, enable, cleanCertifica
// checkTLSEnv check tiflash vserson and show confirm
func checkTLSEnv(topo spec.Topology, clusterName, version string, skipConfirm bool) error {
// check tiflash version
if clusterSpec, ok := topo.(*spec.Specification); ok {
if clusterSpec.GlobalOptions.TLSEnabled {
if semver.Compare(version, "v4.0.5") < 0 && len(clusterSpec.TiFlashServers) > 0 {
return fmt.Errorf("TiFlash %s is not supported in TLS enabled cluster", version)
}
}
if err := checkTiFlashWithTLS(topo, version); err != nil {
return err
}

if clusterSpec, ok := topo.(*spec.Specification); ok {
if len(clusterSpec.PDServers) != 1 {
return errorx.EnsureStackTrace(fmt.Errorf("Having multiple PD nodes is not supported when enable/disable TLS")).
WithProperty(tui.SuggestionFromString("Please `scale-in` PD nodes to one and try again."))
Expand Down
8 changes: 8 additions & 0 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func checkOSInfo(opt *CheckOptions, osInfo *sysinfo.OS) *CheckResult {

// check OS vendor
switch osInfo.Vendor {
case "amzn":
// Amazon Linux 2 is based on CentOS 7 and is recommended for
// AWS Graviton 2 (ARM64) deployments.
if ver, _ := strconv.ParseFloat(osInfo.Version, 64); ver < 2 || ver >= 3 {
result.Err = fmt.Errorf("%s %s not supported, use version 2 please",
osInfo.Name, osInfo.Release)
return result
}
case "centos", "redhat", "rhel":
// check version
// CentOS 8 is known to be not working, and we don't have plan to support it
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (c *AlertManagerComponent) Instances() []Instance {
ins := make([]Instance, 0, len(alertmanagers))

for _, s := range alertmanagers {
s := s
ins = append(ins, &AlertManagerInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (c *GrafanaComponent) Instances() []Instance {
ins := make([]Instance, 0, len(servers))

for _, s := range servers {
s := s
ins = append(ins, &GrafanaInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/spec/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (c *MonitorComponent) Instances() []Instance {
ins := make([]Instance, 0, len(servers))

for _, s := range servers {
s := s
mi := &MonitorInstance{BaseInstance{
InstanceSpec: s,
Name: c.Name(),
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/spec/tispark.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (c *TiSparkMasterComponent) Role() string {
func (c *TiSparkMasterComponent) Instances() []Instance {
ins := make([]Instance, 0, len(c.Topology.TiSparkMasters))
for _, s := range c.Topology.TiSparkMasters {
s := s
ins = append(ins, &TiSparkMasterInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Expand Down

0 comments on commit 9652ee0

Please sign in to comment.