Skip to content

Commit

Permalink
modify vanus gateway endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: jyjiangkai <jyjiangkai@163.com>
  • Loading branch information
hwjiangkai committed Apr 4, 2023
1 parent d5607fd commit 3efd1f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
10 changes: 2 additions & 8 deletions vsctl/command/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,6 @@ func scaleStoreReplicas() *cobra.Command {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

if storeReplicas == 0 {
cmdFailedf(cmd, "the --replicas flag MUST be set")
}

client := &http.Client{}
url := fmt.Sprintf("%s%s%s/cluster", HttpPrefix, operatorEndpoint, BaseUrl)
annotations := make(map[string]string)
Expand Down Expand Up @@ -645,6 +641,7 @@ func scaleStoreReplicas() *cobra.Command {
},
}
cmd.Flags().Int32Var(&storeReplicas, "replicas", 0, "the replicas of store")
cobra.MarkFlagRequired(cmd.Flags(), "replicas")
return cmd
}

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

if triggerReplicas == 0 {
cmdFailedf(cmd, "the --replicas flag MUST be set")
}

client := &http.Client{}
url := fmt.Sprintf("%s%s%s/cluster", HttpPrefix, operatorEndpoint, BaseUrl)
annotations := make(map[string]string)
Expand Down Expand Up @@ -718,6 +711,7 @@ func scaleTriggerReplicas() *cobra.Command {
},
}
cmd.Flags().Int32Var(&triggerReplicas, "replicas", 0, "the replicas of trigger")
cobra.MarkFlagRequired(cmd.Flags(), "replicas")
return cmd
}

Expand Down
10 changes: 2 additions & 8 deletions vsctl/command/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ func uninstallConnectorCommand() *cobra.Command {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

if name == "" {
cmdFailedf(cmd, "the --name flag MUST be set")
}

client := &http.Client{}
url := fmt.Sprintf("%s%s%s/connectors/%s", HttpPrefix, operatorEndpoint, BaseUrl, name)
req, err := http.NewRequest("DELETE", url, &bytes.Reader{})
Expand Down Expand Up @@ -310,6 +306,7 @@ func uninstallConnectorCommand() *cobra.Command {
},
}
cmd.Flags().StringVar(&name, "name", "", "connector name")
cobra.MarkFlagRequired(cmd.Flags(), "name")
return cmd
}

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

if name == "" {
cmdFailedf(cmd, "the --name flag MUST be set")
}

client := &http.Client{}
url := fmt.Sprintf("%s%s%s/connectors/%s", HttpPrefix, operatorEndpoint, BaseUrl, name)
req, err := http.NewRequest("GET", url, &bytes.Reader{})
Expand Down Expand Up @@ -459,6 +452,7 @@ func getConnectorCommand() *cobra.Command {
},
}
cmd.Flags().StringVar(&name, "name", "", "connector name")
cobra.MarkFlagRequired(cmd.Flags(), "name")
return cmd
}

Expand Down
19 changes: 7 additions & 12 deletions vsctl/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (

const (
RespCodeOK int32 = 200
DefaultGatewayPort = 8080
DefaultOperatorPort = 8089
HttpPrefix = "http://"
BaseUrl = "/api/v1"
Expand Down Expand Up @@ -102,12 +103,10 @@ const (
var retryTime = 30

type GlobalFlags struct {
Endpoint string
OperatorEndpoint string
Debug bool
ConfigFile string
Format string
Token string
Debug bool
ConfigFile string
Format string
Token string
}

var (
Expand All @@ -116,7 +115,7 @@ var (
)

func InitGatewayClient(cmd *cobra.Command) {
endpoint, err := cmd.Flags().GetString("endpoint")
endpoint, err := getGatewayEndpoint()
if err != nil {
cmdFailedf(cmd, "get gateway endpoint failed: %s", err)
}
Expand Down Expand Up @@ -148,17 +147,13 @@ func DestroyGatewayClient() {
}

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

func mustGetGatewayEndpoint(cmd *cobra.Command) string {
endpoint, err := cmd.Flags().GetString("endpoint")
endpoint, err := getGatewayEndpoint()
if err != nil {
cmdFailedf(cmd, "get gateway endpoint failed: %s", err)
}
Expand Down
11 changes: 11 additions & 0 deletions vsctl/command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ func operatorIsDeployed(cmd *cobra.Command, endpoint string) bool {
return true
}

func getGatewayEndpoint() (string, error) {
if os.Getenv("VANUS_GATEWAY") != "" {
return os.Getenv("VANUS_GATEWAY"), nil
}
hostname, err := exec.Command("bash", "-c", "kubectl -n vanus get svc vanus-gateway -o jsonpath='{.status.loadBalancer.ingress[*].hostname}'").Output()
if err != nil {
return "", err
}
return fmt.Sprintf("%s:%d", strings.Trim(string(hostname), "\n"), DefaultGatewayPort), nil
}

func getOperatorEndpoint() (string, error) {
if os.Getenv("VANUS_OPERATOR") != "" {
return os.Getenv("VANUS_OPERATOR"), nil
Expand Down
6 changes: 0 additions & 6 deletions vsctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ var (
func init() {
cobra.EnablePrefixMatching = true
cobra.EnableCommandSorting = false
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoint, "endpoint",
"127.0.0.1:8080", "the endpoints of vanus controller")
rootCmd.PersistentFlags().StringVarP(&globalFlags.ConfigFile, "config", "C",
"~/.vanus/vanus.yml", "the config file of vsctl")
rootCmd.PersistentFlags().BoolVarP(&globalFlags.Debug, "debug", "D", false,
Expand All @@ -56,10 +54,6 @@ func init() {
globalFlags.Token = os.Getenv("VANUS_TOKEN")
}

if os.Getenv("VANUS_GATEWAY") != "" {
globalFlags.Endpoint = os.Getenv("VANUS_GATEWAY")
}

rootCmd.AddCommand(
command.NewEventCommand(),
command.NewEventbusCommand(),
Expand Down

0 comments on commit 3efd1f2

Please sign in to comment.