...
1
23
24 package main
25
26 import (
27 "context"
28 "errors"
29 "flag"
30 "fmt"
31 "os"
32
33 _ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres"
34
35 "edge-infra.dev/pkg/edge/api/utils"
36
37 lumberjackUtils "edge-infra.dev/hack/tools/lumberjack/utils"
38 )
39
40 var (
41 fs = flag.NewFlagSet("lumberjack", flag.ExitOnError)
42 bannerInfraCluster = fs.String("bannerInfraCluster", os.Getenv("BannerInfraCluster"), "the banner infra cluster where container clusters are deployed")
43 projectID = fs.String("projectID", os.Getenv("projectID"), "the project id the infra cluster is located in")
44 zone = fs.String("zone", os.Getenv("zone"), "the zone the infra cluster is located in")
45 errBannerInfraClusterRequired = errors.New("error banner infra cluster is required")
46 errProjectIDRequired = errors.New("error project id is required")
47 errZoneRequired = errors.New("error zone is required")
48 )
49
50 func main() {
51 err := fs.Parse(os.Args[1:])
52 if err != nil {
53 fmt.Println("Flag parsing error ", err)
54 os.Exit(1)
55 }
56 if err := validateRequiredFlags(); err != nil {
57 fmt.Println("Flag validation error ", err)
58 os.Exit(1)
59 }
60
61 lumberjackConfig := lumberjackUtils.New()
62 fmt.Println("")
63 fmt.Println(`
64 ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
65 /\__\ /\__\ /\__\ /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ /\__\
66 /:/ / /:/ / /::| | /::\ \ /::\ \ /::\ \ \:\ \ /::\ \ /::\ \ /:/ /
67 /:/ / /:/ / /:|:| | /:/\:\ \ /:/\:\ \ /:/\:\ \ ___ /::\__\ /:/\:\ \ /:/\:\ \ /:/__/
68 /:/ / /:/ / ___ /:/|:|__|__ /::\~\:\__\ /::\~\:\ \ /::\~\:\ \ /\ /:/\/__/ /::\~\:\ \ /:/ \:\ \ /::\__\____
69 /:/__/ /:/__/ /\__\ /:/ |::::\__\ /:/\:\ \:|__| /:/\:\ \:\__\ /:/\:\ \:\__\ \:\/:/ / /:/\:\ \:\__\ /:/__/ \:\__\ /:/\:::::\__\
70 \:\ \ \:\ \ /:/ / \/__/~~/:/ / \:\~\:\/:/ / \:\~\:\ \/__/ \/_|::\/:/ / \::/ / \/__\:\/:/ / \:\ \ \/__/ \/_|:|~~|~
71 \:\ \ \:\ /:/ / /:/ / \:\ \::/ / \:\ \:\__\ |:|::/ / \/__/ \::/ / \:\ \ |:| |
72 \:\ \ \:\/:/ / /:/ / \:\/:/ / \:\ \/__/ |:|\/__/ /:/ / \:\ \ |:| |
73 \:\__\ \::/ / /:/ / \::/__/ \:\__\ |:| | /:/ / \:\__\ |:| |
74 \/__/ \/__/ \/__/ ~~ \/__/ \|__| \/__/ \/__/ \|__|
75 `)
76 fmt.Println("")
77 fmt.Printf("Connecting to banner infra cluster %s, in top level project %s\n", *bannerInfraCluster, *projectID)
78 client, err := lumberjackUtils.GetClient(context.Background(), *projectID, *bannerInfraCluster, *zone)
79 if err != nil {
80 fmt.Printf("could not connect to %s cluster\n", *bannerInfraCluster)
81 os.Exit(1)
82 }
83 lumberjackConfig.SetClusterConnection(client)
84 cmd := lumberjackConfig.Exec("lumberjack", "lumberjack --bannerInfraCluster=someBannerInfraCluster --projectID=someProjectID", "add logging config to container cluster resources", fs)
85
86 if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
87 fmt.Fprintf(os.Stderr, "error:%v\n", err)
88 os.Exit(1)
89 }
90 }
91
92 func validateRequiredFlags() error {
93 if utils.IsNullOrEmpty(bannerInfraCluster) {
94 return errBannerInfraClusterRequired
95 }
96 if utils.IsNullOrEmpty(projectID) {
97 return errProjectIDRequired
98 }
99 if utils.IsNullOrEmpty(zone) {
100 return errZoneRequired
101 }
102 return nil
103 }
104
View as plain text