cloud-barista / cb-larva

CB-Larva is Cloud-Barista Incubator. The incubator researches and develops essential technologies for multi-cloud.
Apache License 2.0
9 stars 8 forks source link

Control cb-network agents remotely #212

Closed yunkon-kim closed 2 years ago

yunkon-kim commented 2 years ago

What would you like to be added : I'd like to control cb-network agents remotely.

Why is this needed : It's needed for an admin to control the agents remotely.

Tasks (expected)

Concept image

yunkon-kim commented 2 years ago

errgroup?

Package errgroup provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task. - errgroup - go.pkg.dev

Good example (I think)

~Practices (ongoing)~ ~- errgroup for graceful shutdown~ ~- A skeleton for remote control~ ~ - Note: It's simply classified as to control module and process module.~

yunkon-kim commented 2 years ago

The following link provides a skeleton for remote control. - A skeleton for remote control

It provides:

func main() {

    fmt.Println("Start")

    var wg sync.WaitGroup

    // A context for graceful shutdown (It is based on the signal package)
    //
    // NOTE
    // Use os.Interrupt to gracefully shutdown on Ctrl+C which is SIGINT
    // Use syscall.SIGTERM which is the usual signal for termination and
    // the default one (it can be modified) for docker containers, which is also used by kubernetes.
    gracefulShutdownContext, stop := signal.NotifyContext(context.TODO(), os.Interrupt, syscall.SIGTERM)
    defer stop()

    go func() {
        <-gracefulShutdownContext.Done()
        fmt.Println("Tasks before shutting down")

        // Add additional tasks here

        stop()
    }()

    command := make(chan string)
    // Process section
    wg.Add(1)
    go process(command, gracefulShutdownContext, &wg)

    // Control section
    wg.Add(1)
    go control(command, gracefulShutdownContext, &wg)

    fmt.Printf("Wait until go routines are finished.\n")
    wg.Wait()

    fmt.Println("Main done")
}

From now on I think I need to improve many parts of the cbnet package and cb-network agent :sweat_smile:

References: