-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: support using provided topo file besides editing it while ca…
…lling edit-config, add show-config command (#1637)
- Loading branch information
1 parent
0ec99bb
commit 9edf64e
Showing
6 changed files
with
134 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package command | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newShowConfigCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show-config <cluster-name>", | ||
Short: "Show TiDB cluster config", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return cmd.Help() | ||
} | ||
|
||
clusterName := args[0] | ||
clusterReport.ID = scrubClusterName(clusterName) | ||
teleCommand = append(teleCommand, scrubClusterName(clusterName)) | ||
|
||
return cm.ShowConfig(clusterName) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package manager | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
perrs "github.com/pingcap/errors" | ||
"github.com/pingcap/tiup/pkg/cluster/clusterutil" | ||
"github.com/pingcap/tiup/pkg/meta" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// ShowConfig shows the cluster's config. | ||
func (m *Manager) ShowConfig(name string) error { | ||
if err := clusterutil.ValidateClusterNameOrError(name); err != nil { | ||
return err | ||
} | ||
|
||
metadata, err := m.meta(name) | ||
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) { | ||
return err | ||
} | ||
|
||
topo := metadata.GetTopology() | ||
|
||
data, err := yaml.Marshal(topo) | ||
if err != nil { | ||
return perrs.AddStack(err) | ||
} | ||
|
||
fmt.Print(string(data)) | ||
return nil | ||
} |