github.com/verrazzano/verrazzano@v1.7.1/cluster-operator/main.go (about) 1 // Copyright (c) 2022, 2023, 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 "os" 9 10 clustersv1alpha1 "github.com/verrazzano/verrazzano/cluster-operator/apis/clusters/v1alpha1" 11 "github.com/verrazzano/verrazzano/cluster-operator/internal/operatorinit" 12 vzlog "github.com/verrazzano/verrazzano/pkg/log" 13 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1" 14 "go.uber.org/zap" 15 istioclinet "istio.io/client-go/pkg/apis/networking/v1beta1" 16 v1 "k8s.io/api/rbac/v1" 17 k8sapiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 18 "k8s.io/apimachinery/pkg/runtime" 19 utilruntime "k8s.io/apimachinery/pkg/util/runtime" 20 clientgoscheme "k8s.io/client-go/kubernetes/scheme" 21 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 22 capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" 23 ctrl "sigs.k8s.io/controller-runtime" 24 kzap "sigs.k8s.io/controller-runtime/pkg/log/zap" 25 // +kubebuilder:scaffold:imports 26 ) 27 28 var ( 29 scheme = runtime.NewScheme() 30 31 metricsAddr string 32 enableLeaderElection bool 33 probeAddr string 34 runWebhooks bool 35 runWebhookInit bool 36 certDir string 37 ingressHost string 38 enableQuickCreate bool 39 disableCAPIRancherRegistration bool 40 ) 41 42 func init() { 43 utilruntime.Must(clientgoscheme.AddToScheme(scheme)) 44 utilruntime.Must(k8sapiext.AddToScheme(scheme)) 45 utilruntime.Must(istioclinet.AddToScheme(scheme)) 46 47 utilruntime.Must(clustersv1alpha1.AddToScheme(scheme)) 48 utilruntime.Must(v1beta1.AddToScheme(scheme)) 49 utilruntime.Must(v1.AddToScheme(scheme)) 50 utilruntime.Must(capiv1beta1.AddToScheme(scheme)) 51 // +kubebuilder:scaffold:scheme 52 } 53 54 func main() { 55 props := handleFlags() 56 log := zap.S() 57 58 if runWebhookInit { 59 err := operatorinit.WebhookInit(log, props) 60 if err != nil { 61 os.Exit(1) 62 } 63 } else if runWebhooks { 64 err := operatorinit.StartWebhookServer(log, props) 65 if err != nil { 66 os.Exit(1) 67 } 68 } else { 69 err := operatorinit.StartClusterOperator(log, props) 70 if err != nil { 71 os.Exit(1) 72 } 73 } 74 } 75 76 // handleFlags sets up the CLI flags, parses them, and initializes loggers 77 func handleFlags() operatorinit.Properties { 78 flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") 79 flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") 80 flag.BoolVar(&enableLeaderElection, "leader-elect", false, 81 "Enable leader election for controller manager. "+ 82 "Enabling this will ensure there is only one active controller manager.") 83 flag.BoolVar(&runWebhooks, "run-webhooks", false, 84 "Runs in webhook mode; if false, runs the main operator reconcile loop") 85 flag.BoolVar(&runWebhookInit, "run-webhook-init", false, 86 "Runs the webhook initialization code") 87 flag.BoolVar(&enableQuickCreate, "quick-create", true, "If true, enables Quick Create Clusters") 88 flag.StringVar(&certDir, "cert-dir", "/etc/certs/", "The directory containing tls.crt and tls.key.") 89 flag.StringVar(&ingressHost, "ingress-host", "", "The host used for Rancher API requests.") 90 flag.BoolVar(&disableCAPIRancherRegistration, "disable-capi-rancher-registration", false, 91 "Disables the registration of CAPI-based clusters with Rancher") 92 93 opts := kzap.Options{} 94 opts.BindFlags(flag.CommandLine) 95 flag.Parse() 96 97 kzap.UseFlagOptions(&opts) 98 vzlog.InitLogs(opts) 99 ctrl.SetLogger(kzap.New(kzap.UseFlagOptions(&opts))) 100 return operatorinit.Properties{ 101 Scheme: scheme, 102 CertificateDir: certDir, 103 MetricsAddress: metricsAddr, 104 ProbeAddress: probeAddr, 105 IngressHost: ingressHost, 106 EnableLeaderElection: enableLeaderElection, 107 EnableQuickCreate: enableQuickCreate, 108 DisableCAPIRancherRegistration: disableCAPIRancherRegistration, 109 } 110 }