Skip to content

Commit

Permalink
Merge pull request #376 from orozery/import-api
Browse files Browse the repository at this point in the history
pkg/api: Move bindings inside imports
  • Loading branch information
orozery authored Mar 11, 2024
2 parents 6b9fe17 + ce25668 commit c2fc608
Show file tree
Hide file tree
Showing 26 changed files with 168 additions and 915 deletions.
3 changes: 0 additions & 3 deletions cmd/gwctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func createCmd() *cobra.Command {
createCmd.AddCommand(subcommand.PeerCreateCmd())
createCmd.AddCommand(subcommand.ExportCreateCmd())
createCmd.AddCommand(subcommand.ImportCreateCmd())
createCmd.AddCommand(subcommand.BindingCreateCmd())
createCmd.AddCommand(subcommand.PolicyCreateCmd())
return createCmd
}
Expand All @@ -76,7 +75,6 @@ func deleteCmd() *cobra.Command {
deleteCmd.AddCommand(subcommand.PeerDeleteCmd())
deleteCmd.AddCommand(subcommand.ExportDeleteCmd())
deleteCmd.AddCommand(subcommand.ImportDeleteCmd())
deleteCmd.AddCommand(subcommand.BindingDeleteCmd())
deleteCmd.AddCommand(subcommand.PolicyDeleteCmd())
return deleteCmd
}
Expand Down Expand Up @@ -108,7 +106,6 @@ func getCmd() *cobra.Command {
getCmd.AddCommand(subcommand.PeerGetCmd())
getCmd.AddCommand(subcommand.ExportGetCmd())
getCmd.AddCommand(subcommand.ImportGetCmd())
getCmd.AddCommand(subcommand.BindingGetCmd())
getCmd.AddCommand(subcommand.PolicyGetCmd())
getCmd.AddCommand(subcommand.MetricsGetCmd())
getCmd.AddCommand(subcommand.AllGetCmd())
Expand Down
180 changes: 0 additions & 180 deletions cmd/gwctl/subcommand/binding.go

This file was deleted.

7 changes: 3 additions & 4 deletions cmd/gwctl/subcommand/gwctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ func (o *allGetOptions) run() error {
}

objects := map[string]*rest.Client{
"Peers": g.Peers,
"Exports": g.Exports,
"Imports": g.Imports,
"Bindings": g.Bindings,
"Peers": g.Peers,
"Exports": g.Exports,
"Imports": g.Imports,
}

for name, o := range objects {
Expand Down
20 changes: 10 additions & 10 deletions cmd/gwctl/subcommand/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (

// importOptions is the command line options for 'create import' or 'update import'.
type importOptions struct {
myID string
name string
host string
port uint16
myID string
name string
port uint16
peers []string
}

// ImportCreateCmd - create an imported service.
Expand Down Expand Up @@ -73,8 +73,8 @@ func ImportUpdateCmd() *cobra.Command {
func (o *importOptions) addFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.myID, "myid", "", "gwctl ID")
fs.StringVar(&o.name, "name", "", "Imported service name")
fs.StringVar(&o.host, "host", "", "Imported service endpoint (IP/DNS), if unspecified, uses the service name")
fs.Uint16Var(&o.port, "port", 0, "Imported service port")
fs.StringSliceVar(&o.peers, "peer", []string{}, "Remote peer to import the service from")
}

// run performs the execution of the 'create import' or 'update import' subcommand.
Expand All @@ -92,10 +92,8 @@ func (o *importOptions) run(isUpdate bool) error {
err = importOperation(&api.Import{
Name: o.name,
Spec: api.ImportSpec{
Service: api.Endpoint{
Host: o.host,
Port: o.port,
},
Port: o.port,
Peers: o.peers,
},
})
if err != nil {
Expand Down Expand Up @@ -192,7 +190,9 @@ func (o *importGetOptions) run() error {
}
fmt.Printf("Imported services:\n")
for i, s := range *sArr.(*[]api.Import) {
fmt.Printf("%d. Imported Name: %s. Endpoint %v\n", i+1, s.Name, s.Spec.Service)
fmt.Printf(
"%d. Imported Name: %s. Port %v. TargetPort %v. Peers %v.\n",
i+1, s.Name, s.Spec.Port, s.Spec.TargetPort, s.Spec.Peers)
}
} else {
imp, err := importClient.Imports.Get(o.name)
Expand Down
7 changes: 1 addition & 6 deletions demos/bookinfo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ def bookInfoDemo(cl1:cluster, cl2:cluster, cl3:cluster, testOutputFolder,logLeve
# Import service
cl1.useCluster()
printHeader(f"\n\nStart import svc {reviewSvc}")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {reviewSvc} --host {reviewSvc} --port {srcK8sSvcPort} ')

# Binding
printHeader(f"\n\nStart binding svc {reviewSvc}")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {reviewSvc} --peer {cl2.name}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {reviewSvc} --peer {cl3.name}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {reviewSvc} --port {srcK8sSvcPort} --peer {cl2.name} --peer {cl3.name}')

# Get services
cl1.useCluster()
Expand Down
2 changes: 1 addition & 1 deletion demos/iperf3/kind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ First, we specify which service we want to import and specify the local k8s endp
When running Kind cluster on macOS run instead the following:

kubectl config use-context kind-peer1
kubectl exec -i $GWCTL1-- gwctl create import --myid peer1 --name iperf3-server --host iperf3-server --port 5000
kubectl exec -i $GWCTL1-- gwctl create import --myid peer1 --name iperf3-server --port 5000

Second, we specify the peer we want to import the service:

Expand Down
4 changes: 1 addition & 3 deletions demos/iperf3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def iperf3Test(cl1:cluster, cl2:cluster, testOutputFolder,logLevel="info" ,datap

#Import destination service
printHeader(f"\n\nStart Importing {destSvc} service to {cl1.name}")
runcmd(f'gwctl --myid {cl1.name} create import --name {destSvc} --host {destSvc} --port {destPort}')
printHeader(f"\n\nStart binding {destSvc} service to {cl1.name}")
runcmd(f'gwctl --myid {cl1.name} create binding --import {destSvc} --peer {cl2.name}')
runcmd(f'gwctl --myid {cl1.name} create import --name {destSvc} --port {destPort} --peer {cl2.name}')

#Add policy
printHeader("Applying policies")
Expand Down
35 changes: 14 additions & 21 deletions demos/qotd/kind/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,23 @@

# Import and binding Services
cl1.useCluster()
printHeader(f"\n\nStart import and binding svc {quoteApp.name} to cl1 from cl2 ")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {quoteApp.name} --host {quoteApp.name} --port {quoteApp.port}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {quoteApp.name} --peer {cl2.name}')
printHeader(f"\n\nStart import and binding svc {authorApp.name} to cl1 from cl2")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {authorApp.name} --host {authorApp.name} --port {authorApp.port}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {authorApp.name} --peer {cl2.name}')
printHeader(f"\n\nStart import and binding svc {dbApp.name} to cl1 from cl2")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {dbApp.name} --host {dbApp.name} --port {dbApp.port}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {dbApp.name} --peer {cl2.name}')
printHeader(f"\n\nStart import and binding svc {imageApp.name} to cl1 from cl2")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {imageApp.name} --host {imageApp.name} --port {imageApp.port}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {imageApp.name} --peer {cl2.name}')
printHeader(f"\n\nStart import svc {quoteApp.name} to cl1 from cl2 ")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {quoteApp.name} --port {quoteApp.port} --peer {cl2.name}')
printHeader(f"\n\nStart import svc {authorApp.name} to cl1 from cl2")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {authorApp.name} --port {authorApp.port} --peer {cl2.name}')
printHeader(f"\n\nStart import svc {dbApp.name} to cl1 from cl2")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {dbApp.name} --port {dbApp.port} --peer {cl2.name}')
printHeader(f"\n\nStart import svc {imageApp.name} to cl1 from cl2")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {imageApp.name} --port {imageApp.port} --peer {cl2.name}')

printHeader(f"\n\nStart import and binding svc {pdfApp.name} to cl1 from cl3")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {pdfApp.name} --host {pdfApp.name} --port {pdfApp.port}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {pdfApp.name} --peer {cl3.name}')
printHeader(f"\n\nStart import and binding svc {ratingApp.name} to cl1 from cl3")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {ratingApp.name} --host {ratingApp.name} --port {ratingApp.port}')
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create binding --import {ratingApp.name} --peer {cl3.name}')
printHeader(f"\n\nStart import svc {pdfApp.name} to cl1 from cl3")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {pdfApp.name} --port {pdfApp.port} --peer {cl3.name}')
printHeader(f"\n\nStart import svc {ratingApp.name} to cl1 from cl3")
runcmd(f'kubectl exec -i {gwctl1Pod} -- gwctl create import --name {ratingApp.name} --port {ratingApp.port} --peer {cl3.name}')

cl3.useCluster()
printHeader(f"\n\nStart import and binding svc {quoteApp.name} in cl3")
runcmd(f'kubectl exec -i {gwctl3Pod} -- gwctl create import --name {quoteApp.name} --host {quoteApp.name} --port {quoteApp.port}')
runcmd(f'kubectl exec -i {gwctl3Pod} -- gwctl create binding --import {quoteApp.name} --peer {cl2.name}')
printHeader(f"\n\nStart import svc {quoteApp.name} in cl3")
runcmd(f'kubectl exec -i {gwctl3Pod} -- gwctl create import --name {quoteApp.name} --port {quoteApp.port} --peer {cl2.name}')

# Set policies
printHeader(f"\n\nApplying policy file {allowAllPolicy}")
Expand Down
10 changes: 2 additions & 8 deletions demos/speedtest/kind/service_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,9 @@
#Import service
printHeader(f"\n\nStart import svc {destSvc}")
cl1.useCluster()
runcmd(f'gwctl create import --myid {cl1.name} --name {destSvc} --host {destSvc} --port 3000')
runcmd(f'gwctl create import --myid {cl1.name} --name {destSvc} --port 3000 --peer {cl2.name}')
cl3.useCluster()
runcmd(f'gwctl create import --myid {cl3.name} --name {destSvc} --host {destSvc} --port 3000')
#Set K8s network services
printHeader(f"\n\nStart binding service {destSvc}")
cl1.useCluster()
runcmd(f'gwctl create binding --myid {cl1.name} --import {destSvc} --peer {cl2.name}')
cl3.useCluster()
runcmd(f'gwctl create binding --myid {cl3.name} --import {destSvc} --peer {cl2.name}')
runcmd(f'gwctl create import --myid {cl3.name} --name {destSvc} --port 3000 --peer {cl2.name}')

printHeader("\n\nStart get service cl1")
runcmd(f'gwctl get import --myid {cl1.name} ')
Expand Down
Loading

0 comments on commit c2fc608

Please sign in to comment.