From 6fa593c9bf0e56451922094d3987b30d6bf44508 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Fri, 18 Mar 2022 17:41:56 +0900 Subject: [PATCH 1/9] Fix resume failure - Close listen connection - Change log level from fatal to debug to return a function normally --- poc-cb-net/cmd/agent/agent.go | 5 +-- poc-cb-net/internal/cb-network/cb-network.go | 47 ++++++++++++-------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 21c36a6..817b045 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -105,12 +105,11 @@ func handleCommand(command string, commandOption string, etcdClient *clientv3.Cl switch command { case "suspend": updatePeerState(model.Suspended, etcdClient) - CBNet.Shutdown() + CBNet.Stop() case "resume": - // Start the cb-network - go CBNet.Startup() + go CBNet.Run() // Wait until the goroutine is started time.Sleep(200 * time.Millisecond) diff --git a/poc-cb-net/internal/cb-network/cb-network.go b/poc-cb-net/internal/cb-network/cb-network.go index 8b21554..ff44ee3 100644 --- a/poc-cb-net/internal/cb-network/cb-network.go +++ b/poc-cb-net/internal/cb-network/cb-network.go @@ -97,8 +97,7 @@ type CBNetwork struct { privateKey *rsa.PrivateKey // Private key keyring map[string]*rsa.PublicKey // Keyring for secrets keyringMutex *sync.Mutex // Mutext for keyring - - //listenConnection *net.UDPConn // Connection for encapsulation and decapsulation + listenConnection *net.UDPConn // Listen connection for encapsulation and decapsulation //NetworkInterfaces []model.NetworkInterface // Deprecated } @@ -387,8 +386,8 @@ func (cbnetwork *CBNetwork) runIP(args ...string) { CBLogger.Debug("End.........") } -// Startup represents a function to start the cloud-barista network. -func (cbnetwork *CBNetwork) Startup() { +// Run represents a function to start the cloud-barista network. +func (cbnetwork *CBNetwork) Run() { CBLogger.Debug("Start.........") CBLogger.Debug("Blocked till the networking rule setup") @@ -416,12 +415,13 @@ func (cbnetwork *CBNetwork) runTunneling() { if err != nil { CBLogger.Fatal("Unable to listen on UDP socket:", err) } + cbnetwork.listenConnection = lstnConn // Perform error handling defer func() { - errClose := lstnConn.Close() + errClose := cbnetwork.listenConnection.Close() if errClose != nil { - CBLogger.Fatal("can't close the listen connection", errClose) + CBLogger.Error("can't close the listen connection", errClose) } }() @@ -429,27 +429,29 @@ func (cbnetwork *CBNetwork) runTunneling() { // Decapsulation wg.Add(1) - go cbnetwork.decapsulate(lstnConn, &wg) + go cbnetwork.decapsulate(&wg) // Encapsulation wg.Add(1) - go cbnetwork.encapsulate(lstnConn, &wg) + go cbnetwork.encapsulate(&wg) wg.Wait() + CBLogger.Debug("End.........") } -func (cbnetwork *CBNetwork) encapsulate(lstnConn *net.UDPConn, wg *sync.WaitGroup) { +func (cbnetwork *CBNetwork) encapsulate(wg *sync.WaitGroup) error { CBLogger.Debug("Start.........") defer wg.Done() packet := make([]byte, BUFFERSIZE) for { + // Read packet from the interface "cbnet0" plen, err := cbnetwork.Interface.Read(packet[:]) if err != nil { - CBLogger.Error("Error Read() in encapsulation:", err) - return + CBLogger.Error("Error Read() in encapsulation: ", err) + return err } // Parse header @@ -498,16 +500,16 @@ func (cbnetwork *CBNetwork) encapsulate(lstnConn *net.UDPConn, wg *sync.WaitGrou } // Send packet - nWriteToUDP, errWriteToUDP := lstnConn.WriteToUDP(bufToWrite, remoteAddr) + nWriteToUDP, errWriteToUDP := cbnetwork.listenConnection.WriteToUDP(bufToWrite, remoteAddr) if errWriteToUDP != nil || nWriteToUDP == 0 { CBLogger.Errorf("Error(%d len): %s", nWriteToUDP, errWriteToUDP) } } + // CBLogger.Debug("End.........") } - // CBLogger.Debug("End.........") } -func (cbnetwork *CBNetwork) decapsulate(lstnConn *net.UDPConn, wg *sync.WaitGroup) { +func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error { CBLogger.Debug("Start.........") defer wg.Done() @@ -515,10 +517,10 @@ func (cbnetwork *CBNetwork) decapsulate(lstnConn *net.UDPConn, wg *sync.WaitGrou buf := make([]byte, BUFFERSIZE) for { // ReadFromUDP acts like ReadFrom but returns a UDPAddr. - n, addr, err := lstnConn.ReadFromUDP(buf) + n, addr, err := cbnetwork.listenConnection.ReadFromUDP(buf) if err != nil { CBLogger.Error("Error in cbnetwork.listenConnection.ReadFromUDP(buf): ", err) - return + return err } CBLogger.Tracef("[Decapsulation] Received %d bytes from %v", n, addr) @@ -553,19 +555,28 @@ func (cbnetwork *CBNetwork) decapsulate(lstnConn *net.UDPConn, wg *sync.WaitGrou if errWrite != nil || nWrite == 0 { CBLogger.Errorf("Error(%d len): %s", nWrite, errWrite) } + } // CBLogger.Debug("End.........") } -// Shutdown represents a function to stop the cloud-barista network. -func (cbnetwork *CBNetwork) Shutdown() { +// Stop represents a function to stop the cloud-barista network. +func (cbnetwork *CBNetwork) Stop() { CBLogger.Debug("Start.........") // [To be improved] Stop tunneling routines // Currently just return func() when an error occur + CBLogger.Debug("close the listen connection") + cbnetwork.listenConnection.Close() + + CBLogger.Debugf("down interface (%s)", cbnetwork.name) cbnetwork.runIP("link", "set", "dev", cbnetwork.name, "down") + + CBLogger.Debug("close interface") cbnetwork.Interface.Close() + + CBLogger.Debug("set flag (isInterfaceConfigured) false") cbnetwork.isInterfaceConfigured = false CBLogger.Debug("End.........") From 4ce7f8a7d350d67e5234d15497644052b9dba1d4 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Mon, 21 Mar 2022 17:39:32 +0900 Subject: [PATCH 2/9] Track the status of cb-network agents - Add `suspending` status - Shutdown gracefully by signals --- poc-cb-net/cmd/agent/agent.go | 35 +++++++++++++++++--- poc-cb-net/internal/cb-network/model/peer.go | 3 ++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 817b045..2bcf09d 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -6,9 +6,11 @@ import ( "fmt" "os" "os/exec" + "os/signal" "path/filepath" "strings" "sync" + "syscall" "time" cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network" @@ -72,7 +74,7 @@ func init() { } // Control the cb-network agent by commands from remote -func watchControlCommand(etcdClient *clientv3.Client, wg *sync.WaitGroup) { +func watchControlCommand(ctx context.Context, etcdClient *clientv3.Client, wg *sync.WaitGroup) { CBLogger.Debug("Start.........") defer wg.Done() @@ -83,7 +85,7 @@ func watchControlCommand(etcdClient *clientv3.Client, wg *sync.WaitGroup) { // Watch "/registry/cloud-adaptive-network/control-command/{cladnet-id}/{host-id} keyControlCommand := fmt.Sprint(etcdkey.ControlCommand + "/" + cladnetID + "/" + hostID) CBLogger.Tracef("Watch \"%v\"", keyControlCommand) - watchChan1 := etcdClient.Watch(context.TODO(), keyControlCommand) + watchChan1 := etcdClient.Watch(ctx, keyControlCommand) for watchResponse := range watchChan1 { for _, event := range watchResponse.Events { CBLogger.Tracef("Watch - %s %q : %q", event.Type, event.Kv.Key, event.Kv.Value) @@ -93,7 +95,7 @@ func watchControlCommand(etcdClient *clientv3.Client, wg *sync.WaitGroup) { handleCommand(controlCommand, controlCommandOption, etcdClient) } } - CBLogger.Debug("Start.........") + CBLogger.Debug("End.........") } // Handle commands of the cb-network agent @@ -104,8 +106,9 @@ func handleCommand(command string, commandOption string, etcdClient *clientv3.Cl CBLogger.Tracef("CommandOption: %+v", commandOption) switch command { case "suspend": - updatePeerState(model.Suspended, etcdClient) + updatePeerState(model.Suspending, etcdClient) CBNet.Stop() + updatePeerState(model.Suspended, etcdClient) case "resume": // Start the cb-network @@ -526,11 +529,33 @@ func main() { // Enable encryption or not CBNet.EnableEncryption(config.CBNetwork.IsEncrypted) + // A context for graceful shutdown (It is based on the signal package) + // NOTE - + // Use os.Interrupt Ctrl+C or Ctrl+Break on Windows + // Use syscall.KILL for Kill(can't be caught or ignored) (POSIX) + // Use syscall.SIGTERM for Termination (ANSI) + // Use syscall.SIGINT for Terminal interrupt (ANSI) + // Use syscall.SIGQUIT for Terminal quit (POSIX) + gracefulShutdownContext, stop := signal.NotifyContext(context.TODO(), + os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) + defer stop() + + go func() { + // Block until a signal is triggered + <-gracefulShutdownContext.Done() + + fmt.Println("Tasks before shutting down") + // Set this agent status "suspended" + updatePeerState(model.Suspended, etcdClient) + + stop() + }() + // Wait for multiple goroutines to complete var wg sync.WaitGroup wg.Add(1) - go watchControlCommand(etcdClient, &wg) + go watchControlCommand(gracefulShutdownContext, etcdClient, &wg) // Sleep until the all routines are ready time.Sleep(2 * time.Second) diff --git a/poc-cb-net/internal/cb-network/model/peer.go b/poc-cb-net/internal/cb-network/model/peer.go index b2c11c1..27817b0 100644 --- a/poc-cb-net/internal/cb-network/model/peer.go +++ b/poc-cb-net/internal/cb-network/model/peer.go @@ -4,6 +4,9 @@ const ( // Running is const for the running state Running = "running" + // Suspending is const for the suspended state + Suspending = "suspending" + // Suspended is const for the suspended state Suspended = "suspended" ) From d3313eee5ae790969db53c95f134a9ae000a5c05 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" <7975459+yunkon-kim@users.noreply.github.com> Date: Tue, 22 Mar 2022 16:01:58 +0900 Subject: [PATCH 3/9] Update 1.setup-environment-and-tools.sh --- .../1.setup-environment-and-tools.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/Kubernetes/1.setup-environment-and-tools.sh b/scripts/Kubernetes/1.setup-environment-and-tools.sh index 8257b83..537d30f 100644 --- a/scripts/Kubernetes/1.setup-environment-and-tools.sh +++ b/scripts/Kubernetes/1.setup-environment-and-tools.sh @@ -38,14 +38,14 @@ echo "sudo apt update -y" sleep 1 sudo apt update -y -# Upgrade apt package considering dependencies -echo -echo ================================================= -echo == Upgrade apt package considering dependencies -echo ================================================= -echo "sudo DEBIAN_FRONTEND=noninteractive apt dist-upgrade -y" -sleep 1 -sudo DEBIAN_FRONTEND=noninteractive apt dist-upgrade -y +## Upgrade apt package considering dependencies +#echo +#echo ================================================= +#echo == Upgrade apt package considering dependencies +#echo ================================================= +#echo "sudo DEBIAN_FRONTEND=noninteractive apt dist-upgrade -y" +#sleep 1 +#sudo DEBIAN_FRONTEND=noninteractive apt dist-upgrade -y # Install apt-utils echo ================================================= @@ -132,4 +132,4 @@ sudo systemctl restart docker echo "!!! Please reboot !!!" echo "!!! Please reboot !!!" -echo "!!! Please reboot !!!" \ No newline at end of file +echo "!!! Please reboot !!!" From 3c5ad0f7337118ffe4793a937bb212d02f6d9c7e Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Tue, 22 Mar 2022 19:32:34 +0900 Subject: [PATCH 4/9] Improve the cb-network agent state tracking - Add `configuring` state - Add `syscall.SIGHUP` and `syscall.SIGABRT` for graceful shutdown - Update graceful shutdown processes --- poc-cb-net/cmd/agent/agent.go | 18 +++++++++++++++--- poc-cb-net/cmd/controller/controller.go | 2 +- poc-cb-net/internal/cb-network/model/peer.go | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 2bcf09d..270f998 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -264,8 +264,13 @@ func initializeAgent(etcdClient *clientv3.Client) { } func updatePeerState(state string, etcdClient *clientv3.Client) { + CBLogger.Debug("Start.........") idx := CBNet.NetworkingRule.GetIndexOfHostID(CBNet.HostID) + if idx == -1 { + CBLogger.Errorf("could not find '%s'", CBNet.HostID) + return + } peer := &model.Peer{ CLADNetID: CBNet.NetworkingRule.CLADNetID, @@ -284,6 +289,8 @@ func updatePeerState(state string, etcdClient *clientv3.Client) { if _, err := etcdClient.Put(context.TODO(), keyNetworkingRuleOfPeer, string(doc)); err != nil { CBLogger.Error(err) } + + CBLogger.Debug("End.........") } func watchSecret(etcdClient *clientv3.Client) { @@ -536,19 +543,24 @@ func main() { // Use syscall.SIGTERM for Termination (ANSI) // Use syscall.SIGINT for Terminal interrupt (ANSI) // Use syscall.SIGQUIT for Terminal quit (POSIX) + // Use syscall.SIGHUP for Hangup (POSIX) + // Use syscall.SIGABRT for Abort (POSIX) gracefulShutdownContext, stop := signal.NotifyContext(context.TODO(), - os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) + os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT) defer stop() go func() { // Block until a signal is triggered <-gracefulShutdownContext.Done() - fmt.Println("Tasks before shutting down") + // Stop this cb-network agent + fmt.Println("[Stop] cb-network agent") + CBNet.Stop() // Set this agent status "suspended" updatePeerState(model.Suspended, etcdClient) - stop() + // Wait for a while + time.Sleep(1 * time.Second) }() // Wait for multiple goroutines to complete diff --git a/poc-cb-net/cmd/controller/controller.go b/poc-cb-net/cmd/controller/controller.go index 0f78698..f80c227 100644 --- a/poc-cb-net/cmd/controller/controller.go +++ b/poc-cb-net/cmd/controller/controller.go @@ -210,7 +210,7 @@ func watchHostNetworkInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client PrivateIPv4Network: hostIPv4Network, PrivateIPv4Address: hostIPAddress, PublicIPv4Address: hostNetworkInformation.PublicIP, - State: model.Suspended, + State: model.Configuring, } } else { // Update the host's configuration diff --git a/poc-cb-net/internal/cb-network/model/peer.go b/poc-cb-net/internal/cb-network/model/peer.go index 27817b0..38dac12 100644 --- a/poc-cb-net/internal/cb-network/model/peer.go +++ b/poc-cb-net/internal/cb-network/model/peer.go @@ -4,11 +4,14 @@ const ( // Running is const for the running state Running = "running" - // Suspending is const for the suspended state + // Suspending is const for the suspending state Suspending = "suspending" // Suspended is const for the suspended state Suspended = "suspended" + + // Configuring is const for the configuring state + Configuring = "configuring" ) // Peer represents a host's rule of the cloud adaptive network. From ab774e4f72fe877c97be9df50d00be715a79f49c Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Wed, 23 Mar 2022 17:40:11 +0900 Subject: [PATCH 5/9] Containerize components of the cb-network control plane - Create Dockerfiles - Change ports, 8088 -> 8052, 8089 -> 8053, 9999 -> 8054, 20000 -> 8055 --- Dockerfile-admin-web | 41 +++++++++++++++ Dockerfile-cladnet-service | 38 ++++++++++++++ Dockerfile => Dockerfile-controller | 11 ++-- poc-cb-net/README.KR.md | 50 +++++++++---------- poc-cb-net/README.md | 50 +++++++++---------- poc-cb-net/cmd/admin-web/admin-web.go | 19 +++---- poc-cb-net/cmd/agent/agent.go | 2 +- .../test-client/config/template-config.yaml | 10 ++-- poc-cb-net/cmd/test-client/demo-client.go | 2 +- poc-cb-net/config/template-config.yaml | 10 ++-- .../internal/cb-network/model/config.go | 2 +- .../scripts/1.deploy-cb-network-agent.sh | 10 ++-- .../scripts/2.re-deploy-cb-network-agent.sh | 10 ++-- .../build-and-run-agent-in-the-background.sh | 10 ++-- poc-cb-net/scripts/build-and-run-agent.sh | 10 ++-- poc-cb-net/scripts/get-and-run-agent.sh | 10 ++-- poc-cb-net/web/public/index.html | 6 +-- 17 files changed, 184 insertions(+), 107 deletions(-) create mode 100644 Dockerfile-admin-web create mode 100644 Dockerfile-cladnet-service rename Dockerfile => Dockerfile-controller (81%) diff --git a/Dockerfile-admin-web b/Dockerfile-admin-web new file mode 100644 index 0000000..6c28898 --- /dev/null +++ b/Dockerfile-admin-web @@ -0,0 +1,41 @@ +## This is a Dockerfile for cb-network admin-web + +############################################################## +## Stage 1 - Go Build +############################################################## + +FROM golang:1.17 AS builder + +ENV GO111MODULE=on + +COPY . /cb-larva + +WORKDIR /cb-larva/poc-cb-net/cmd/admin-web/ + +# Build the admin-web +# Note - Using cgo write normal Go code that imports a pseudo-package "C". I may not need on cross-compiling. +# Note - You can find possible platforms by 'go tool dist list' for GOOS and GOARCH +# Note - Using the -ldflags parameter can help set variable values at compile time. +# Note - Using the -s and -w linker flags can strip the debugging information. +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o admin-web + +############################################################# +## Stage 2 - Application Setup +############################################################## + +FROM alpine:latest + +WORKDIR /app + +RUN mkdir -p config +RUN mkdir -p web + +# Copy the execution file +COPY --from=builder /cb-larva/poc-cb-net/cmd/admin-web/admin-web . +# Copy the web files of the admin-web +COPY --from=builder /cb-larva/poc-cb-net/web/ ./web/ + +# Ports for the cb-network admin-web +EXPOSE 8054 + +ENTRYPOINT ["./admin-web"] diff --git a/Dockerfile-cladnet-service b/Dockerfile-cladnet-service new file mode 100644 index 0000000..51dd69f --- /dev/null +++ b/Dockerfile-cladnet-service @@ -0,0 +1,38 @@ +## This is a Dockerfile for cb-network cladnet-service + +############################################################## +## Stage 1 - Go Build +############################################################## + +FROM golang:1.17 AS builder + +ENV GO111MODULE=on + +COPY . /cb-larva + +WORKDIR /cb-larva/poc-cb-net/cmd/service/ + +# Build the cladnet-service +# Note - Using cgo write normal Go code that imports a pseudo-package "C". I may not need on cross-compiling. +# Note - You can find possible platforms by 'go tool dist list' for GOOS and GOARCH +# Note - Using the -ldflags parameter can help set variable values at compile time. +# Note - Using the -s and -w linker flags can strip the debugging information. +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o cladnet-service + +############################################################# +## Stage 2 - Application Setup +############################################################## + +FROM alpine:latest + +WORKDIR /app + +RUN mkdir -p config + +# Copy the execution file +COPY --from=builder /cb-larva/poc-cb-net/cmd/service/cladnet-service . + +# Ports for the cb-network cladnet-service +EXPOSE 8053 + +ENTRYPOINT ["./cladnet-service"] diff --git a/Dockerfile b/Dockerfile-controller similarity index 81% rename from Dockerfile rename to Dockerfile-controller index 84f645b..a9e12ba 100644 --- a/Dockerfile +++ b/Dockerfile-controller @@ -4,13 +4,13 @@ ## Stage 1 - Go Build ############################################################## -FROM golang:1.15.3 AS builder +FROM golang:1.17 AS builder ENV GO111MODULE=on COPY . /cb-larva -WORKDIR /cb-larva/poc-cb-net/cmd/controller/ +WORKDIR /cb-larva/poc-cb-net/cmd/controller # Build the controller # Note - Using cgo write normal Go code that imports a pseudo-package "C". I may not need on cross-compiling. @@ -28,14 +28,11 @@ FROM alpine:latest WORKDIR /app RUN mkdir -p config -RUN mkdir -p web # Copy the execution file COPY --from=builder /cb-larva/poc-cb-net/cmd/controller/controller . -# Copy the web files of AdminWeb -COPY --from=builder /cb-larva/poc-cb-net/web/ ./web/ -# A port of Admin Web for the cb-network controller -EXPOSE 9999 +# ports for the cb-network controller +# EXPOSE 8051 ENTRYPOINT ["./controller"] diff --git a/poc-cb-net/README.KR.md b/poc-cb-net/README.KR.md index b13c604..b276ae0 100644 --- a/poc-cb-net/README.KR.md +++ b/poc-cb-net/README.KR.md @@ -144,10 +144,10 @@ git checkout tags/v3.5.0 -b v3.5.0 etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -157,9 +157,9 @@ git checkout tags/v3.5.0 -b v3.5.0 # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -224,10 +224,10 @@ sudo ./controller etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -237,9 +237,9 @@ sudo ./controller # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -304,10 +304,10 @@ sudo ./cladnet-service etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -317,9 +317,9 @@ sudo ./cladnet-service # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -385,10 +385,10 @@ sudo ./admin-web etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -398,9 +398,9 @@ sudo ./admin-web # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -475,10 +475,10 @@ sudo ./agent etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -488,9 +488,9 @@ sudo ./agent # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` diff --git a/poc-cb-net/README.md b/poc-cb-net/README.md index 87b1388..3a1a523 100644 --- a/poc-cb-net/README.md +++ b/poc-cb-net/README.md @@ -143,10 +143,10 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -156,9 +156,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -223,10 +223,10 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -236,9 +236,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -303,10 +303,10 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -316,9 +316,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -383,10 +383,10 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -396,9 +396,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` @@ -474,10 +474,10 @@ If it is running on another node, it is required to modify source code (related etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] - # A config for the cb-network AdminWeb as follows: + # A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -487,9 +487,9 @@ If it is running on another node, it is required to modify source code (related # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" ``` diff --git a/poc-cb-net/cmd/admin-web/admin-web.go b/poc-cb-net/cmd/admin-web/admin-web.go index 44bf966..7cce2c0 100644 --- a/poc-cb-net/cmd/admin-web/admin-web.go +++ b/poc-cb-net/cmd/admin-web/admin-web.go @@ -100,7 +100,7 @@ func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c return t.templates.ExecuteTemplate(w, name, data) } -// WebsocketHandler represents a handler to watch and send networking rules to AdminWeb frontend. +// WebsocketHandler represents a handler to watch and send networking rules to admin-web frontend. func WebsocketHandler(c echo.Context) error { ws, err := upgrader.Upgrade(c.Response(), c.Request(), nil) if err != nil { @@ -319,13 +319,13 @@ func getExistingNetworkInfo(etcdClient *clientv3.Client) error { for _, kv := range resp.Kvs { CBLogger.Tracef("CLADNet ID: %v", kv.Key) CBLogger.Tracef("The networking rule of the CLADNet: %v", kv.Value) - CBLogger.Debug("Send a networking rule of CLADNet to AdminWeb frontend") + CBLogger.Debug("Send a networking rule of CLADNet to admin-web frontend") // Build the response bytes of a networking rule responseBytes := buildResponseBytes("peer", string(kv.Value)) // Send the networking rule to the front-end - CBLogger.Debug("Send the networking rule to AdminWeb frontend") + CBLogger.Debug("Send the networking rule to admin-web frontend") sendErr := sendMessageToAllPool(responseBytes) if sendErr != nil { CBLogger.Error(sendErr) @@ -364,7 +364,7 @@ func getExistingNetworkInfo(etcdClient *clientv3.Client) error { responseBytes := buildResponseBytes("CLADNetList", buf.String()) // Send the CLADNet list to the front-end - CBLogger.Debug("Send the CLADNet list to AdminWeb frontend") + CBLogger.Debug("Send the CLADNet list to admin-web frontend") sendErr := sendMessageToAllPool(responseBytes) if sendErr != nil { CBLogger.Error(sendErr) @@ -458,10 +458,11 @@ func RunEchoServer(wg *sync.WaitGroup, config model.Config) { // Render e.GET("/ws", WebsocketHandler) - adminWebURL := fmt.Sprintf("The cb-network admin-web URL => http://%s:%s\n", config.AdminWeb.Host, config.AdminWeb.Port) + adminWebURL := fmt.Sprintf("==> http://%s:%s\n", config.AdminWeb.Host, config.AdminWeb.Port) fmt.Println("") - fmt.Printf("\033[1;36m%s\033[0m", adminWebURL) + fmt.Printf("\033[1;36m%s\033[0m", "[The cb-network admin-web URL]") + fmt.Printf("\033[1;36m% s\033[0m", adminWebURL) fmt.Println("") e.Logger.Fatal(e.Start(":" + config.AdminWeb.Port)) @@ -487,7 +488,7 @@ func watchNetworkingRule(wg *sync.WaitGroup, etcdClient *clientv3.Client) { responseBytes := buildResponseBytes("peer", string(peer)) // Send the networking rule to the front-end - CBLogger.Debug("Send the networking rule to AdminWeb frontend") + CBLogger.Debug("Send the networking rule to admin-web frontend") sendErr := sendMessageToAllPool(responseBytes) if sendErr != nil { CBLogger.Error(sendErr) @@ -541,7 +542,7 @@ func watchCLADNetSpecification(wg *sync.WaitGroup, etcdClient *clientv3.Client) responseBytes := buildResponseBytes("CLADNetList", buf.String()) // Send the CLADNet list to the front-end - CBLogger.Debug("Send the CLADNet list to AdminWeb frontend") + CBLogger.Debug("Send the CLADNet list to admin-web frontend") sendErr := sendMessageToAllPool(responseBytes) if sendErr != nil { CBLogger.Error(sendErr) @@ -572,7 +573,7 @@ func watchStatusInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client) { responseBytes := buildResponseBytes("NetworkStatus", string(status)) // Send the networking rule to the front-end - CBLogger.Debug("Send the status to AdminWeb frontend") + CBLogger.Debug("Send the status to admin-web frontend") sendErr := sendMessageToAllPool(responseBytes) if sendErr != nil { CBLogger.Error(sendErr) diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 270f998..33212d0 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -529,7 +529,7 @@ func main() { } // Create CBNetwork instance with port, which is a tunneling port - CBNet = cbnet.New("cbnet0", 20000) + CBNet = cbnet.New("cbnet0", 8055) CBNet.ID = cladnetID CBNet.HostID = hostID diff --git a/poc-cb-net/cmd/test-client/config/template-config.yaml b/poc-cb-net/cmd/test-client/config/template-config.yaml index cd3283c..5cb8456 100644 --- a/poc-cb-net/cmd/test-client/config/template-config.yaml +++ b/poc-cb-net/cmd/test-client/config/template-config.yaml @@ -2,10 +2,10 @@ etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -15,6 +15,6 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "localhost:8053" + server_port: "8053" + gateway_port: "8052" diff --git a/poc-cb-net/cmd/test-client/demo-client.go b/poc-cb-net/cmd/test-client/demo-client.go index c9b5662..81026bd 100644 --- a/poc-cb-net/cmd/test-client/demo-client.go +++ b/poc-cb-net/cmd/test-client/demo-client.go @@ -573,7 +573,7 @@ func main() { start := time.Now() // Dummy data to test - gRPCServiceEndpoint := "localhost:8089" + gRPCServiceEndpoint := "localhost:8053" // dummyIPNetworks := []string{"10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16", "172.16.1.0/24", "172.16.2.0/24", "172.16.3.0/24", "172.16.4.0/24", "172.16.5.0/24", "172.16.6.0/24", "192.168.1.0/28", "192.168.2.0/28", "192.168.3.0/28", "192.168.4.0/28", "192.168.5.0/28", "192.168.6.0/28", "192.168.7.0/28"} cladnetName := "CLADNet01" diff --git a/poc-cb-net/config/template-config.yaml b/poc-cb-net/config/template-config.yaml index 42727b5..02ea54b 100644 --- a/poc-cb-net/config/template-config.yaml +++ b/poc-cb-net/config/template-config.yaml @@ -2,10 +2,10 @@ etcd_cluster: endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "xxx.xxx.xxx.xxx" # e.g., "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -15,6 +15,6 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "xxx.xxx.xxx.xxx:8089" # e.g., "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" + server_port: "8053" + gateway_port: "8052" diff --git a/poc-cb-net/internal/cb-network/model/config.go b/poc-cb-net/internal/cb-network/model/config.go index 26288f5..8b7d2e9 100644 --- a/poc-cb-net/internal/cb-network/model/config.go +++ b/poc-cb-net/internal/cb-network/model/config.go @@ -16,7 +16,7 @@ type ETCDConfig struct { // A config for the cb-network controller as follows: -// AdminWebConfig represents the configuration information for a AdminWeb +// admin-webConfig represents the configuration information for a AdminWeb type AdminWebConfig struct { Host string `yaml:"host"` Port string `yaml:"port"` diff --git a/poc-cb-net/scripts/1.deploy-cb-network-agent.sh b/poc-cb-net/scripts/1.deploy-cb-network-agent.sh index 1d180c7..15f7af7 100644 --- a/poc-cb-net/scripts/1.deploy-cb-network-agent.sh +++ b/poc-cb-net/scripts/1.deploy-cb-network-agent.sh @@ -53,10 +53,10 @@ cat <./config.yaml etcd_cluster: endpoints: ${REFINED_ETCD_HOSTS} -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -66,9 +66,9 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "localhost:8053" + server_port: "8053" + gateway_port: "8052" EOF diff --git a/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh b/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh index 15995bd..b048cbc 100644 --- a/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh +++ b/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh @@ -60,10 +60,10 @@ cat <./config.yaml etcd_cluster: endpoints: ${REFINED_ETCD_HOSTS} -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -73,9 +73,9 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "localhost:8053" + server_port: "8053" + gateway_port: "8052" EOF diff --git a/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh b/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh index cce1520..977743c 100644 --- a/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh +++ b/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh @@ -103,10 +103,10 @@ cat <./config.yaml etcd_cluster: endpoints: ${REFINED_ETCD_HOSTS} -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -115,9 +115,9 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "localhost:8053" + server_port: "8053" + gateway_port: "8052" EOF diff --git a/poc-cb-net/scripts/build-and-run-agent.sh b/poc-cb-net/scripts/build-and-run-agent.sh index d39a713..f28ef11 100644 --- a/poc-cb-net/scripts/build-and-run-agent.sh +++ b/poc-cb-net/scripts/build-and-run-agent.sh @@ -103,10 +103,10 @@ cat <./config.yaml etcd_cluster: endpoints: ${REFINED_ETCD_HOSTS} -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -115,9 +115,9 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "localhost:8053" + server_port: "8053" + gateway_port: "8052" EOF diff --git a/poc-cb-net/scripts/get-and-run-agent.sh b/poc-cb-net/scripts/get-and-run-agent.sh index b242df7..942d637 100644 --- a/poc-cb-net/scripts/get-and-run-agent.sh +++ b/poc-cb-net/scripts/get-and-run-agent.sh @@ -53,10 +53,10 @@ cat <./config.yaml etcd_cluster: endpoints: ${REFINED_ETCD_HOSTS} -# A config for the cb-network AdminWeb as follows: +# A config for the cb-network admin-web as follows: admin_web: host: "localhost" - port: "9999" + port: "8054" # A config for the cb-network agent as follows: cb_network: @@ -65,9 +65,9 @@ cb_network: # A config for the grpc as follows: grpc: - service_endpoint: "localhost:8089" - server_port: "8089" - gateway_port: "8088" + service_endpoint: "localhost:8053" + server_port: "8053" + gateway_port: "8052" EOF diff --git a/poc-cb-net/web/public/index.html b/poc-cb-net/web/public/index.html index 7b7b321..8a35c1f 100644 --- a/poc-cb-net/web/public/index.html +++ b/poc-cb-net/web/public/index.html @@ -86,9 +86,9 @@ @@ -275,7 +275,7 @@

Status chart

console.log("JSON String of dataFrame:"); console.log(dataframeStr); - // Send those to the AdminWeb server + // Send those to the admin-web server ws.send(dataframeStr); } From e5ecd4b3aa524c37c680858eb9252092a01292d3 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Wed, 23 Mar 2022 22:40:26 +0900 Subject: [PATCH 6/9] Add `docker-compose` to deploy the cb-network control plane - Add and test 'docker-compose` - Add 'container-volume/' to `.gitignore` - Display several URLs to access admin-web --- .gitignore | 3 + docker-compose.yaml | 90 +++++++++++++++++++++++++++ poc-cb-net/cmd/admin-web/admin-web.go | 24 ++++--- 3 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yaml diff --git a/.gitignore b/.gitignore index 6baf2e5..d08212f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ .idea/ .vscode/ +# Temporal directory for container volumes +container-volume/ + # Ignore configuration directory # to avoid leaking sensitive information and frequent update poc-cb-net/config/** diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f5b3915 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,90 @@ +version: "3.3" +services: + cb-network-etcd: + image: gcr.io/etcd-development/etcd:v3.5.2 + container_name: etcd-gcr-v3.5.2 + ports: + - "2379:2379" + - "2380:2380" + volumes: + - ./container-volume/etcd/data:/etcd-data + entrypoint: + - /usr/local/bin/etcd + - --name + - s1 + - --data-dir + - /etcd-data + - --listen-client-urls + - http://0.0.0.0:2379 + - --advertise-client-urls + - http://0.0.0.0:2379 + - --listen-peer-urls + - http://0.0.0.0:2380 + - --initial-advertise-peer-urls + - http://0.0.0.0:2380 + - --initial-cluster + - s1=http://0.0.0.0:2380 + - --initial-cluster-token + - tkn + - --initial-cluster-state + - new + - --log-level + - info + - --logger + - zap + - --log-outputs + - stderr + healthcheck: + test: /usr/local/bin/etcd --version + interval: 2s + timeout: 5s + retries: 3 + + cb-network-controller: + image: cloudbaristaorg/cb-network-controller:latest + build: + context: . + dockerfile: Dockerfile-controller + container_name: cb-network-controller + network_mode: "host" + volumes: + - ./container-volume/cb-network/config:/app/config + depends_on: + cb-network-etcd: + condition: service_healthy + + cb-network-cladnet-service: + image: cloudbaristaorg/cb-network-cladnet-service:latest + build: + context: . + dockerfile: Dockerfile-cladnet-service + container_name: cb-network-cladnet-service + ports: + - "8053:8053" + volumes: + - ./container-volume/cb-network/config:/app/config + depends_on: + cb-network-etcd: + condition: service_healthy + healthcheck: + test: nc -vz localhost 8053 + interval: 2s + timeout: 5s + retries: 3 + + + cb-network-admin-web: + image: cloudbaristaorg/cb-network-admin-web:latest + build: + context: . + dockerfile: Dockerfile-admin-web + container_name: cb-network-admin-web + ports: + - "8054:8054" + volumes: + - ./container-volume/cb-network/config:/app/config + depends_on: + cb-network-etcd: + condition: service_healthy + cb-network-cladnet-service: + condition: service_healthy diff --git a/poc-cb-net/cmd/admin-web/admin-web.go b/poc-cb-net/cmd/admin-web/admin-web.go index 7cce2c0..0a0242b 100644 --- a/poc-cb-net/cmd/admin-web/admin-web.go +++ b/poc-cb-net/cmd/admin-web/admin-web.go @@ -16,6 +16,7 @@ import ( "sync" "time" + cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network" model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" cmd "github.com/cloud-barista/cb-larva/poc-cb-net/internal/command" etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" @@ -39,7 +40,7 @@ var config model.Config var cladnetClient pb.CloudAdaptiveNetworkServiceClient func init() { - fmt.Println("Start......... init() of controller.go") + fmt.Println("Start......... init() of admin-web.go") ex, err := os.Executable() if err != nil { panic(err) @@ -76,7 +77,7 @@ func init() { } config, _ = model.LoadConfig(configPath) CBLogger.Debugf("Load %v", configPath) - fmt.Println("End......... init() of controller.go") + fmt.Println("End......... init() of admin-web.go") } var ( @@ -458,11 +459,20 @@ func RunEchoServer(wg *sync.WaitGroup, config model.Config) { // Render e.GET("/ws", WebsocketHandler) - adminWebURL := fmt.Sprintf("==> http://%s:%s\n", config.AdminWeb.Host, config.AdminWeb.Port) + CBNet := cbnet.New("temp", 0) + + adminWebURL := fmt.Sprintf("http://%s:%s", config.AdminWeb.Host, config.AdminWeb.Port) + localhostURL := fmt.Sprintf("http://%s:%s", "localhost", config.AdminWeb.Port) + publicAccessURL := fmt.Sprintf("http://%s:%s", CBNet.HostPublicIP, config.AdminWeb.Port) fmt.Println("") - fmt.Printf("\033[1;36m%s\033[0m", "[The cb-network admin-web URL]") - fmt.Printf("\033[1;36m% s\033[0m", adminWebURL) + fmt.Printf("\033[1;36m%s\033[0m\n", "[The cb-network admin-web URLs]") + fmt.Printf("\033[1;36m ==> %s (set in 'config.yaml')\033[0m\n", adminWebURL) + fmt.Printf("\033[1;36m ==> %s (may need to check firewall rule)\033[0m\n", publicAccessURL) + if config.AdminWeb.Host != "localhost" { + fmt.Printf("\033[1;36m ==> %s\033[0m\n", localhostURL) + } + fmt.Println("") e.Logger.Fatal(e.Start(":" + config.AdminWeb.Port)) @@ -584,7 +594,7 @@ func watchStatusInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client) { } func main() { - CBLogger.Debug("Start cb-network controller .........") + CBLogger.Debug("Start cb-network admin-web .........") // Wait for multiple goroutines to complete var wg sync.WaitGroup @@ -642,5 +652,5 @@ func main() { wg.Wait() - CBLogger.Debug("End cb-network controller .........") + CBLogger.Debug("End cb-network admin-web .........") } From 6ac7628edf646e1d3f4e222150c2ffaec99fb6d3 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Thu, 24 Mar 2022 18:12:40 +0900 Subject: [PATCH 7/9] Expose `cbnet` package - Replace `internal` to `pkg` --- poc-cb-net/cmd/admin-web/admin-web.go | 4 ++-- poc-cb-net/cmd/agent/agent.go | 4 ++-- poc-cb-net/cmd/controller/controller.go | 2 +- poc-cb-net/cmd/service/cladnet-service.go | 2 +- poc-cb-net/cmd/test-client/demo-client.go | 2 +- poc-cb-net/{internal => pkg}/cb-network/cb-network.go | 2 +- .../cb-network/dynamic-subnet-configuration.go | 2 +- .../cb-network/model/cladnet-specification.go | 0 poc-cb-net/{internal => pkg}/cb-network/model/config.go | 2 +- .../cb-network/model/host-network-information.go | 0 .../{internal => pkg}/cb-network/model/network-interface.go | 0 .../{internal => pkg}/cb-network/model/network-status.go | 0 .../{internal => pkg}/cb-network/model/networking-rule.go | 0 poc-cb-net/{internal => pkg}/cb-network/model/peer.go | 0 .../cb-network/model/websocket-message-frame.go | 0 15 files changed, 10 insertions(+), 10 deletions(-) rename poc-cb-net/{internal => pkg}/cb-network/cb-network.go (99%) rename poc-cb-net/{internal => pkg}/cb-network/dynamic-subnet-configuration.go (94%) rename poc-cb-net/{internal => pkg}/cb-network/model/cladnet-specification.go (100%) rename poc-cb-net/{internal => pkg}/cb-network/model/config.go (95%) rename poc-cb-net/{internal => pkg}/cb-network/model/host-network-information.go (100%) rename poc-cb-net/{internal => pkg}/cb-network/model/network-interface.go (100%) rename poc-cb-net/{internal => pkg}/cb-network/model/network-status.go (100%) rename poc-cb-net/{internal => pkg}/cb-network/model/networking-rule.go (100%) rename poc-cb-net/{internal => pkg}/cb-network/model/peer.go (100%) rename poc-cb-net/{internal => pkg}/cb-network/model/websocket-message-frame.go (100%) diff --git a/poc-cb-net/cmd/admin-web/admin-web.go b/poc-cb-net/cmd/admin-web/admin-web.go index 0a0242b..cafc7ef 100644 --- a/poc-cb-net/cmd/admin-web/admin-web.go +++ b/poc-cb-net/cmd/admin-web/admin-web.go @@ -16,12 +16,12 @@ import ( "sync" "time" - cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" cmd "github.com/cloud-barista/cb-larva/poc-cb-net/internal/command" etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" file "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" + cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" cblog "github.com/cloud-barista/cb-log" "github.com/gorilla/websocket" "github.com/labstack/echo" diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 33212d0..873f67b 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -13,11 +13,11 @@ import ( "syscall" "time" - cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" cmd "github.com/cloud-barista/cb-larva/poc-cb-net/internal/command" etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" + cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" cblog "github.com/cloud-barista/cb-log" "github.com/go-ping/ping" "github.com/sirupsen/logrus" diff --git a/poc-cb-net/cmd/controller/controller.go b/poc-cb-net/cmd/controller/controller.go index f80c227..ab4501f 100644 --- a/poc-cb-net/cmd/controller/controller.go +++ b/poc-cb-net/cmd/controller/controller.go @@ -14,9 +14,9 @@ import ( "sync" "time" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" file "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" cblog "github.com/cloud-barista/cb-log" "github.com/rs/xid" "github.com/sirupsen/logrus" diff --git a/poc-cb-net/cmd/service/cladnet-service.go b/poc-cb-net/cmd/service/cladnet-service.go index 3c560c2..8408ce6 100644 --- a/poc-cb-net/cmd/service/cladnet-service.go +++ b/poc-cb-net/cmd/service/cladnet-service.go @@ -13,11 +13,11 @@ import ( "strings" "time" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/internal/network-helper" pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" cblog "github.com/cloud-barista/cb-log" "github.com/golang/protobuf/ptypes/empty" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" diff --git a/poc-cb-net/cmd/test-client/demo-client.go b/poc-cb-net/cmd/test-client/demo-client.go index 81026bd..5dc7320 100644 --- a/poc-cb-net/cmd/test-client/demo-client.go +++ b/poc-cb-net/cmd/test-client/demo-client.go @@ -13,9 +13,9 @@ import ( "sync" "time" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" "github.com/go-resty/resty/v2" "github.com/tidwall/gjson" "google.golang.org/grpc" diff --git a/poc-cb-net/internal/cb-network/cb-network.go b/poc-cb-net/pkg/cb-network/cb-network.go similarity index 99% rename from poc-cb-net/internal/cb-network/cb-network.go rename to poc-cb-net/pkg/cb-network/cb-network.go index ff44ee3..5ba1769 100644 --- a/poc-cb-net/internal/cb-network/cb-network.go +++ b/poc-cb-net/pkg/cb-network/cb-network.go @@ -19,9 +19,9 @@ import ( "time" "unsafe" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" secutil "github.com/cloud-barista/cb-larva/poc-cb-net/internal/secret-util" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" cblog "github.com/cloud-barista/cb-log" "github.com/sirupsen/logrus" "golang.org/x/net/ipv4" diff --git a/poc-cb-net/internal/cb-network/dynamic-subnet-configuration.go b/poc-cb-net/pkg/cb-network/dynamic-subnet-configuration.go similarity index 94% rename from poc-cb-net/internal/cb-network/dynamic-subnet-configuration.go rename to poc-cb-net/pkg/cb-network/dynamic-subnet-configuration.go index ce12a2e..053017a 100644 --- a/poc-cb-net/internal/cb-network/dynamic-subnet-configuration.go +++ b/poc-cb-net/pkg/cb-network/dynamic-subnet-configuration.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - model "github.com/cloud-barista/cb-larva/poc-cb-net/internal/cb-network/model" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" ) // DynamicSubnetConfigurator represents a configurator for Dynamic Subnet Configuration Protocol diff --git a/poc-cb-net/internal/cb-network/model/cladnet-specification.go b/poc-cb-net/pkg/cb-network/model/cladnet-specification.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/cladnet-specification.go rename to poc-cb-net/pkg/cb-network/model/cladnet-specification.go diff --git a/poc-cb-net/internal/cb-network/model/config.go b/poc-cb-net/pkg/cb-network/model/config.go similarity index 95% rename from poc-cb-net/internal/cb-network/model/config.go rename to poc-cb-net/pkg/cb-network/model/config.go index 8b7d2e9..26288f5 100644 --- a/poc-cb-net/internal/cb-network/model/config.go +++ b/poc-cb-net/pkg/cb-network/model/config.go @@ -16,7 +16,7 @@ type ETCDConfig struct { // A config for the cb-network controller as follows: -// admin-webConfig represents the configuration information for a AdminWeb +// AdminWebConfig represents the configuration information for a AdminWeb type AdminWebConfig struct { Host string `yaml:"host"` Port string `yaml:"port"` diff --git a/poc-cb-net/internal/cb-network/model/host-network-information.go b/poc-cb-net/pkg/cb-network/model/host-network-information.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/host-network-information.go rename to poc-cb-net/pkg/cb-network/model/host-network-information.go diff --git a/poc-cb-net/internal/cb-network/model/network-interface.go b/poc-cb-net/pkg/cb-network/model/network-interface.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/network-interface.go rename to poc-cb-net/pkg/cb-network/model/network-interface.go diff --git a/poc-cb-net/internal/cb-network/model/network-status.go b/poc-cb-net/pkg/cb-network/model/network-status.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/network-status.go rename to poc-cb-net/pkg/cb-network/model/network-status.go diff --git a/poc-cb-net/internal/cb-network/model/networking-rule.go b/poc-cb-net/pkg/cb-network/model/networking-rule.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/networking-rule.go rename to poc-cb-net/pkg/cb-network/model/networking-rule.go diff --git a/poc-cb-net/internal/cb-network/model/peer.go b/poc-cb-net/pkg/cb-network/model/peer.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/peer.go rename to poc-cb-net/pkg/cb-network/model/peer.go diff --git a/poc-cb-net/internal/cb-network/model/websocket-message-frame.go b/poc-cb-net/pkg/cb-network/model/websocket-message-frame.go similarity index 100% rename from poc-cb-net/internal/cb-network/model/websocket-message-frame.go rename to poc-cb-net/pkg/cb-network/model/websocket-message-frame.go From 0887621fffc4a1a1bc066a2eb31e310945468743 Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Fri, 25 Mar 2022 10:26:46 +0900 Subject: [PATCH 8/9] Expose all packages related to poc-cb-net - Relocate from `/internal` to `/pkg` --- go.mod | 1 - go.sum | 2 -- poc-cb-net/cmd/admin-web/admin-web.go | 6 +++--- poc-cb-net/cmd/agent/agent.go | 6 +++--- poc-cb-net/cmd/controller/controller.go | 4 ++-- poc-cb-net/cmd/service/cladnet-service.go | 6 +++--- poc-cb-net/cmd/test-client/demo-client.go | 2 +- poc-cb-net/pkg/cb-network/cb-network.go | 4 ++-- poc-cb-net/pkg/cb-network/model/networking-rule.go | 2 +- poc-cb-net/{internal => pkg}/command/command.go | 0 poc-cb-net/{internal => pkg}/etcd-key/etcd-key.go | 0 poc-cb-net/{internal => pkg}/file/file.go | 0 .../{internal => pkg}/network-helper/network-helper.go | 0 poc-cb-net/{internal => pkg}/secret-util/secret-util.go | 2 +- 14 files changed, 16 insertions(+), 19 deletions(-) rename poc-cb-net/{internal => pkg}/command/command.go (100%) rename poc-cb-net/{internal => pkg}/etcd-key/etcd-key.go (100%) rename poc-cb-net/{internal => pkg}/file/file.go (100%) rename poc-cb-net/{internal => pkg}/network-helper/network-helper.go (100%) rename poc-cb-net/{internal => pkg}/secret-util/secret-util.go (99%) diff --git a/go.mod b/go.mod index 6e291af..8a8e8ea 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/rs/xid v1.3.0 github.com/sirupsen/logrus v1.8.1 github.com/tidwall/gjson v1.11.0 - go.etcd.io/etcd v3.3.27+incompatible go.etcd.io/etcd/api/v3 v3.5.0 go.etcd.io/etcd/client/v3 v3.5.0 golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d diff --git a/go.sum b/go.sum index 206d6dc..048d433 100644 --- a/go.sum +++ b/go.sum @@ -256,8 +256,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/etcd v3.3.27+incompatible h1:5hMrpf6REqTHV2LW2OclNpRtxI0k9ZplMemJsMSWju0= -go.etcd.io/etcd v3.3.27+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI= go.etcd.io/etcd/api/v3 v3.5.0 h1:GsV3S+OfZEOCNXdtNkBSR7kgLobAa/SO6tCxRa0GAYw= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0 h1:2aQv6F436YnN7I4VbI8PPYrBhu+SmrTaADcf8Mi/6PU= diff --git a/poc-cb-net/cmd/admin-web/admin-web.go b/poc-cb-net/cmd/admin-web/admin-web.go index cafc7ef..2be3c72 100644 --- a/poc-cb-net/cmd/admin-web/admin-web.go +++ b/poc-cb-net/cmd/admin-web/admin-web.go @@ -16,12 +16,12 @@ import ( "sync" "time" - cmd "github.com/cloud-barista/cb-larva/poc-cb-net/internal/command" - etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" - file "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + cmd "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/command" + etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/etcd-key" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" cblog "github.com/cloud-barista/cb-log" "github.com/gorilla/websocket" "github.com/labstack/echo" diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 873f67b..02a4d28 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -13,11 +13,11 @@ import ( "syscall" "time" - cmd "github.com/cloud-barista/cb-larva/poc-cb-net/internal/command" - etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" - "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" cbnet "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + cmd "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/command" + etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/etcd-key" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" cblog "github.com/cloud-barista/cb-log" "github.com/go-ping/ping" "github.com/sirupsen/logrus" diff --git a/poc-cb-net/cmd/controller/controller.go b/poc-cb-net/cmd/controller/controller.go index ab4501f..00600cf 100644 --- a/poc-cb-net/cmd/controller/controller.go +++ b/poc-cb-net/cmd/controller/controller.go @@ -14,9 +14,9 @@ import ( "sync" "time" - etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" - file "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/etcd-key" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" cblog "github.com/cloud-barista/cb-log" "github.com/rs/xid" "github.com/sirupsen/logrus" diff --git a/poc-cb-net/cmd/service/cladnet-service.go b/poc-cb-net/cmd/service/cladnet-service.go index 8408ce6..cde9e6b 100644 --- a/poc-cb-net/cmd/service/cladnet-service.go +++ b/poc-cb-net/cmd/service/cladnet-service.go @@ -13,11 +13,11 @@ import ( "strings" "time" - etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/internal/etcd-key" - "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" - nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/internal/network-helper" pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + etcdkey "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/etcd-key" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" + nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" cblog "github.com/cloud-barista/cb-log" "github.com/golang/protobuf/ptypes/empty" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" diff --git a/poc-cb-net/cmd/test-client/demo-client.go b/poc-cb-net/cmd/test-client/demo-client.go index 5dc7320..8363503 100644 --- a/poc-cb-net/cmd/test-client/demo-client.go +++ b/poc-cb-net/cmd/test-client/demo-client.go @@ -13,9 +13,9 @@ import ( "sync" "time" - "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" "github.com/go-resty/resty/v2" "github.com/tidwall/gjson" "google.golang.org/grpc" diff --git a/poc-cb-net/pkg/cb-network/cb-network.go b/poc-cb-net/pkg/cb-network/cb-network.go index 5ba1769..07d6c5d 100644 --- a/poc-cb-net/pkg/cb-network/cb-network.go +++ b/poc-cb-net/pkg/cb-network/cb-network.go @@ -19,9 +19,9 @@ import ( "time" "unsafe" - "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" - secutil "github.com/cloud-barista/cb-larva/poc-cb-net/internal/secret-util" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" + secutil "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/secret-util" cblog "github.com/cloud-barista/cb-log" "github.com/sirupsen/logrus" "golang.org/x/net/ipv4" diff --git a/poc-cb-net/pkg/cb-network/model/networking-rule.go b/poc-cb-net/pkg/cb-network/model/networking-rule.go index a999ce9..25b9a6d 100644 --- a/poc-cb-net/pkg/cb-network/model/networking-rule.go +++ b/poc-cb-net/pkg/cb-network/model/networking-rule.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" cblog "github.com/cloud-barista/cb-log" "github.com/sirupsen/logrus" ) diff --git a/poc-cb-net/internal/command/command.go b/poc-cb-net/pkg/command/command.go similarity index 100% rename from poc-cb-net/internal/command/command.go rename to poc-cb-net/pkg/command/command.go diff --git a/poc-cb-net/internal/etcd-key/etcd-key.go b/poc-cb-net/pkg/etcd-key/etcd-key.go similarity index 100% rename from poc-cb-net/internal/etcd-key/etcd-key.go rename to poc-cb-net/pkg/etcd-key/etcd-key.go diff --git a/poc-cb-net/internal/file/file.go b/poc-cb-net/pkg/file/file.go similarity index 100% rename from poc-cb-net/internal/file/file.go rename to poc-cb-net/pkg/file/file.go diff --git a/poc-cb-net/internal/network-helper/network-helper.go b/poc-cb-net/pkg/network-helper/network-helper.go similarity index 100% rename from poc-cb-net/internal/network-helper/network-helper.go rename to poc-cb-net/pkg/network-helper/network-helper.go diff --git a/poc-cb-net/internal/secret-util/secret-util.go b/poc-cb-net/pkg/secret-util/secret-util.go similarity index 99% rename from poc-cb-net/internal/secret-util/secret-util.go rename to poc-cb-net/pkg/secret-util/secret-util.go index 3f731c1..419d3a5 100644 --- a/poc-cb-net/internal/secret-util/secret-util.go +++ b/poc-cb-net/pkg/secret-util/secret-util.go @@ -14,7 +14,7 @@ import ( "path/filepath" "strings" - "github.com/cloud-barista/cb-larva/poc-cb-net/internal/file" + "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" cblog "github.com/cloud-barista/cb-log" "github.com/sirupsen/logrus" ) From 62390af9826167ed8390b6b508400e6c7f0da6cb Mon Sep 17 00:00:00 2001 From: "Yunkon (Alvin) Kim" Date: Fri, 25 Mar 2022 11:28:04 +0900 Subject: [PATCH 9/9] Wait until the graceful shutdown process is done --- poc-cb-net/cmd/agent/agent.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/poc-cb-net/cmd/agent/agent.go b/poc-cb-net/cmd/agent/agent.go index 02a4d28..ca2e2fe 100644 --- a/poc-cb-net/cmd/agent/agent.go +++ b/poc-cb-net/cmd/agent/agent.go @@ -549,20 +549,6 @@ func main() { os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT) defer stop() - go func() { - // Block until a signal is triggered - <-gracefulShutdownContext.Done() - - // Stop this cb-network agent - fmt.Println("[Stop] cb-network agent") - CBNet.Stop() - // Set this agent status "suspended" - updatePeerState(model.Suspended, etcdClient) - - // Wait for a while - time.Sleep(1 * time.Second) - }() - // Wait for multiple goroutines to complete var wg sync.WaitGroup @@ -575,6 +561,23 @@ func main() { // Resume cb-network handleCommand("resume", "", etcdClient) + wg.Add(1) + go func(wg *sync.WaitGroup) { + defer wg.Done() + + // Block until a signal is triggered + <-gracefulShutdownContext.Done() + + // Stop this cb-network agent + fmt.Println("[Stop] cb-network agent") + CBNet.Stop() + // Set this agent status "suspended" + updatePeerState(model.Suspended, etcdClient) + + // Wait for a while + time.Sleep(3 * time.Second) + }(&wg) + // Waiting for all goroutines to finish CBLogger.Info("Waiting for all goroutines to finish") wg.Wait()