Skip to content

Commit d87fe96

Browse files
committed
fix: modify vanus operator default endpoint
Signed-off-by: jyjiangkai <[email protected]>
1 parent f90ea26 commit d87fe96

File tree

5 files changed

+19
-46
lines changed

5 files changed

+19
-46
lines changed

vsctl/command/cluster.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@ func createClusterCommand() *cobra.Command {
172172
Run: func(cmd *cobra.Command, args []string) {
173173
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
174174
if err != nil {
175-
operatorEndpoint, err = getOperatorEndpoint()
176-
if err != nil {
177-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
178-
}
175+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
179176
}
180177

181178
if showInstallableList {
@@ -251,6 +248,7 @@ func createClusterCommand() *cobra.Command {
251248
}
252249

253250
clusterspec := table.NewWriter()
251+
clusterspec.SetCaption("The Endpoints Of Vanus Operator: %s\n", operatorEndpoint)
254252
clusterspec.AppendHeader(table.Row{"Cluster", "Version", "Component", "Replicas", "StorageSize", "StorageClass"})
255253
if c.Etcd.StorageClass == nil {
256254
clusterspec.AppendRow(table.Row{"vanus", *c.Version, "etcd", *c.Etcd.Replicas, *c.Etcd.StorageSize, "-"})
@@ -353,10 +351,7 @@ func deleteClusterCommand() *cobra.Command {
353351
Run: func(cmd *cobra.Command, args []string) {
354352
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
355353
if err != nil {
356-
operatorEndpoint, err = getOperatorEndpoint()
357-
if err != nil {
358-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
359-
}
354+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
360355
}
361356

362357
fmt.Print("Deleting a cluster will lose all cluster data and can't be recovered, do you still want to delete the vanus cluster(y/n):")
@@ -467,10 +462,7 @@ func upgradeClusterCommand() *cobra.Command {
467462
Run: func(cmd *cobra.Command, args []string) {
468463
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
469464
if err != nil {
470-
operatorEndpoint, err = getOperatorEndpoint()
471-
if err != nil {
472-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
473-
}
465+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
474466
}
475467

476468
if showUpgradeableList {
@@ -590,10 +582,7 @@ func scaleStoreReplicas() *cobra.Command {
590582
Run: func(cmd *cobra.Command, args []string) {
591583
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
592584
if err != nil {
593-
operatorEndpoint, err = getOperatorEndpoint()
594-
if err != nil {
595-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
596-
}
585+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
597586
}
598587

599588
client := &http.Client{}
@@ -662,10 +651,7 @@ func scaleTriggerReplicas() *cobra.Command {
662651
Run: func(cmd *cobra.Command, args []string) {
663652
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
664653
if err != nil {
665-
operatorEndpoint, err = getOperatorEndpoint()
666-
if err != nil {
667-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
668-
}
654+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
669655
}
670656

671657
client := &http.Client{}
@@ -734,10 +720,7 @@ func getClusterCommand() *cobra.Command {
734720
Run: func(cmd *cobra.Command, args []string) {
735721
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
736722
if err != nil {
737-
operatorEndpoint, err = getOperatorEndpoint()
738-
if err != nil {
739-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
740-
}
723+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
741724
}
742725

743726
client := &http.Client{}

vsctl/command/connector.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ func installConnectorCommand() *cobra.Command {
104104
Run: func(cmd *cobra.Command, args []string) {
105105
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
106106
if err != nil {
107-
operatorEndpoint, err = getOperatorEndpoint()
108-
if err != nil {
109-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
110-
}
107+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
111108
}
112109

113110
if showConnectors {
@@ -257,10 +254,7 @@ func uninstallConnectorCommand() *cobra.Command {
257254
Run: func(cmd *cobra.Command, args []string) {
258255
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
259256
if err != nil {
260-
operatorEndpoint, err = getOperatorEndpoint()
261-
if err != nil {
262-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
263-
}
257+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
264258
}
265259

266260
if name == "" {
@@ -326,10 +320,7 @@ func listConnectorCommand() *cobra.Command {
326320
Run: func(cmd *cobra.Command, args []string) {
327321
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
328322
if err != nil {
329-
operatorEndpoint, err = getOperatorEndpoint()
330-
if err != nil {
331-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
332-
}
323+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
333324
}
334325

335326
if !operatorIsDeployed(cmd, operatorEndpoint) {
@@ -403,10 +394,7 @@ func getConnectorCommand() *cobra.Command {
403394
Run: func(cmd *cobra.Command, args []string) {
404395
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
405396
if err != nil {
406-
operatorEndpoint, err = getOperatorEndpoint()
407-
if err != nil {
408-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
409-
}
397+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
410398
}
411399

412400
if name == "" {

vsctl/command/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const (
4040

4141
const (
4242
RespCodeOK int32 = 200
43-
DefaultOperatorPort = 30009
43+
DefaultOperatorPort = 8089
4444
HttpPrefix = "http://"
4545
BaseUrl = "/api/v1"
4646
)

vsctl/command/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ func operatorIsDeployed(cmd *cobra.Command, endpoint string) bool {
9393
return true
9494
}
9595

96-
func getOperatorEndpoint() (string, error) {
97-
nodeip, err := exec.Command("bash", "-c", "kubectl get no --no-headers -o wide | awk '{print $6}' | head -n 1").Output()
96+
func DefaultOperatorEndpoint() string {
97+
hostname, err := exec.Command("bash", "-c", "kubectl -n vanus get svc vanus-operator -o jsonpath='{.status.loadBalancer.ingress[*].hostname}'").Output()
9898
if err != nil {
99-
return "", err
99+
return fmt.Sprintf("127.0.0.1:%d", DefaultOperatorPort)
100100
}
101-
return fmt.Sprintf("%s:%d", strings.Trim(string(nodeip), "\n"), DefaultOperatorPort), nil
101+
return fmt.Sprintf("%s:%d", strings.Trim(string(hostname), "\n"), DefaultOperatorPort)
102102
}
103103

104104
func LoadConfig(filename string, config interface{}) error {

vsctl/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func init() {
4444
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoint, "endpoint",
4545
"127.0.0.1:8080", "the endpoints of vanus controller")
4646
rootCmd.PersistentFlags().StringVar(&globalFlags.OperatorEndpoint, "operator-endpoint",
47-
"127.0.0.1:8080", "the endpoints of vanus operator")
47+
"127.0.0.1:8089", "the endpoints of vanus operator")
4848
rootCmd.PersistentFlags().StringVarP(&globalFlags.ConfigFile, "config", "C",
4949
"~/.vanus/vanus.yml", "the config file of vsctl")
5050
rootCmd.PersistentFlags().BoolVarP(&globalFlags.Debug, "debug", "D", false,
@@ -64,6 +64,8 @@ func init() {
6464

6565
if os.Getenv("VANUS_OPERATOR") != "" {
6666
globalFlags.OperatorEndpoint = os.Getenv("VANUS_OPERATOR")
67+
} else {
68+
globalFlags.OperatorEndpoint = command.DefaultOperatorEndpoint()
6769
}
6870

6971
rootCmd.AddCommand(

0 commit comments

Comments
 (0)