github.com/verrazzano/verrazzano@v1.7.0/application-operator/main.go (about) 1 // Copyright (c) 2020, 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 "github.com/verrazzano/verrazzano/application-operator/internal/operatorinit" 11 12 certapiv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" 13 "github.com/crossplane/oam-kubernetes-runtime/apis/core" 14 promoperapi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" 15 vzapp "github.com/verrazzano/verrazzano/application-operator/apis/app/v1alpha1" 16 clustersv1alpha1 "github.com/verrazzano/verrazzano/application-operator/apis/clusters/v1alpha1" 17 vzapi "github.com/verrazzano/verrazzano/application-operator/apis/oam/v1alpha1" 18 "github.com/verrazzano/verrazzano/application-operator/constants" 19 vmc "github.com/verrazzano/verrazzano/cluster-operator/apis/clusters/v1alpha1" 20 vzlog "github.com/verrazzano/verrazzano/pkg/log" 21 "go.uber.org/zap" 22 istioclinet "istio.io/client-go/pkg/apis/networking/v1alpha3" 23 clisecurity "istio.io/client-go/pkg/apis/security/v1beta1" 24 k8sapiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 25 "k8s.io/apimachinery/pkg/runtime" 26 clientgoscheme "k8s.io/client-go/kubernetes/scheme" 27 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 28 kzap "sigs.k8s.io/controller-runtime/pkg/log/zap" 29 ) 30 31 var ( 32 scheme = runtime.NewScheme() 33 ) 34 35 func init() { 36 _ = clientgoscheme.AddToScheme(scheme) 37 _ = k8sapiext.AddToScheme(scheme) 38 39 // Add core oam types to scheme 40 _ = core.AddToScheme(scheme) 41 42 // Add ingress trait to scheme 43 _ = vzapi.AddToScheme(scheme) 44 _ = vzapp.AddToScheme(scheme) 45 _ = istioclinet.AddToScheme(scheme) 46 _ = clisecurity.AddToScheme(scheme) 47 48 _ = clustersv1alpha1.AddToScheme(scheme) 49 _ = vmc.AddToScheme(scheme) 50 _ = certapiv1.AddToScheme(scheme) 51 _ = promoperapi.AddToScheme(scheme) 52 } 53 54 var ( 55 metricsAddr string 56 defaultMetricsScraper string 57 certDir string 58 enableLeaderElection bool 59 enableWebhooks bool 60 runClusterAgent bool 61 runWebhooks bool 62 runWebhookInit bool 63 ) 64 65 func main() { 66 flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") 67 flag.StringVar(&defaultMetricsScraper, "default-metrics-scraper", constants.DefaultScraperName, 68 "The namespace/deploymentName of the prometheus deployment to be used as the default metrics scraper") 69 flag.StringVar(&certDir, "cert-dir", "/etc/certs/", "The directory containing tls.crt and tls.key.") 70 flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, 71 "Enable leader election for controller manager. "+ 72 "Enabling this will ensure there is only one active controller manager.") 73 flag.BoolVar(&enableWebhooks, "enable-webhooks", true, 74 "Enable access-controller webhooks") 75 flag.BoolVar(&runWebhooks, "run-webhooks", false, 76 "Runs in webhook mode; if false, runs the main operator reconcile loop") 77 flag.BoolVar(&runWebhookInit, "run-webhook-init", false, 78 "Runs the webhook initialization code") 79 flag.BoolVar(&runClusterAgent, "run-cluster-agent", false, 80 "Runs in cluster agent mode; if true, starts the managed cluster agent reconciler; otherwise runs the main operator reconcile loop") 81 82 // Add the zap logger flag set to the CLI. 83 opts := kzap.Options{} 84 opts.BindFlags(flag.CommandLine) 85 86 flag.Parse() 87 kzap.UseFlagOptions(&opts) 88 vzlog.InitLogs(opts) 89 90 // Initialize the zap log 91 log := zap.S() 92 93 var exitErr error 94 if runWebhookInit { 95 exitErr = operatorinit.WebhookInit(certDir, log) 96 } else if runWebhooks { 97 exitErr = operatorinit.StartWebhookServer(metricsAddr, log, enableLeaderElection, certDir, scheme) 98 } else if runClusterAgent { 99 exitErr = operatorinit.StartClusterAgent(metricsAddr, enableLeaderElection, log, scheme) 100 } else { 101 exitErr = operatorinit.StartApplicationOperator(metricsAddr, enableLeaderElection, defaultMetricsScraper, log, scheme) 102 } 103 if exitErr != nil { 104 os.Exit(1) 105 } 106 }