|
| 1 | +/* |
| 2 | +Copyright 2014 The Kubernetes Authors All rights reserved. |
| 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 | +//use for --watch-cache-sizes param of kube-apiserver |
| 18 | +//make watch cache size of resources configurable |
| 19 | +package cachesize |
| 20 | + |
| 21 | +import ( |
| 22 | + "strconv" |
| 23 | + "strings" |
| 24 | + |
| 25 | + "github.com/golang/glog" |
| 26 | +) |
| 27 | + |
| 28 | +type Resource string |
| 29 | + |
| 30 | +const ( |
| 31 | + Controllers Resource = "controllers" |
| 32 | + Daemonsets Resource = "daemonsets" |
| 33 | + Deployments Resource = "deployments" |
| 34 | + Endpoints Resource = "endpoints" |
| 35 | + HorizontalPodAutoscalers Resource = "horizontalpodautoscalers" |
| 36 | + Ingress Resource = "ingress" |
| 37 | + Jobs Resource = "jobs" |
| 38 | + LimitRanges Resource = "limitranges" |
| 39 | + Namespaces Resource = "namespaces" |
| 40 | + Nodes Resource = "nodes" |
| 41 | + PersistentVolumes Resource = "persistentvolumes" |
| 42 | + PersistentVolumeClaims Resource = "persistentvolumeclaims" |
| 43 | + Pods Resource = "pods" |
| 44 | + PodTemplates Resource = "podtemplates" |
| 45 | + ResourceQuotas Resource = "resourcequotas" |
| 46 | + Secrets Resource = "secrets" |
| 47 | + ServiceAccounts Resource = "serviceaccounts" |
| 48 | + Services Resource = "services" |
| 49 | +) |
| 50 | + |
| 51 | +var watchCacheSizes map[Resource]int |
| 52 | + |
| 53 | +func init() { |
| 54 | + watchCacheSizes = make(map[Resource]int) |
| 55 | + watchCacheSizes[Controllers] = 100 |
| 56 | + watchCacheSizes[Daemonsets] = 100 |
| 57 | + watchCacheSizes[Deployments] = 100 |
| 58 | + watchCacheSizes[Endpoints] = 1000 |
| 59 | + watchCacheSizes[HorizontalPodAutoscalers] = 100 |
| 60 | + watchCacheSizes[Ingress] = 100 |
| 61 | + watchCacheSizes[Jobs] = 100 |
| 62 | + watchCacheSizes[LimitRanges] = 100 |
| 63 | + watchCacheSizes[Namespaces] = 100 |
| 64 | + watchCacheSizes[Nodes] = 1000 |
| 65 | + watchCacheSizes[PersistentVolumes] = 100 |
| 66 | + watchCacheSizes[PersistentVolumeClaims] = 100 |
| 67 | + watchCacheSizes[Pods] = 1000 |
| 68 | + watchCacheSizes[PodTemplates] = 100 |
| 69 | + watchCacheSizes[ResourceQuotas] = 100 |
| 70 | + watchCacheSizes[Secrets] = 100 |
| 71 | + watchCacheSizes[ServiceAccounts] = 100 |
| 72 | + watchCacheSizes[Services] = 100 |
| 73 | +} |
| 74 | + |
| 75 | +func SetWatchCacheSizes(cacheSizes []string) { |
| 76 | + for _, c := range cacheSizes { |
| 77 | + tokens := strings.Split(c, "#") |
| 78 | + if len(tokens) != 2 { |
| 79 | + glog.Errorf("invalid value of watch cache capabilities: %s", c) |
| 80 | + continue |
| 81 | + } |
| 82 | + |
| 83 | + size, err := strconv.Atoi(tokens[1]) |
| 84 | + if err != nil { |
| 85 | + glog.Errorf("invalid size of watch cache capabilities: %s", c) |
| 86 | + continue |
| 87 | + } |
| 88 | + |
| 89 | + watchCacheSizes[Resource(strings.ToLower(tokens[0]))] = size |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +func GetWatchCacheSizeByResource(resource Resource) int { |
| 94 | + return watchCacheSizes[resource] |
| 95 | +} |
0 commit comments