Skip to content

Commit d5607fd

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

File tree

5 files changed

+37
-61
lines changed

5 files changed

+37
-61
lines changed

vsctl/command/cluster.go

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,9 @@ func createClusterCommand() *cobra.Command {
170170
Use: "create",
171171
Short: "create a cluster",
172172
Run: func(cmd *cobra.Command, args []string) {
173-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
173+
operatorEndpoint, err := getOperatorEndpoint()
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, "-"})
@@ -351,12 +349,9 @@ func deleteClusterCommand() *cobra.Command {
351349
Use: "delete",
352350
Short: "delete a cluster",
353351
Run: func(cmd *cobra.Command, args []string) {
354-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
352+
operatorEndpoint, err := getOperatorEndpoint()
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):")
@@ -465,12 +460,9 @@ func upgradeClusterCommand() *cobra.Command {
465460
Use: "upgrade",
466461
Short: "upgrade cluster",
467462
Run: func(cmd *cobra.Command, args []string) {
468-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
463+
operatorEndpoint, err := getOperatorEndpoint()
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 {
@@ -588,12 +580,13 @@ func scaleStoreReplicas() *cobra.Command {
588580
Use: "store",
589581
Short: "scale store replicas",
590582
Run: func(cmd *cobra.Command, args []string) {
591-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
583+
operatorEndpoint, err := getOperatorEndpoint()
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)
586+
}
587+
588+
if storeReplicas == 0 {
589+
cmdFailedf(cmd, "the --replicas flag MUST be set")
597590
}
598591

599592
client := &http.Client{}
@@ -651,7 +644,7 @@ func scaleStoreReplicas() *cobra.Command {
651644
}
652645
},
653646
}
654-
cmd.Flags().Int32Var(&storeReplicas, "replicas", 3, "replicas")
647+
cmd.Flags().Int32Var(&storeReplicas, "replicas", 0, "the replicas of store")
655648
return cmd
656649
}
657650

@@ -660,12 +653,13 @@ func scaleTriggerReplicas() *cobra.Command {
660653
Use: "trigger",
661654
Short: "scale trigger replicas",
662655
Run: func(cmd *cobra.Command, args []string) {
663-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
656+
operatorEndpoint, err := getOperatorEndpoint()
664657
if err != nil {
665-
operatorEndpoint, err = getOperatorEndpoint()
666-
if err != nil {
667-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
668-
}
658+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
659+
}
660+
661+
if triggerReplicas == 0 {
662+
cmdFailedf(cmd, "the --replicas flag MUST be set")
669663
}
670664

671665
client := &http.Client{}
@@ -723,7 +717,7 @@ func scaleTriggerReplicas() *cobra.Command {
723717
}
724718
},
725719
}
726-
cmd.Flags().Int32Var(&triggerReplicas, "replicas", 3, "replicas")
720+
cmd.Flags().Int32Var(&triggerReplicas, "replicas", 0, "the replicas of trigger")
727721
return cmd
728722
}
729723

@@ -732,12 +726,9 @@ func getClusterCommand() *cobra.Command {
732726
Use: "status",
733727
Short: "get cluster status",
734728
Run: func(cmd *cobra.Command, args []string) {
735-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
729+
operatorEndpoint, err := getOperatorEndpoint()
736730
if err != nil {
737-
operatorEndpoint, err = getOperatorEndpoint()
738-
if err != nil {
739-
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
740-
}
731+
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
741732
}
742733

743734
client := &http.Client{}

vsctl/command/connector.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@ func installConnectorCommand() *cobra.Command {
102102
Use: "install",
103103
Short: "install a connector",
104104
Run: func(cmd *cobra.Command, args []string) {
105-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
105+
operatorEndpoint, err := getOperatorEndpoint()
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 {
@@ -255,12 +252,9 @@ func uninstallConnectorCommand() *cobra.Command {
255252
Use: "uninstall",
256253
Short: "uninstall a connector",
257254
Run: func(cmd *cobra.Command, args []string) {
258-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
255+
operatorEndpoint, err := getOperatorEndpoint()
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 == "" {
@@ -324,12 +318,9 @@ func listConnectorCommand() *cobra.Command {
324318
Use: "list",
325319
Short: "list connectors",
326320
Run: func(cmd *cobra.Command, args []string) {
327-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
321+
operatorEndpoint, err := getOperatorEndpoint()
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) {
@@ -401,12 +392,9 @@ func getConnectorCommand() *cobra.Command {
401392
Use: "info",
402393
Short: "get connector info",
403394
Run: func(cmd *cobra.Command, args []string) {
404-
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
395+
operatorEndpoint, err := getOperatorEndpoint()
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ func operatorIsDeployed(cmd *cobra.Command, endpoint string) bool {
9494
}
9595

9696
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()
97+
if os.Getenv("VANUS_OPERATOR") != "" {
98+
return os.Getenv("VANUS_OPERATOR"), nil
99+
}
100+
hostname, err := exec.Command("bash", "-c", "kubectl -n vanus get svc vanus-operator -o jsonpath='{.status.loadBalancer.ingress[*].hostname}'").Output()
98101
if err != nil {
99102
return "", err
100103
}
101-
return fmt.Sprintf("%s:%d", strings.Trim(string(nodeip), "\n"), DefaultOperatorPort), nil
104+
return fmt.Sprintf("%s:%d", strings.Trim(string(hostname), "\n"), DefaultOperatorPort), nil
102105
}
103106

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

vsctl/main.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ func init() {
4343
cobra.EnableCommandSorting = false
4444
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoint, "endpoint",
4545
"127.0.0.1:8080", "the endpoints of vanus controller")
46-
rootCmd.PersistentFlags().StringVar(&globalFlags.OperatorEndpoint, "operator-endpoint",
47-
"127.0.0.1:8080", "the endpoints of vanus operator")
4846
rootCmd.PersistentFlags().StringVarP(&globalFlags.ConfigFile, "config", "C",
4947
"~/.vanus/vanus.yml", "the config file of vsctl")
5048
rootCmd.PersistentFlags().BoolVarP(&globalFlags.Debug, "debug", "D", false,
@@ -62,10 +60,6 @@ func init() {
6260
globalFlags.Endpoint = os.Getenv("VANUS_GATEWAY")
6361
}
6462

65-
if os.Getenv("VANUS_OPERATOR") != "" {
66-
globalFlags.OperatorEndpoint = os.Getenv("VANUS_OPERATOR")
67-
}
68-
6963
rootCmd.AddCommand(
7064
command.NewEventCommand(),
7165
command.NewEventbusCommand(),

0 commit comments

Comments
 (0)