Skip to content

Commit 78a8fc6

Browse files
committed
modify vanus gateway endpoint
Signed-off-by: jyjiangkai <[email protected]>
1 parent d5607fd commit 78a8fc6

File tree

5 files changed

+25
-33
lines changed

5 files changed

+25
-33
lines changed

vsctl/command/cluster.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,6 @@ func scaleStoreReplicas() *cobra.Command {
585585
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
586586
}
587587

588-
if storeReplicas == 0 {
589-
cmdFailedf(cmd, "the --replicas flag MUST be set")
590-
}
591-
592588
client := &http.Client{}
593589
url := fmt.Sprintf("%s%s%s/cluster", HttpPrefix, operatorEndpoint, BaseUrl)
594590
annotations := make(map[string]string)
@@ -645,6 +641,7 @@ func scaleStoreReplicas() *cobra.Command {
645641
},
646642
}
647643
cmd.Flags().Int32Var(&storeReplicas, "replicas", 0, "the replicas of store")
644+
cobra.MarkFlagRequired(cmd.Flags(), "replicas")
648645
return cmd
649646
}
650647

@@ -658,10 +655,6 @@ func scaleTriggerReplicas() *cobra.Command {
658655
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
659656
}
660657

661-
if triggerReplicas == 0 {
662-
cmdFailedf(cmd, "the --replicas flag MUST be set")
663-
}
664-
665658
client := &http.Client{}
666659
url := fmt.Sprintf("%s%s%s/cluster", HttpPrefix, operatorEndpoint, BaseUrl)
667660
annotations := make(map[string]string)
@@ -718,6 +711,7 @@ func scaleTriggerReplicas() *cobra.Command {
718711
},
719712
}
720713
cmd.Flags().Int32Var(&triggerReplicas, "replicas", 0, "the replicas of trigger")
714+
cobra.MarkFlagRequired(cmd.Flags(), "replicas")
721715
return cmd
722716
}
723717

vsctl/command/connector.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ func uninstallConnectorCommand() *cobra.Command {
257257
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
258258
}
259259

260-
if name == "" {
261-
cmdFailedf(cmd, "the --name flag MUST be set")
262-
}
263-
264260
client := &http.Client{}
265261
url := fmt.Sprintf("%s%s%s/connectors/%s", HttpPrefix, operatorEndpoint, BaseUrl, name)
266262
req, err := http.NewRequest("DELETE", url, &bytes.Reader{})
@@ -310,6 +306,7 @@ func uninstallConnectorCommand() *cobra.Command {
310306
},
311307
}
312308
cmd.Flags().StringVar(&name, "name", "", "connector name")
309+
cobra.MarkFlagRequired(cmd.Flags(), "name")
313310
return cmd
314311
}
315312

@@ -397,10 +394,6 @@ func getConnectorCommand() *cobra.Command {
397394
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
398395
}
399396

400-
if name == "" {
401-
cmdFailedf(cmd, "the --name flag MUST be set")
402-
}
403-
404397
client := &http.Client{}
405398
url := fmt.Sprintf("%s%s%s/connectors/%s", HttpPrefix, operatorEndpoint, BaseUrl, name)
406399
req, err := http.NewRequest("GET", url, &bytes.Reader{})
@@ -459,6 +452,7 @@ func getConnectorCommand() *cobra.Command {
459452
},
460453
}
461454
cmd.Flags().StringVar(&name, "name", "", "connector name")
455+
cobra.MarkFlagRequired(cmd.Flags(), "name")
462456
return cmd
463457
}
464458

vsctl/command/global.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040

4141
const (
4242
RespCodeOK int32 = 200
43+
DefaultGatewayPort = 8080
4344
DefaultOperatorPort = 8089
4445
HttpPrefix = "http://"
4546
BaseUrl = "/api/v1"
@@ -102,12 +103,10 @@ const (
102103
var retryTime = 30
103104

104105
type GlobalFlags struct {
105-
Endpoint string
106-
OperatorEndpoint string
107-
Debug bool
108-
ConfigFile string
109-
Format string
110-
Token string
106+
Debug bool
107+
ConfigFile string
108+
Format string
109+
Token string
111110
}
112111

113112
var (
@@ -116,7 +115,7 @@ var (
116115
)
117116

118117
func InitGatewayClient(cmd *cobra.Command) {
119-
endpoint, err := cmd.Flags().GetString("endpoint")
118+
endpoint, err := getGatewayEndpoint()
120119
if err != nil {
121120
cmdFailedf(cmd, "get gateway endpoint failed: %s", err)
122121
}
@@ -148,17 +147,13 @@ func DestroyGatewayClient() {
148147
}
149148

150149
func mustGetGatewayCloudEventsEndpoint(cmd *cobra.Command) string {
151-
//res, err := client.ClusterInfo(context.Background(), &emptypb.Empty{})
152-
//if err != nil {
153-
// cmdFailedf(cmd, "get cloudevents endpoint failed: %s", err)
154-
//}
155150
sp := strings.Split(mustGetGatewayEndpoint(cmd), ":")
156151
v, _ := strconv.ParseInt(sp[1], 10, 64)
157152
return fmt.Sprintf("%s:%d", sp[0], v+1)
158153
}
159154

160155
func mustGetGatewayEndpoint(cmd *cobra.Command) string {
161-
endpoint, err := cmd.Flags().GetString("endpoint")
156+
endpoint, err := getGatewayEndpoint()
162157
if err != nil {
163158
cmdFailedf(cmd, "get gateway endpoint failed: %s", err)
164159
}

vsctl/command/util.go

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

96+
func getGatewayEndpoint() (string, error) {
97+
if os.Getenv("VANUS_GATEWAY") != "" {
98+
return os.Getenv("VANUS_GATEWAY"), nil
99+
}
100+
hostname, err := exec.Command("bash", "-c", "kubectl -n vanus get svc vanus-gateway -o jsonpath='{.status.loadBalancer.ingress[*].hostname}'").Output()
101+
if err != nil {
102+
return "", err
103+
}
104+
return fmt.Sprintf("%s:%d", strings.Trim(string(hostname), "\n"), DefaultGatewayPort), nil
105+
}
106+
96107
func getOperatorEndpoint() (string, error) {
97108
if os.Getenv("VANUS_OPERATOR") != "" {
98109
return os.Getenv("VANUS_OPERATOR"), nil

vsctl/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ var (
4141
func init() {
4242
cobra.EnablePrefixMatching = true
4343
cobra.EnableCommandSorting = false
44-
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoint, "endpoint",
45-
"127.0.0.1:8080", "the endpoints of vanus controller")
4644
rootCmd.PersistentFlags().StringVarP(&globalFlags.ConfigFile, "config", "C",
4745
"~/.vanus/vanus.yml", "the config file of vsctl")
4846
rootCmd.PersistentFlags().BoolVarP(&globalFlags.Debug, "debug", "D", false,
@@ -56,9 +54,9 @@ func init() {
5654
globalFlags.Token = os.Getenv("VANUS_TOKEN")
5755
}
5856

59-
if os.Getenv("VANUS_GATEWAY") != "" {
60-
globalFlags.Endpoint = os.Getenv("VANUS_GATEWAY")
61-
}
57+
// if os.Getenv("VANUS_GATEWAY") != "" {
58+
// globalFlags.Endpoint = os.Getenv("VANUS_GATEWAY")
59+
// }
6260

6361
rootCmd.AddCommand(
6462
command.NewEventCommand(),

0 commit comments

Comments
 (0)