kubectl-persistent-logger/main.go

56 lines
1.3 KiB
Go

package main
import (
"context"
"flag"
"log"
"os"
"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() {
var (
kubeconfig *string
deployName *string
container *string
strictExist *bool
)
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")
container = flag.String("container", "", "name of a specific container")
strictExist = flag.Bool("strict-exist", false, "require deployment to exist on launch")
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()
watcher := logs.NewWatcher(
*deployName,
*container,
*strictExist,
logs.KubernetesClient{Interface: clientset},
logs.NewPodWatcher,
os.Stdout,
)
if err := watcher.Watch(ctx); err != nil {
log.Fatal(err)
}
}