2022-11-28 17:56:38 +08:00
/ *
Copyright 2022 The KubeVela Authors .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
package options
import (
"strconv"
"time"
2025-03-25 07:52:51 +08:00
"github.com/kubevela/pkg/cue/cuex"
2023-01-31 16:55:37 +08:00
pkgclient "github.com/kubevela/pkg/controller/client"
2022-11-28 17:56:38 +08:00
ctrlrec "github.com/kubevela/pkg/controller/reconciler"
2023-02-07 11:12:40 +08:00
"github.com/kubevela/pkg/controller/sharding"
2022-11-28 17:56:38 +08:00
pkgmulticluster "github.com/kubevela/pkg/multicluster"
2023-01-31 13:03:29 +08:00
utillog "github.com/kubevela/pkg/util/log"
2023-06-12 10:41:02 +08:00
"github.com/kubevela/pkg/util/profiling"
2022-11-28 17:56:38 +08:00
wfTypes "github.com/kubevela/workflow/pkg/types"
utilfeature "k8s.io/apiserver/pkg/util/feature"
cliflag "k8s.io/component-base/cli/flag"
standardcontroller "github.com/oam-dev/kubevela/pkg/controller"
commonconfig "github.com/oam-dev/kubevela/pkg/controller/common"
2023-02-07 11:12:40 +08:00
oamcontroller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev"
2022-11-28 17:56:38 +08:00
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/resourcekeeper"
)
// CoreOptions contains everything necessary to create and run vela-core
type CoreOptions struct {
2025-01-03 07:54:42 +08:00
UseWebhook bool
CertDir string
WebhookPort int
MetricsAddr string
EnableLeaderElection bool
LeaderElectionNamespace string
LogFilePath string
LogFileMaxSize uint64
LogDebug bool
2025-10-01 00:32:16 +08:00
DevLogs bool
2025-01-03 07:54:42 +08:00
ControllerArgs * oamcontroller . Args
HealthAddr string
StorageDriver string
InformerSyncPeriod time . Duration
QPS float64
Burst int
LeaseDuration time . Duration
RenewDeadLine time . Duration
RetryPeriod time . Duration
EnableClusterGateway bool
EnableClusterMetrics bool
ClusterMetricsInterval time . Duration
2022-11-28 17:56:38 +08:00
}
// NewCoreOptions creates a new NewVelaCoreOptions object with default parameters
func NewCoreOptions ( ) * CoreOptions {
s := & CoreOptions {
UseWebhook : false ,
CertDir : "/k8s-webhook-server/serving-certs" ,
WebhookPort : 9443 ,
MetricsAddr : ":8080" ,
EnableLeaderElection : false ,
LeaderElectionNamespace : "" ,
LogFilePath : "" ,
LogFileMaxSize : 1024 ,
LogDebug : false ,
2025-10-01 00:32:16 +08:00
DevLogs : false ,
2022-11-28 17:56:38 +08:00
ControllerArgs : & oamcontroller . Args {
RevisionLimit : 50 ,
AppRevisionLimit : 10 ,
DefRevisionLimit : 20 ,
AutoGenWorkloadDefinition : true ,
ConcurrentReconciles : 4 ,
IgnoreAppWithoutControllerRequirement : false ,
IgnoreDefinitionWithoutControllerRequirement : false ,
} ,
2025-01-03 07:54:42 +08:00
HealthAddr : ":9440" ,
StorageDriver : "Local" ,
InformerSyncPeriod : 10 * time . Hour ,
QPS : 50 ,
Burst : 100 ,
LeaseDuration : 15 * time . Second ,
RenewDeadLine : 10 * time . Second ,
RetryPeriod : 2 * time . Second ,
EnableClusterGateway : false ,
EnableClusterMetrics : false ,
ClusterMetricsInterval : 15 * time . Second ,
2022-11-28 17:56:38 +08:00
}
return s
}
// Flags returns the complete NamedFlagSets
func ( s * CoreOptions ) Flags ( ) cliflag . NamedFlagSets {
fss := cliflag . NamedFlagSets { }
gfs := fss . FlagSet ( "generic" )
gfs . BoolVar ( & s . UseWebhook , "use-webhook" , s . UseWebhook , "Enable Admission Webhook" )
gfs . StringVar ( & s . CertDir , "webhook-cert-dir" , s . CertDir , "Admission webhook cert/key dir." )
gfs . IntVar ( & s . WebhookPort , "webhook-port" , s . WebhookPort , "admission webhook listen address" )
gfs . StringVar ( & s . MetricsAddr , "metrics-addr" , s . MetricsAddr , "The address the metric endpoint binds to." )
gfs . BoolVar ( & s . EnableLeaderElection , "enable-leader-election" , s . EnableLeaderElection ,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." )
gfs . StringVar ( & s . LeaderElectionNamespace , "leader-election-namespace" , s . LeaderElectionNamespace ,
"Determines the namespace in which the leader election configmap will be created." )
gfs . StringVar ( & s . LogFilePath , "log-file-path" , s . LogFilePath , "The file to write logs to." )
gfs . Uint64Var ( & s . LogFileMaxSize , "log-file-max-size" , s . LogFileMaxSize , "Defines the maximum size a log file can grow to, Unit is megabytes." )
gfs . BoolVar ( & s . LogDebug , "log-debug" , s . LogDebug , "Enable debug logs for development purpose" )
2025-10-01 00:32:16 +08:00
gfs . BoolVar ( & s . DevLogs , "dev-logs" , s . DevLogs , "Enable ANSI color formatting for console logs (ignored when log-file-path is set)" )
2022-11-28 17:56:38 +08:00
gfs . StringVar ( & s . HealthAddr , "health-addr" , s . HealthAddr , "The address the health endpoint binds to." )
gfs . DurationVar ( & s . InformerSyncPeriod , "informer-sync-period" , s . InformerSyncPeriod ,
"The re-sync period for informer in controller-runtime. This is a system-level configuration." )
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." )
gfs . IntVar ( & s . Burst , "kube-api-burst" , s . Burst , "the burst for reconcile clients. Recommend setting it qps*2." )
gfs . DurationVar ( & s . LeaseDuration , "leader-election-lease-duration" , s . LeaseDuration ,
"The duration that non-leader candidates will wait to force acquire leadership" )
gfs . DurationVar ( & s . RenewDeadLine , "leader-election-renew-deadline" , s . RenewDeadLine ,
"The duration that the acting controlplane will retry refreshing leadership before giving up" )
gfs . DurationVar ( & s . RetryPeriod , "leader-election-retry-period" , s . RetryPeriod ,
"The duration the LeaderElector clients should wait between tries of actions" )
gfs . BoolVar ( & s . EnableClusterGateway , "enable-cluster-gateway" , s . EnableClusterGateway , "Enable cluster-gateway to use multicluster, disabled by default." )
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" )
gfs . DurationVar ( & s . ClusterMetricsInterval , "cluster-metrics-interval" , s . ClusterMetricsInterval , "The interval that ClusterMetricsMgr will collect metrics from clusters, default value is 15 seconds." )
2025-03-25 07:52:51 +08:00
gfs . BoolVar ( & cuex . EnableExternalPackageForDefaultCompiler , "enable-external-package-for-default-compiler" , cuex . EnableExternalPackageForDefaultCompiler , "Enable external package for default compiler" )
gfs . BoolVar ( & cuex . EnableExternalPackageWatchForDefaultCompiler , "enable-external-package-watch-for-default-compiler" , cuex . EnableExternalPackageWatchForDefaultCompiler , "Enable external package watch for default compiler" )
2022-11-28 17:56:38 +08:00
s . ControllerArgs . AddFlags ( fss . FlagSet ( "controllerArgs" ) , s . ControllerArgs )
cfs := fss . FlagSet ( "commonconfig" )
cfs . DurationVar ( & commonconfig . ApplicationReSyncPeriod , "application-re-sync-period" , commonconfig . ApplicationReSyncPeriod ,
"Re-sync period for application to re-sync, also known as the state-keep interval." )
cfs . BoolVar ( & commonconfig . PerfEnabled , "perf-enabled" , commonconfig . PerfEnabled , "Enable performance logging for controllers, disabled by default." )
ofs := fss . FlagSet ( "oam" )
ofs . StringVar ( & oam . SystemDefinitionNamespace , "system-definition-namespace" , "vela-system" , "define the namespace of the system-level definition" )
standardcontroller . AddOptimizeFlags ( fss . FlagSet ( "optimize" ) )
standardcontroller . AddAdmissionFlags ( fss . FlagSet ( "admission" ) )
rfs := fss . FlagSet ( "resourcekeeper" )
rfs . IntVar ( & resourcekeeper . MaxDispatchConcurrent , "max-dispatch-concurrent" , 10 , "Set the max dispatch concurrent number, default is 10" )
wfs := fss . FlagSet ( "wfTypes" )
wfs . IntVar ( & wfTypes . MaxWorkflowWaitBackoffTime , "max-workflow-wait-backoff-time" , 60 , "Set the max workflow wait backoff time, default is 60" )
2023-06-06 09:52:09 +08:00
wfs . IntVar ( & wfTypes . MaxWorkflowFailedBackoffTime , "max-workflow-failed-backoff-time" , 300 , "Set the max workflow failed backoff time, default is 300" )
2022-11-28 17:56:38 +08:00
wfs . IntVar ( & wfTypes . MaxWorkflowStepErrorRetryTimes , "max-workflow-step-error-retry-times" , 10 , "Set the max workflow step error retry times, default is 10" )
pkgmulticluster . AddFlags ( fss . FlagSet ( "multicluster" ) )
ctrlrec . AddFlags ( fss . FlagSet ( "controllerreconciles" ) )
utilfeature . DefaultMutableFeatureGate . AddFlag ( fss . FlagSet ( "featuregate" ) )
2023-01-31 13:03:29 +08:00
sharding . AddFlags ( fss . FlagSet ( "sharding" ) )
2022-11-28 17:56:38 +08:00
kfs := fss . FlagSet ( "klog" )
2023-01-31 16:55:37 +08:00
pkgclient . AddTimeoutControllerClientFlags ( fss . FlagSet ( "controllerclient" ) )
2023-01-31 13:03:29 +08:00
utillog . AddFlags ( kfs )
2023-06-12 10:41:02 +08:00
profiling . AddFlags ( fss . FlagSet ( "profiling" ) )
2022-11-28 17:56:38 +08:00
if s . LogDebug {
_ = kfs . Set ( "v" , strconv . Itoa ( int ( commonconfig . LogDebug ) ) )
}
if s . LogFilePath != "" {
_ = kfs . Set ( "logtostderr" , "false" )
_ = kfs . Set ( "log_file" , s . LogFilePath )
_ = kfs . Set ( "log_file_max_size" , strconv . FormatUint ( s . LogFileMaxSize , 10 ) )
}
return fss
}