github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/cmd/verrazzano-monitoring-ctrl/main.go (about) 1 // Copyright (C) 2020, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package main 5 6 import ( 7 "flag" 8 "fmt" 9 "os" 10 11 kzap "sigs.k8s.io/controller-runtime/pkg/log/zap" 12 // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). 13 // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 14 15 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/config" 16 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/constants" 17 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/metricsexporter" 18 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/util/logs" 19 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/vmo" 20 "go.uber.org/zap" 21 ) 22 23 var ( 24 masterURL string 25 kubeconfig string 26 namespace string 27 watchNamespace string 28 watchVmi string 29 configmapName string 30 buildVersion string 31 buildDate string 32 certdir string 33 port string 34 zapOptions = kzap.Options{} 35 ) 36 37 func main() { 38 flag.Parse() 39 logs.InitLogs(zapOptions) 40 41 // Namespace must still be specified on the command line, as it is a prerequisite to fetching the config map 42 if namespace == "" { 43 zap.S().Fatalf("A namespace must be specified") 44 } 45 46 // Initialize the images to use 47 err := config.InitComponentDetails() 48 if err != nil { 49 zap.S().Fatalf("Error identifying docker images: %s", err.Error()) 50 } 51 52 zap.S().Debugf("Creating new controller in namespace %s.", namespace) 53 controller, err := vmo.NewController(namespace, configmapName, buildVersion, kubeconfig, masterURL, watchNamespace, watchVmi) 54 if err != nil { 55 zap.S().Fatalf("Error creating the controller: %s", err.Error()) 56 } 57 58 _, err = vmo.CreateCertificates(certdir) 59 if err != nil { 60 zap.S().Fatalf("Error creating certificates: %s", err.Error()) 61 os.Exit(1) 62 } 63 64 vmo.StartHTTPServer(controller, certdir, port) 65 66 metricsexporter.StartMetricsServer() 67 68 if err = controller.Run(1); err != nil { 69 zap.S().Fatalf("Error running controller: %s", err.Error()) 70 } 71 } 72 73 func init() { 74 flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") 75 flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") 76 flag.StringVar(&namespace, "namespace", constants.DefaultNamespace, "The namespace in which this operator runs.") 77 flag.StringVar(&watchNamespace, "watchNamespace", "", "Optionally, a namespace to watch exclusively. If not set, all namespaces will be watched.") 78 flag.StringVar(&watchVmi, "watchVmi", "", "Optionally, a specific VMI to watch exclusively. If not set, all VMIs will be watched.") 79 flag.StringVar(&configmapName, "configmapName", config.DefaultOperatorConfigmapName, "The configmap name containing the operator config") 80 flag.StringVar(&certdir, "certdir", "/etc/certs", "the directory to initalize certificates into") 81 flag.StringVar(&port, "port", "8080", "VMO server HTTP port") 82 flag.Usage = func() { 83 fmt.Fprintf(os.Stderr, "%s version %s\n", os.Args[0], buildVersion) 84 fmt.Fprintf(os.Stderr, "built %s\n", buildDate) 85 flag.PrintDefaults() 86 } 87 zapOptions.BindFlags(flag.CommandLine) 88 }