Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
elkanatovey authored Oct 8, 2023
2 parents 69b1567 + b557c09 commit 8115344
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/gwctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ func getCmd() *cobra.Command {
getCmd.AddCommand(subcommand.BindingGetCmd())
getCmd.AddCommand(subcommand.PolicyGetCmd())
getCmd.AddCommand(subcommand.MetricsGetCmd())
getCmd.AddCommand(subcommand.AllGetCmd())
return getCmd
}
52 changes: 52 additions & 0 deletions cmd/gwctl/subcommand/gwctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/clusterlink-net/clusterlink/cmd/gwctl/config"
cmdutil "github.com/clusterlink-net/clusterlink/cmd/util"
"github.com/clusterlink-net/clusterlink/pkg/util"
"github.com/clusterlink-net/clusterlink/pkg/util/rest"
)

// initOptions is the command line options for 'init'
Expand Down Expand Up @@ -114,3 +115,54 @@ func (o *stateGetOptions) run() error {
fmt.Println(string(sJSON))
return nil
}

type allGetOptions struct {
myID string
}

// AllGetCmd - get all gateways objects.
func AllGetCmd() *cobra.Command {
o := allGetOptions{}
cmd := &cobra.Command{
Use: "all",
Short: "Get all information of the gateway (peers, exports, imports, bindings policies)",
Long: "Get all information of the gateway (peers, exports, imports, bindings policies)",
RunE: func(cmd *cobra.Command, args []string) error {
return o.run()
},
}
o.addFlags(cmd.Flags())

return cmd
}

// addFlags registers flags for the CLI.
func (o *allGetOptions) addFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.myID, "myid", "", "gwctl ID")
}

// run performs the execution of the 'get all' subcommand
func (o *allGetOptions) run() error {
g, err := config.GetClientFromID(o.myID)
if err != nil {
return err
}

objects := map[string]*rest.Client{"Peers": g.Peers, "Exports": g.Exports, "Imports": g.Imports, "Bindings": g.Bindings}
for name, o := range objects {
fmt.Printf("%s:\n", name)
d, err := o.List()
if err != nil {
return fmt.Errorf("error: %v", err.Error())
}
sJSON, err := json.Marshal(d)
if err != nil {
return fmt.Errorf("error: %v", err.Error())
}
fmt.Println(string(sJSON))
}

// Policy
p := policyGetOptions{myID: o.myID}
return p.run()
}
22 changes: 11 additions & 11 deletions tests/k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,38 @@ function test_k8s {
kubectl wait --for=condition=ready pod/gwctl

# install iperf3 and jq
kubectl exec -it gwctl -- apk add iperf3 jq
kubectl exec -i gwctl -- apk add iperf3 jq

# start iperf3 server
kubectl exec -it gwctl -- iperf3 -s -D -p 1234
kubectl exec -i gwctl -- iperf3 -s -D -p 1234

# expose iperf3 server
kubectl expose pod gwctl --name=foo --port=80 --target-port=1234

# wait for API server to come up
kubectl exec -it gwctl -- timeout 30 sh -c 'until gwctl get peer; do sleep 0.1; done > /dev/null 2>&1'
kubectl exec -i gwctl -- timeout 30 sh -c 'until gwctl get peer; do sleep 0.1; done > /dev/null 2>&1'

# export iperf server
kubectl exec -it gwctl -- gwctl create export --name foo --host foo --port 80
kubectl exec -i gwctl -- gwctl create export --name foo --host foo --port 80

# import
kubectl exec -it gwctl -- gwctl create peer --host cl-dataplane --port 443 --name peer1
kubectl exec -it gwctl -- gwctl create import --name foo --host bla --port 9999
kubectl exec -it gwctl -- gwctl create binding --import foo --peer peer1
kubectl exec -i gwctl -- gwctl create peer --host cl-dataplane --port 443 --name peer1
kubectl exec -i gwctl -- gwctl create import --name foo --host bla --port 9999
kubectl exec -i gwctl -- gwctl create binding --import foo --peer peer1

# get imported service port
PORT=$(kubectl exec -it gwctl -- /bin/bash -c "gwctl get import --name foo | jq '.Status.Listener.Port' | tr -d '\n'")
PORT=$(kubectl exec -i gwctl -- /bin/bash -c "gwctl get import --name foo | jq '.Status.Listener.Port' | tr -d '\n'")

# expose imported service (TODO: remove this when controlplane automatically creates a service)
kubectl expose deployment cl-dataplane --name=bla --port=9999 --target-port=$PORT

# wait for imported service socket to come up
kubectl exec -it gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' bla 9999
kubectl exec -i gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' bla 9999
# wait for iperf server to come up
kubectl exec -it gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' gwctl 1234
kubectl exec -i gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' gwctl 1234

# run iperf client
kubectl exec -it gwctl -- iperf3 -c bla -p 9999 -t 1
kubectl exec -i gwctl -- iperf3 -c bla -p 9999 -t 1
}

cd $TEST_DIR
Expand Down

0 comments on commit 8115344

Please sign in to comment.