kubectl-persistent-logger/main.go

56 lines
1.3 KiB
Go
Raw Normal View History

2022-05-29 19:04:02 +00:00
package main
import (
"context"
"flag"
"log"
2022-05-30 10:10:58 +00:00
"os"
2022-05-29 19:04:02 +00:00
"path/filepath"
"git.netflux.io/rob/kubectl-persistent-logger/logs"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
func main() {
2022-05-31 04:11:44 +00:00
var (
2022-06-01 20:04:20 +00:00
kubeconfig *string
deployName *string
container *string
strictExist *bool
2022-05-31 04:11:44 +00:00
)
2022-05-29 19:04:02 +00:00
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
deployName = flag.String("deployment", "", "name of a deployment to monitor")
2022-05-31 04:11:44 +00:00
container = flag.String("container", "", "name of a specific container")
2022-06-01 20:04:20 +00:00
strictExist = flag.Bool("strict-exist", false, "require deployment to exist on launch")
2022-05-29 19:04:02 +00:00
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
log.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
2022-05-31 04:11:44 +00:00
watcher := logs.NewWatcher(
*deployName,
*container,
2022-06-01 20:04:20 +00:00
*strictExist,
2022-05-31 04:11:44 +00:00
logs.KubernetesClient{Interface: clientset},
2022-06-01 17:19:55 +00:00
logs.NewPodWatcher,
2022-05-31 04:11:44 +00:00
os.Stdout,
)
2022-05-29 19:04:02 +00:00
if err := watcher.Watch(ctx); err != nil {
log.Fatal(err)
}
}