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
|
|
|
|
|
|
|
"git.netflux.io/rob/kubectl-persistent-logger/logs"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
2022-06-07 19:16:37 +00:00
|
|
|
clientconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
|
2022-05-29 19:04:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-05-31 04:11:44 +00:00
|
|
|
var (
|
2022-06-01 20:04:20 +00:00
|
|
|
deployName *string
|
|
|
|
container *string
|
|
|
|
strictExist *bool
|
2022-05-31 04:11:44 +00:00
|
|
|
)
|
2022-05-29 19:04:02 +00:00
|
|
|
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()
|
|
|
|
|
2022-06-07 19:16:37 +00:00
|
|
|
cfg, err := clientconfig.GetConfig()
|
2022-05-29 19:04:02 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:37 +00:00
|
|
|
clientset, err := kubernetes.NewForConfig(cfg)
|
2022-05-29 19:04:02 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|