mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
Configurable cache sizes of cachers
This commit is contained in:
@@ -31,6 +31,7 @@ const (
|
||||
CertificateSigningRequests Resource = "certificatesigningrequests"
|
||||
ClusterRoles Resource = "clusterroles"
|
||||
ClusterRoleBindings Resource = "clusterrolebindings"
|
||||
ConfigMaps Resource = "configmaps"
|
||||
Controllers Resource = "controllers"
|
||||
Daemonsets Resource = "daemonsets"
|
||||
Deployments Resource = "deployments"
|
||||
@@ -47,6 +48,7 @@ const (
|
||||
PersistentVolumes Resource = "persistentvolumes"
|
||||
PersistentVolumeClaims Resource = "persistentvolumeclaims"
|
||||
Pods Resource = "pods"
|
||||
PodSecurityPolicies Resource = "podsecuritypolicies"
|
||||
PodTemplates Resource = "podtemplates"
|
||||
Replicasets Resource = "replicasets"
|
||||
ResourceQuotas Resource = "resourcequotas"
|
||||
@@ -56,40 +58,36 @@ const (
|
||||
Secrets Resource = "secrets"
|
||||
ServiceAccounts Resource = "serviceaccounts"
|
||||
Services Resource = "services"
|
||||
StorageClasses Resource = "storageclasses"
|
||||
|
||||
// Default value of watch cache size for a resource if not specified.
|
||||
defaultWatchCacheSize = 100
|
||||
)
|
||||
|
||||
// TODO: This shouldn't be a global variable.
|
||||
var watchCacheSizes map[Resource]int
|
||||
|
||||
func init() {
|
||||
watchCacheSizes = make(map[Resource]int)
|
||||
watchCacheSizes[CertificateSigningRequests] = 1000
|
||||
watchCacheSizes[ClusterRoles] = 100
|
||||
watchCacheSizes[ClusterRoleBindings] = 100
|
||||
watchCacheSizes[Controllers] = 100
|
||||
watchCacheSizes[Daemonsets] = 100
|
||||
watchCacheSizes[Deployments] = 100
|
||||
watchCacheSizes[Endpoints] = 1000
|
||||
watchCacheSizes[HorizontalPodAutoscalers] = 100
|
||||
watchCacheSizes[Ingress] = 100
|
||||
watchCacheSizes[PetSet] = 100
|
||||
watchCacheSizes[PodDisruptionBudget] = 100
|
||||
watchCacheSizes[Jobs] = 100
|
||||
watchCacheSizes[LimitRanges] = 100
|
||||
watchCacheSizes[Namespaces] = 100
|
||||
watchCacheSizes[NetworkPolicys] = 100
|
||||
watchCacheSizes[Nodes] = 1000
|
||||
watchCacheSizes[PersistentVolumes] = 100
|
||||
watchCacheSizes[PersistentVolumeClaims] = 100
|
||||
watchCacheSizes[Pods] = 1000
|
||||
watchCacheSizes[PodTemplates] = 100
|
||||
watchCacheSizes[Replicasets] = 100
|
||||
watchCacheSizes[ResourceQuotas] = 100
|
||||
watchCacheSizes[ScheduledJobs] = 100
|
||||
watchCacheSizes[Roles] = 100
|
||||
watchCacheSizes[RoleBindings] = 100
|
||||
watchCacheSizes[Secrets] = 100
|
||||
watchCacheSizes[ServiceAccounts] = 100
|
||||
watchCacheSizes[Services] = 100
|
||||
}
|
||||
|
||||
func InitializeWatchCacheSizes(expectedRAMCapacityMB int) {
|
||||
// This is the heuristics that from memory capacity is trying to infer
|
||||
// the maximum number of nodes in the cluster and set cache sizes based
|
||||
// on that value.
|
||||
// From our documentation, we officially recomment 120GB machines for
|
||||
// 2000 nodes, and we scale from that point. Thus we assume ~60MB of
|
||||
// capacity per node.
|
||||
// TODO: Revisit this heuristics
|
||||
clusterSize := expectedRAMCapacityMB / 60
|
||||
|
||||
// We should specify cache size for a given resource only if it
|
||||
// is supposed to have non-default value.
|
||||
//
|
||||
// TODO: Figure out which resource we should have non-default value.
|
||||
watchCacheSizes[Endpoints] = maxInt(10*clusterSize, 1000)
|
||||
watchCacheSizes[Nodes] = maxInt(3*clusterSize, 1000)
|
||||
watchCacheSizes[Pods] = maxInt(10*clusterSize, 1000)
|
||||
}
|
||||
|
||||
func SetWatchCacheSizes(cacheSizes []string) {
|
||||
@@ -111,5 +109,15 @@ func SetWatchCacheSizes(cacheSizes []string) {
|
||||
}
|
||||
|
||||
func GetWatchCacheSizeByResource(resource Resource) int {
|
||||
return watchCacheSizes[resource]
|
||||
if value, found := watchCacheSizes[resource]; found {
|
||||
return value
|
||||
}
|
||||
return defaultWatchCacheSize
|
||||
}
|
||||
|
||||
func maxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user