Skip to content

fix: modify vanus operator default endpoint #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions vsctl/command/cluster.go
Original file line number Diff line number Diff line change
@@ -170,12 +170,9 @@ func createClusterCommand() *cobra.Command {
Use: "create",
Short: "create a cluster",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

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

clusterspec := table.NewWriter()
clusterspec.SetCaption("The Endpoints Of Vanus Operator: %s\n", operatorEndpoint)
clusterspec.AppendHeader(table.Row{"Cluster", "Version", "Component", "Replicas", "StorageSize", "StorageClass"})
if c.Etcd.StorageClass == nil {
clusterspec.AppendRow(table.Row{"vanus", *c.Version, "etcd", *c.Etcd.Replicas, *c.Etcd.StorageSize, "-"})
@@ -351,12 +349,9 @@ func deleteClusterCommand() *cobra.Command {
Use: "delete",
Short: "delete a cluster",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

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 {
Use: "upgrade",
Short: "upgrade cluster",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

if showUpgradeableList {
@@ -588,12 +580,9 @@ func scaleStoreReplicas() *cobra.Command {
Use: "store",
Short: "scale store replicas",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

client := &http.Client{}
@@ -651,7 +640,8 @@ func scaleStoreReplicas() *cobra.Command {
}
},
}
cmd.Flags().Int32Var(&storeReplicas, "replicas", 3, "replicas")
cmd.Flags().Int32Var(&storeReplicas, "replicas", 0, "the replicas of store")
cobra.MarkFlagRequired(cmd.Flags(), "replicas")
return cmd
}

@@ -660,12 +650,9 @@ func scaleTriggerReplicas() *cobra.Command {
Use: "trigger",
Short: "scale trigger replicas",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

client := &http.Client{}
@@ -723,7 +710,8 @@ func scaleTriggerReplicas() *cobra.Command {
}
},
}
cmd.Flags().Int32Var(&triggerReplicas, "replicas", 3, "replicas")
cmd.Flags().Int32Var(&triggerReplicas, "replicas", 0, "the replicas of trigger")
cobra.MarkFlagRequired(cmd.Flags(), "replicas")
return cmd
}

@@ -732,12 +720,9 @@ func getClusterCommand() *cobra.Command {
Use: "status",
Short: "get cluster status",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

client := &http.Client{}
38 changes: 10 additions & 28 deletions vsctl/command/connector.go
Original file line number Diff line number Diff line change
@@ -102,12 +102,9 @@ func installConnectorCommand() *cobra.Command {
Use: "install",
Short: "install a connector",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

if showConnectors {
@@ -255,16 +252,9 @@ func uninstallConnectorCommand() *cobra.Command {
Use: "uninstall",
Short: "uninstall a connector",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
}

if name == "" {
cmdFailedf(cmd, "the --name flag MUST be set")
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

client := &http.Client{}
@@ -316,6 +306,7 @@ func uninstallConnectorCommand() *cobra.Command {
},
}
cmd.Flags().StringVar(&name, "name", "", "connector name")
cobra.MarkFlagRequired(cmd.Flags(), "name")
return cmd
}

@@ -324,12 +315,9 @@ func listConnectorCommand() *cobra.Command {
Use: "list",
Short: "list connectors",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

if !operatorIsDeployed(cmd, operatorEndpoint) {
@@ -401,16 +389,9 @@ func getConnectorCommand() *cobra.Command {
Use: "info",
Short: "get connector info",
Run: func(cmd *cobra.Command, args []string) {
operatorEndpoint, err := cmd.Flags().GetString("operator-endpoint")
operatorEndpoint, err := getOperatorEndpoint()
if err != nil {
operatorEndpoint, err = getOperatorEndpoint()
if err != nil {
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}
}

if name == "" {
cmdFailedf(cmd, "the --name flag MUST be set")
cmdFailedf(cmd, "get operator endpoint failed: %s", err)
}

client := &http.Client{}
@@ -471,6 +452,7 @@ func getConnectorCommand() *cobra.Command {
},
}
cmd.Flags().StringVar(&name, "name", "", "connector name")
cobra.MarkFlagRequired(cmd.Flags(), "name")
return cmd
}

21 changes: 8 additions & 13 deletions vsctl/command/global.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,8 @@ const (

const (
RespCodeOK int32 = 200
DefaultOperatorPort = 30009
DefaultGatewayPort = 8080
DefaultOperatorPort = 8089
HttpPrefix = "http://"
BaseUrl = "/api/v1"
)
@@ -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 (
@@ -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)
}
@@ -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)
}
18 changes: 16 additions & 2 deletions vsctl/command/util.go
Original file line number Diff line number Diff line change
@@ -93,12 +93,26 @@ 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) {
nodeip, err := exec.Command("bash", "-c", "kubectl get no --no-headers -o wide | awk '{print $6}' | head -n 1").Output()
if os.Getenv("VANUS_OPERATOR") != "" {
return os.Getenv("VANUS_OPERATOR"), nil
}
hostname, err := exec.Command("bash", "-c", "kubectl -n vanus get svc vanus-operator -o jsonpath='{.status.loadBalancer.ingress[*].hostname}'").Output()
if err != nil {
return "", err
}
return fmt.Sprintf("%s:%d", strings.Trim(string(nodeip), "\n"), DefaultOperatorPort), nil
return fmt.Sprintf("%s:%d", strings.Trim(string(hostname), "\n"), DefaultOperatorPort), nil
}

func LoadConfig(filename string, config interface{}) error {
12 changes: 0 additions & 12 deletions vsctl/main.go
Original file line number Diff line number Diff line change
@@ -41,10 +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().StringVar(&globalFlags.OperatorEndpoint, "operator-endpoint",
"127.0.0.1:8080", "the endpoints of vanus operator")
rootCmd.PersistentFlags().StringVarP(&globalFlags.ConfigFile, "config", "C",
"~/.vanus/vanus.yml", "the config file of vsctl")
rootCmd.PersistentFlags().BoolVarP(&globalFlags.Debug, "debug", "D", false,
@@ -58,14 +54,6 @@ func init() {
globalFlags.Token = os.Getenv("VANUS_TOKEN")
}

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

if os.Getenv("VANUS_OPERATOR") != "" {
globalFlags.OperatorEndpoint = os.Getenv("VANUS_OPERATOR")
}

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