The GC controller does not handle resources under different legacy paths
correctly.
... | ... |
@@ -31,9 +31,11 @@ import ( |
31 | 31 |
kclient "k8s.io/kubernetes/pkg/client/unversioned" |
32 | 32 |
clientadapter "k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset" |
33 | 33 |
"k8s.io/kubernetes/pkg/controller/deployment" |
34 |
+ "k8s.io/kubernetes/pkg/controller/garbagecollector/metaonly" |
|
34 | 35 |
"k8s.io/kubernetes/pkg/master" |
35 | 36 |
"k8s.io/kubernetes/pkg/registry/generic" |
36 | 37 |
"k8s.io/kubernetes/pkg/runtime" |
38 |
+ "k8s.io/kubernetes/pkg/runtime/serializer" |
|
37 | 39 |
"k8s.io/kubernetes/pkg/storage" |
38 | 40 |
storagefactory "k8s.io/kubernetes/pkg/storage/storagebackend/factory" |
39 | 41 |
utilwait "k8s.io/kubernetes/pkg/util/wait" |
... | ... |
@@ -42,6 +44,7 @@ import ( |
42 | 42 |
"k8s.io/kubernetes/pkg/controller/daemon" |
43 | 43 |
"k8s.io/kubernetes/pkg/controller/disruption" |
44 | 44 |
endpointcontroller "k8s.io/kubernetes/pkg/controller/endpoint" |
45 |
+ "k8s.io/kubernetes/pkg/controller/garbagecollector" |
|
45 | 46 |
jobcontroller "k8s.io/kubernetes/pkg/controller/job" |
46 | 47 |
namespacecontroller "k8s.io/kubernetes/pkg/controller/namespace" |
47 | 48 |
nodecontroller "k8s.io/kubernetes/pkg/controller/node" |
... | ... |
@@ -363,6 +366,7 @@ func (c *MasterConfig) RunScheduler() { |
363 | 363 |
s.Run() |
364 | 364 |
} |
365 | 365 |
|
366 |
+// RunGCController handles deletion of terminated pods. |
|
366 | 367 |
func (c *MasterConfig) RunGCController(client *client.Client) { |
367 | 368 |
if c.ControllerManager.TerminatedPodGCThreshold > 0 { |
368 | 369 |
gcController := gccontroller.New(clientadapter.FromUnversionedClient(client), kctrlmgr.ResyncPeriod(c.ControllerManager), int(c.ControllerManager.TerminatedPodGCThreshold)) |
... | ... |
@@ -370,6 +374,33 @@ func (c *MasterConfig) RunGCController(client *client.Client) { |
370 | 370 |
} |
371 | 371 |
} |
372 | 372 |
|
373 |
+// RunGarbageCollectorController starts generic garbage collection for the cluster. |
|
374 |
+func (c *MasterConfig) RunGarbageCollectorController(client *osclient.Client, config *restclient.Config) { |
|
375 |
+ if !c.ControllerManager.EnableGarbageCollector { |
|
376 |
+ return |
|
377 |
+ } |
|
378 |
+ |
|
379 |
+ groupVersionResources, err := client.Discovery().ServerPreferredResources() |
|
380 |
+ if err != nil { |
|
381 |
+ glog.Fatalf("Failed to get supported resources from server: %v", err) |
|
382 |
+ } |
|
383 |
+ |
|
384 |
+ config = restclient.AddUserAgent(config, "generic-garbage-collector") |
|
385 |
+ config.ContentConfig.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: metaonly.NewMetadataCodecFactory()} |
|
386 |
+ // TODO: needs to take GVR |
|
387 |
+ metaOnlyClientPool := dynamic.NewClientPool(config, dynamic.LegacyAPIPathResolverFunc) |
|
388 |
+ config.ContentConfig.NegotiatedSerializer = nil |
|
389 |
+ // TODO: needs to take GVR |
|
390 |
+ clientPool := dynamic.NewClientPool(config, dynamic.LegacyAPIPathResolverFunc) |
|
391 |
+ garbageCollector, err := garbagecollector.NewGarbageCollector(metaOnlyClientPool, clientPool, groupVersionResources) |
|
392 |
+ if err != nil { |
|
393 |
+ glog.Fatalf("Failed to start the garbage collector: %v", err) |
|
394 |
+ } |
|
395 |
+ |
|
396 |
+ workers := int(c.ControllerManager.ConcurrentGCSyncs) |
|
397 |
+ go garbageCollector.Run(workers, utilwait.NeverStop) |
|
398 |
+} |
|
399 |
+ |
|
373 | 400 |
// RunNodeController starts the node controller |
374 | 401 |
// TODO: handle node CIDR and route allocation |
375 | 402 |
func (c *MasterConfig) RunNodeController() { |
... | ... |
@@ -183,8 +183,9 @@ func BuildKubernetesMasterConfig(options configapi.MasterConfig, requestContextM |
183 | 183 |
// Defaults are tested in TestCMServerDefaults |
184 | 184 |
cmserver := cmapp.NewCMServer() |
185 | 185 |
// Adjust defaults |
186 |
- cmserver.Address = "" // no healthz endpoint |
|
187 |
- cmserver.Port = 0 // no healthz endpoint |
|
186 |
+ cmserver.Address = "" // no healthz endpoint |
|
187 |
+ cmserver.Port = 0 // no healthz endpoint |
|
188 |
+ cmserver.EnableGarbageCollector = false // disabled until we add the controller |
|
188 | 189 |
cmserver.PodEvictionTimeout = unversioned.Duration{Duration: podEvictionTimeout} |
189 | 190 |
cmserver.VolumeConfiguration.EnableDynamicProvisioning = options.VolumeConfig.DynamicProvisioningEnabled |
190 | 191 |
|