github.com/oam-dev/kubevela@v1.9.11/cmd/core/app/options/options.go (about) 1 /* 2 Copyright 2022 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package options 18 19 import ( 20 "strconv" 21 "time" 22 23 pkgclient "github.com/kubevela/pkg/controller/client" 24 ctrlrec "github.com/kubevela/pkg/controller/reconciler" 25 "github.com/kubevela/pkg/controller/sharding" 26 pkgmulticluster "github.com/kubevela/pkg/multicluster" 27 utillog "github.com/kubevela/pkg/util/log" 28 "github.com/kubevela/pkg/util/profiling" 29 wfTypes "github.com/kubevela/workflow/pkg/types" 30 utilfeature "k8s.io/apiserver/pkg/util/feature" 31 cliflag "k8s.io/component-base/cli/flag" 32 33 standardcontroller "github.com/oam-dev/kubevela/pkg/controller" 34 commonconfig "github.com/oam-dev/kubevela/pkg/controller/common" 35 oamcontroller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" 36 "github.com/oam-dev/kubevela/pkg/oam" 37 "github.com/oam-dev/kubevela/pkg/resourcekeeper" 38 ) 39 40 // CoreOptions contains everything necessary to create and run vela-core 41 type CoreOptions struct { 42 UseWebhook bool 43 CertDir string 44 WebhookPort int 45 MetricsAddr string 46 EnableLeaderElection bool 47 LeaderElectionNamespace string 48 LogFilePath string 49 LogFileMaxSize uint64 50 LogDebug bool 51 ControllerArgs *oamcontroller.Args 52 HealthAddr string 53 StorageDriver string 54 InformerSyncPeriod time.Duration 55 QPS float64 56 Burst int 57 LeaderElectionResourceLock string 58 LeaseDuration time.Duration 59 RenewDeadLine time.Duration 60 RetryPeriod time.Duration 61 EnableClusterGateway bool 62 EnableClusterMetrics bool 63 ClusterMetricsInterval time.Duration 64 } 65 66 // NewCoreOptions creates a new NewVelaCoreOptions object with default parameters 67 func NewCoreOptions() *CoreOptions { 68 s := &CoreOptions{ 69 UseWebhook: false, 70 CertDir: "/k8s-webhook-server/serving-certs", 71 WebhookPort: 9443, 72 MetricsAddr: ":8080", 73 EnableLeaderElection: false, 74 LeaderElectionNamespace: "", 75 LogFilePath: "", 76 LogFileMaxSize: 1024, 77 LogDebug: false, 78 ControllerArgs: &oamcontroller.Args{ 79 RevisionLimit: 50, 80 AppRevisionLimit: 10, 81 DefRevisionLimit: 20, 82 AutoGenWorkloadDefinition: true, 83 ConcurrentReconciles: 4, 84 IgnoreAppWithoutControllerRequirement: false, 85 IgnoreDefinitionWithoutControllerRequirement: false, 86 }, 87 HealthAddr: ":9440", 88 StorageDriver: "Local", 89 InformerSyncPeriod: 10 * time.Hour, 90 QPS: 50, 91 Burst: 100, 92 LeaderElectionResourceLock: "configmapsleases", 93 LeaseDuration: 15 * time.Second, 94 RenewDeadLine: 10 * time.Second, 95 RetryPeriod: 2 * time.Second, 96 EnableClusterGateway: false, 97 EnableClusterMetrics: false, 98 ClusterMetricsInterval: 15 * time.Second, 99 } 100 return s 101 } 102 103 // Flags returns the complete NamedFlagSets 104 func (s *CoreOptions) Flags() cliflag.NamedFlagSets { 105 fss := cliflag.NamedFlagSets{} 106 107 gfs := fss.FlagSet("generic") 108 gfs.BoolVar(&s.UseWebhook, "use-webhook", s.UseWebhook, "Enable Admission Webhook") 109 gfs.StringVar(&s.CertDir, "webhook-cert-dir", s.CertDir, "Admission webhook cert/key dir.") 110 gfs.IntVar(&s.WebhookPort, "webhook-port", s.WebhookPort, "admission webhook listen address") 111 gfs.StringVar(&s.MetricsAddr, "metrics-addr", s.MetricsAddr, "The address the metric endpoint binds to.") 112 gfs.BoolVar(&s.EnableLeaderElection, "enable-leader-election", s.EnableLeaderElection, 113 "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") 114 gfs.StringVar(&s.LeaderElectionNamespace, "leader-election-namespace", s.LeaderElectionNamespace, 115 "Determines the namespace in which the leader election configmap will be created.") 116 gfs.StringVar(&s.LogFilePath, "log-file-path", s.LogFilePath, "The file to write logs to.") 117 gfs.Uint64Var(&s.LogFileMaxSize, "log-file-max-size", s.LogFileMaxSize, "Defines the maximum size a log file can grow to, Unit is megabytes.") 118 gfs.BoolVar(&s.LogDebug, "log-debug", s.LogDebug, "Enable debug logs for development purpose") 119 gfs.StringVar(&s.HealthAddr, "health-addr", s.HealthAddr, "The address the health endpoint binds to.") 120 gfs.DurationVar(&s.InformerSyncPeriod, "informer-sync-period", s.InformerSyncPeriod, 121 "The re-sync period for informer in controller-runtime. This is a system-level configuration.") 122 gfs.Float64Var(&s.QPS, "kube-api-qps", s.QPS, "the qps for reconcile clients. Low qps may lead to low throughput. High qps may give stress to api-server. Raise this value if concurrent-reconciles is set to be high.") 123 gfs.IntVar(&s.Burst, "kube-api-burst", s.Burst, "the burst for reconcile clients. Recommend setting it qps*2.") 124 gfs.StringVar(&s.LeaderElectionResourceLock, "leader-election-resource-lock", s.LeaderElectionResourceLock, "The resource lock to use for leader election") 125 gfs.DurationVar(&s.LeaseDuration, "leader-election-lease-duration", s.LeaseDuration, 126 "The duration that non-leader candidates will wait to force acquire leadership") 127 gfs.DurationVar(&s.RenewDeadLine, "leader-election-renew-deadline", s.RenewDeadLine, 128 "The duration that the acting controlplane will retry refreshing leadership before giving up") 129 gfs.DurationVar(&s.RetryPeriod, "leader-election-retry-period", s.RetryPeriod, 130 "The duration the LeaderElector clients should wait between tries of actions") 131 gfs.BoolVar(&s.EnableClusterGateway, "enable-cluster-gateway", s.EnableClusterGateway, "Enable cluster-gateway to use multicluster, disabled by default.") 132 gfs.BoolVar(&s.EnableClusterMetrics, "enable-cluster-metrics", s.EnableClusterMetrics, "Enable cluster-metrics-management to collect metrics from clusters with cluster-gateway, disabled by default. When this param is enabled, enable-cluster-gateway should be enabled") 133 gfs.DurationVar(&s.ClusterMetricsInterval, "cluster-metrics-interval", s.ClusterMetricsInterval, "The interval that ClusterMetricsMgr will collect metrics from clusters, default value is 15 seconds.") 134 135 s.ControllerArgs.AddFlags(fss.FlagSet("controllerArgs"), s.ControllerArgs) 136 137 cfs := fss.FlagSet("commonconfig") 138 cfs.DurationVar(&commonconfig.ApplicationReSyncPeriod, "application-re-sync-period", commonconfig.ApplicationReSyncPeriod, 139 "Re-sync period for application to re-sync, also known as the state-keep interval.") 140 cfs.BoolVar(&commonconfig.PerfEnabled, "perf-enabled", commonconfig.PerfEnabled, "Enable performance logging for controllers, disabled by default.") 141 142 ofs := fss.FlagSet("oam") 143 ofs.StringVar(&oam.SystemDefinitionNamespace, "system-definition-namespace", "vela-system", "define the namespace of the system-level definition") 144 145 standardcontroller.AddOptimizeFlags(fss.FlagSet("optimize")) 146 standardcontroller.AddAdmissionFlags(fss.FlagSet("admission")) 147 148 rfs := fss.FlagSet("resourcekeeper") 149 rfs.IntVar(&resourcekeeper.MaxDispatchConcurrent, "max-dispatch-concurrent", 10, "Set the max dispatch concurrent number, default is 10") 150 151 wfs := fss.FlagSet("wfTypes") 152 wfs.IntVar(&wfTypes.MaxWorkflowWaitBackoffTime, "max-workflow-wait-backoff-time", 60, "Set the max workflow wait backoff time, default is 60") 153 wfs.IntVar(&wfTypes.MaxWorkflowFailedBackoffTime, "max-workflow-failed-backoff-time", 300, "Set the max workflow failed backoff time, default is 300") 154 wfs.IntVar(&wfTypes.MaxWorkflowStepErrorRetryTimes, "max-workflow-step-error-retry-times", 10, "Set the max workflow step error retry times, default is 10") 155 156 pkgmulticluster.AddFlags(fss.FlagSet("multicluster")) 157 ctrlrec.AddFlags(fss.FlagSet("controllerreconciles")) 158 utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("featuregate")) 159 sharding.AddFlags(fss.FlagSet("sharding")) 160 kfs := fss.FlagSet("klog") 161 pkgclient.AddTimeoutControllerClientFlags(fss.FlagSet("controllerclient")) 162 utillog.AddFlags(kfs) 163 profiling.AddFlags(fss.FlagSet("profiling")) 164 165 if s.LogDebug { 166 _ = kfs.Set("v", strconv.Itoa(int(commonconfig.LogDebug))) 167 } 168 169 if s.LogFilePath != "" { 170 _ = kfs.Set("logtostderr", "false") 171 _ = kfs.Set("log_file", s.LogFilePath) 172 _ = kfs.Set("log_file_max_size", strconv.FormatUint(s.LogFileMaxSize, 10)) 173 } 174 175 return fss 176 }