github.com/cilium/cilium@v1.16.2/pkg/clustermesh/endpointslicesync/cell.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package endpointslicesync 5 6 import ( 7 "time" 8 9 "github.com/cilium/hive/cell" 10 "github.com/cilium/hive/job" 11 "github.com/sirupsen/logrus" 12 "github.com/spf13/pflag" 13 14 "github.com/cilium/cilium/pkg/clustermesh/operator" 15 k8sClient "github.com/cilium/cilium/pkg/k8s/client" 16 "github.com/cilium/cilium/pkg/k8s/resource" 17 slim_corev1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1" 18 "github.com/cilium/cilium/pkg/metrics" 19 ) 20 21 const subsystem = "clustermesh" 22 23 // Cell is the cell for the Operator ClusterMesh 24 var Cell = cell.Module( 25 "endpointslicesync-clustermesh", 26 "EndpointSlice clustermesh synchronization in the Cilium operator", 27 cell.Config(EndpointSliceSyncConfig{}), 28 cell.Invoke(registerEndpointSliceSync), 29 30 metrics.Metric(NewMetrics), 31 ) 32 33 type endpointSliceSyncParams struct { 34 cell.In 35 36 operator.ClusterMeshConfig 37 EndpointSliceSyncConfig 38 Logger logrus.FieldLogger 39 JobGroup job.Group 40 41 Clientset k8sClient.Clientset 42 Services resource.Resource[*slim_corev1.Service] 43 ClusterMesh operator.ClusterMesh 44 } 45 46 // EndpointSliceSyncConfig contains the configuration for endpointSliceSync inside the operator. 47 type EndpointSliceSyncConfig struct { 48 // ClusterMeshConcurrentEndpointSync the number of service endpoint syncing operations 49 // that will be done concurrently by the EndpointSlice Cluster Mesh controller. 50 ClusterMeshConcurrentEndpointSync int `mapstructure:"clustermesh-concurrent-service-endpoint-syncs"` 51 // ClusterMeshEndpointUpdatesBatchPeriod describes the length of endpoint updates batching period. 52 // Processing of cluster service changes will be delayed by this duration to join them with potential 53 // upcoming updates and reduce the overall number of endpoints updates. 54 ClusterMeshEndpointUpdatesBatchPeriod time.Duration `mapstructure:"clustermesh-endpoint-updates-batch-period"` 55 // ClusterMeshEndpointsPerSlice is the maximum number of endpoints that 56 // will be added to an EndpointSlice synced from a remote cluster. 57 // More endpoints per slice will result in less endpoint slices, but larger resources. Defaults to 100. 58 ClusterMeshMaxEndpointsPerSlice int `mapstructure:"clustermesh-endpoints-per-slice"` 59 } 60 61 // Flags adds the flags used by ClientConfig. 62 func (cfg EndpointSliceSyncConfig) Flags(flags *pflag.FlagSet) { 63 flags.IntVar(&cfg.ClusterMeshConcurrentEndpointSync, 64 "clustermesh-concurrent-service-endpoint-syncs", 65 5, // This currently mirrors the same default value as the endpointslice Kubernetes controller https://github.com/kubernetes/kubernetes/blob/v1.29.0/cmd/kube-controller-manager/app/options/endpointslicecontroller.go#L45 66 "The number of remote cluster service syncing operations that will be done concurrently. Larger number = faster endpoint slice updating, but more CPU (and network) load.", 67 ) 68 flags.DurationVar(&cfg.ClusterMeshEndpointUpdatesBatchPeriod, 69 "clustermesh-endpoint-updates-batch-period", 70 time.Millisecond*500, 71 "The length of endpoint slice updates batching period for remote cluster services. Processing of pod changes will be delayed by this duration to join them with potential upcoming updates and reduce the overall number of endpoints updates. Larger number = higher endpoint programming latency, but lower number of endpoints revision generated.", 72 ) 73 flags.IntVar(&cfg.ClusterMeshMaxEndpointsPerSlice, 74 "clustermesh-endpoints-per-slice", 75 100, 76 "The maximum number of endpoints that will be added to a remote cluster's EndpointSlice . More endpoints per slice will result in less endpoint slices, but larger resources.", 77 ) 78 }