/* ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ /\__\ /\__\ /\__\ /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ /\__\ /:/ / /:/ / /::| | /::\ \ /::\ \ /::\ \ \:\ \ /::\ \ /::\ \ /:/ / /:/ / /:/ / /:|:| | /:/\:\ \ /:/\:\ \ /:/\:\ \ ___ /::\__\ /:/\:\ \ /:/\:\ \ /:/__/ /:/ / /:/ / ___ /:/|:|__|__ /::\~\:\__\ /::\~\:\ \ /::\~\:\ \ /\ /:/\/__/ /::\~\:\ \ /:/ \:\ \ /::\__\____ /:/__/ /:/__/ /\__\ /:/ |::::\__\ /:/\:\ \:|__| /:/\:\ \:\__\ /:/\:\ \:\__\ \:\/:/ / /:/\:\ \:\__\ /:/__/ \:\__\ /:/\:::::\__\ \:\ \ \:\ \ /:/ / \/__/~~/:/ / \:\~\:\/:/ / \:\~\:\ \/__/ \/_|::\/:/ / \::/ / \/__\:\/:/ / \:\ \ \/__/ \/_|:|~~|~ \:\ \ \:\ /:/ / /:/ / \:\ \::/ / \:\ \:\__\ |:|::/ / \/__/ \::/ / \:\ \ |:| | \:\ \ \:\/:/ / /:/ / \:\/:/ / \:\ \/__/ |:|\/__/ /:/ / \:\ \ |:| | \:\__\ \::/ / /:/ / \::/__/ \:\__\ |:| | /:/ / \:\__\ |:| | \/__/ \/__/ \/__/ ~~ \/__/ \|__| \/__/ \/__/ \|__| CLI program written to append container cluster resources deployed on a banner infra cluster with a logging config. This config will tell fluentbit-gke to only forward system logs. The cli program can be run like so: lumberjack --bannerInfraCluster=someBannerInfraCluster --projectID=someProjectID The --bannerInfraCluster and --projectID flags are required. */ package main import ( "context" "errors" "flag" "fmt" "os" _ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres" "edge-infra.dev/pkg/edge/api/utils" lumberjackUtils "edge-infra.dev/hack/tools/lumberjack/utils" ) var ( fs = flag.NewFlagSet("lumberjack", flag.ExitOnError) bannerInfraCluster = fs.String("bannerInfraCluster", os.Getenv("BannerInfraCluster"), "the banner infra cluster where container clusters are deployed") projectID = fs.String("projectID", os.Getenv("projectID"), "the project id the infra cluster is located in") zone = fs.String("zone", os.Getenv("zone"), "the zone the infra cluster is located in") errBannerInfraClusterRequired = errors.New("error banner infra cluster is required") errProjectIDRequired = errors.New("error project id is required") errZoneRequired = errors.New("error zone is required") ) func main() { err := fs.Parse(os.Args[1:]) if err != nil { fmt.Println("Flag parsing error ", err) os.Exit(1) } if err := validateRequiredFlags(); err != nil { fmt.Println("Flag validation error ", err) os.Exit(1) } lumberjackConfig := lumberjackUtils.New() fmt.Println("") fmt.Println(` ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ /\__\ /\__\ /\__\ /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ /\__\ /:/ / /:/ / /::| | /::\ \ /::\ \ /::\ \ \:\ \ /::\ \ /::\ \ /:/ / /:/ / /:/ / /:|:| | /:/\:\ \ /:/\:\ \ /:/\:\ \ ___ /::\__\ /:/\:\ \ /:/\:\ \ /:/__/ /:/ / /:/ / ___ /:/|:|__|__ /::\~\:\__\ /::\~\:\ \ /::\~\:\ \ /\ /:/\/__/ /::\~\:\ \ /:/ \:\ \ /::\__\____ /:/__/ /:/__/ /\__\ /:/ |::::\__\ /:/\:\ \:|__| /:/\:\ \:\__\ /:/\:\ \:\__\ \:\/:/ / /:/\:\ \:\__\ /:/__/ \:\__\ /:/\:::::\__\ \:\ \ \:\ \ /:/ / \/__/~~/:/ / \:\~\:\/:/ / \:\~\:\ \/__/ \/_|::\/:/ / \::/ / \/__\:\/:/ / \:\ \ \/__/ \/_|:|~~|~ \:\ \ \:\ /:/ / /:/ / \:\ \::/ / \:\ \:\__\ |:|::/ / \/__/ \::/ / \:\ \ |:| | \:\ \ \:\/:/ / /:/ / \:\/:/ / \:\ \/__/ |:|\/__/ /:/ / \:\ \ |:| | \:\__\ \::/ / /:/ / \::/__/ \:\__\ |:| | /:/ / \:\__\ |:| | \/__/ \/__/ \/__/ ~~ \/__/ \|__| \/__/ \/__/ \|__| `) fmt.Println("") fmt.Printf("Connecting to banner infra cluster %s, in top level project %s\n", *bannerInfraCluster, *projectID) client, err := lumberjackUtils.GetClient(context.Background(), *projectID, *bannerInfraCluster, *zone) if err != nil { fmt.Printf("could not connect to %s cluster\n", *bannerInfraCluster) os.Exit(1) } lumberjackConfig.SetClusterConnection(client) cmd := lumberjackConfig.Exec("lumberjack", "lumberjack --bannerInfraCluster=someBannerInfraCluster --projectID=someProjectID", "add logging config to container cluster resources", fs) if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil { fmt.Fprintf(os.Stderr, "error:%v\n", err) os.Exit(1) } } func validateRequiredFlags() error { if utils.IsNullOrEmpty(bannerInfraCluster) { return errBannerInfraClusterRequired } if utils.IsNullOrEmpty(projectID) { return errProjectIDRequired } if utils.IsNullOrEmpty(zone) { return errZoneRequired } return nil }