New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easegress egctl cmd enhancement #486
Comments
|
Sounds like a nice improvement! I also often struggle with |
|
I'v just found |
|
First we should add |
|
I just do a simple origin egctl cmd wrapper and compiled binary named as egctl+ for delete all and apply subcommand, package main
import (
"fmt"
"gopkg.in/yaml.v2"
"log"
"os"
"os/exec"
)
type ObjectSpec struct {
Kind string `yaml:"kind"`
Name string `yaml:"name"`
}
func main() {
if isDelAllCmd() {
execDelAllCmd()
} else if isApplyCmd() {
execDelAllCmd()
execOriginCmd([]string{"object", "create", "-f", os.Args[len(os.Args)-1]})
} else {
execOriginCmd(os.Args[1:])
}
}
func isApplyCmd() bool {
//egctl+ object apply -f file
return len(os.Args) == 5 && os.Args[1] == "object" && os.Args[2] == "apply" && os.Args[3] == "-f" && os.Args[4] != ""
}
func isDelAllCmd() bool {
//egctl+ object delete --all
return len(os.Args) == 4 && os.Args[1] == "object" && os.Args[2] == "delete" && os.Args[3] == "--all"
}
func execOriginCmd(args []string) {
cmd := exec.Command("egctl", args...)
output, err := cmd.Output()
if err != nil {
log.Fatalf("execute cmd %s %s err %s", cmd.Path, cmd.Args, err)
}
fmt.Print(string(output))
}
func execDelAllCmd() {
cmd := exec.Command("egctl", "object", "list")
output, err := cmd.Output()
if err != nil {
log.Fatalf("execute cmd output: %s", err)
}
var objSpecs []*ObjectSpec
err = yaml.Unmarshal(output, &objSpecs)
if err != nil {
log.Fatalf("unmarshal object specs failure: %s", err)
}
var cmds []*exec.Cmd
for _, spec := range objSpecs {
cmds = append(cmds, exec.Command("egctl", "object", "delete", spec.Name))
}
for _, cmd := range cmds {
_, err := cmd.Output()
if err != nil {
log.Fatalf("execute cmd %s %s err %s", cmd.Path, cmd.Args, err)
}
}
} |
|
Very clever and simple way to add I think that it would be nice to implement it in
What about others, do you think we should have |


Is egctl has any way to delete all objects using just one command, right now I can put all Easegress objects(including HTTPServer、GlobalFilter、NacosServiceRegistry、HTTPPipeline etc) in a file and use just one command
egctl object create -f fileto create. But for any reason if I change one of these objects especially for local debug,it is very hard for me to apply these new changes(I need to delete local etcd data dir and restart), I think egctl should like k8s kubectl to supportegctl object apply -f filein a declarative way.The text was updated successfully, but these errors were encountered: