Skip to content

Commit 197c576

Browse files
authored
feat: add cluster subcommand for vsctl (#411)
Signed-off-by: jyjiangkai <[email protected]>
1 parent b762f1e commit 197c576

File tree

11 files changed

+949
-84
lines changed

11 files changed

+949
-84
lines changed

vsctl/command/cluster.go

Lines changed: 466 additions & 0 deletions
Large diffs are not rendered by default.

vsctl/command/connector.go

Lines changed: 423 additions & 0 deletions
Large diffs are not rendered by default.

vsctl/command/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

vsctl/command/eventbus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

vsctl/command/flag.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -55,6 +55,22 @@ var (
5555

5656
showSegment bool
5757
showBlock bool
58+
59+
// for cluster
60+
clusterVersion string
61+
controllerReplicas int32
62+
controllerStorageSize string
63+
storeReplicas int32
64+
storeStorageSize string
65+
triggerReplicas int32
66+
67+
// for connector
68+
configfile string
69+
kind string
70+
name string
71+
ctype string
72+
connectorVersion string
73+
showConnectors bool
5874
)
5975

6076
const (

vsctl/command/global.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -32,11 +32,17 @@ const (
3232
FormatJSON = "json"
3333
)
3434

35+
const (
36+
HttpPrefix = "http://"
37+
BaseUrl = "/api/v1"
38+
)
39+
3540
type GlobalFlags struct {
36-
Endpoint string
37-
Debug bool
38-
ConfigFile string
39-
Format string
41+
Endpoint string
42+
OperatorEndpoint string
43+
Debug bool
44+
ConfigFile string
45+
Format string
4046
}
4147

4248
var (

vsctl/command/meta.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

vsctl/command/subscription.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

vsctl/command/util.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,8 +15,10 @@
1515
package command
1616

1717
import (
18+
"bytes"
1819
"encoding/json"
1920
"fmt"
21+
"net/http"
2022
"os"
2123

2224
"github.com/fatih/color"
@@ -55,3 +57,20 @@ func cmdFailedWithHelpNotice(cmd *cobra.Command, format string) {
5557
_ = cmd.Help()
5658
os.Exit(-1)
5759
}
60+
61+
func operatorIsDeployed(cmd *cobra.Command, endpoint string) bool {
62+
client := &http.Client{}
63+
url := fmt.Sprintf("http://%s/api/v1/vanus/healthz", endpoint)
64+
req, err := http.NewRequest("GET", url, &bytes.Reader{})
65+
if err != nil {
66+
return false
67+
}
68+
69+
req.Header.Set("Content-Type", "application/json")
70+
resp, err := client.Do(req)
71+
if err != nil {
72+
return false
73+
}
74+
defer resp.Body.Close()
75+
return true
76+
}

vsctl/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Linkall Inc.
1+
// Copyright 2023 Linkall Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -42,6 +42,8 @@ func init() {
4242
cobra.EnableCommandSorting = false
4343
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoint, "endpoint",
4444
"127.0.0.1:8080", "the endpoints of vanus controller")
45+
rootCmd.PersistentFlags().StringVar(&globalFlags.OperatorEndpoint, "operator-endpoint",
46+
"127.0.0.1:8080", "the endpoints of vanus operator")
4547
rootCmd.PersistentFlags().StringVarP(&globalFlags.ConfigFile, "config", "C",
4648
"~/.vanus/vanus.yml", "the config file of vsctl")
4749
rootCmd.PersistentFlags().BoolVarP(&globalFlags.Debug, "debug", "D", false,
@@ -53,11 +55,16 @@ func init() {
5355
globalFlags.Endpoint = os.Getenv("VANUS_GATEWAY")
5456
}
5557

58+
if os.Getenv("VANUS_OPERATOR") != "" {
59+
globalFlags.OperatorEndpoint = os.Getenv("VANUS_OPERATOR")
60+
}
61+
5662
rootCmd.AddCommand(
5763
command.NewEventCommand(),
5864
command.NewEventbusCommand(),
5965
command.NewSubscriptionCommand(),
6066
command.NewClusterCommand(),
67+
command.NewConnectorCommand(),
6168
newVersionCommand(),
6269
)
6370
rootCmd.CompletionOptions.DisableDefaultCmd = true

0 commit comments

Comments
 (0)