I have implemented a CLI using go and I display the status of kubernetese cells. The command is cellery ps
func ps() error {
cmd := exec.Command("kubectl", "get", "cells")
stdoutReader, _ := cmd.StdoutPipe()
stdoutScanner := bufio.NewScanner(stdoutReader)
go func() {
for stdoutScanner.Scan() {
fmt.Println(stdoutScanner.Text())
}
}()
stderrReader, _ := cmd.StderrPipe()
stderrScanner := bufio.NewScanner(stderrReader)
go func() {
for stderrScanner.Scan() {
fmt.Println(stderrScanner.Text())
if (stderrScanner.Text() == "No resources found.") {
os.Exit(0)
}
}
}()
err := cmd.Start()
if err != nil {
fmt.Printf("Error in executing cell ps: %v \n", err)
os.Exit(1)
}
err = cmd.Wait()
if err != nil {
fmt.Printf("\x1b[31;1m Cell ps finished with error: \x1b[0m %v \n", err)
os.Exit(1)
}
return nil
}
However cells need time to get into ready state when they are deployed. Therefore I need to give a flag(wait) which would update the CLI output.
The command would be cellery ps -w
. However Kubernetese API have not implemented this yet. So I will have to come up with a command.
Basically what you want is to listen to the event of a cell become ready. You can register to the events in a cluster and act upon them. A good example can be found here