policy.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package app implements a server that runs a set of active
  14. // components. This includes replication controllers, service endpoints and
  15. // nodes.
  16. //
  17. package app
  18. import (
  19. "k8s.io/apimachinery/pkg/runtime/schema"
  20. "k8s.io/client-go/dynamic"
  21. "k8s.io/client-go/scale"
  22. "k8s.io/kubernetes/pkg/controller/disruption"
  23. "net/http"
  24. "k8s.io/klog"
  25. )
  26. func startDisruptionController(ctx ControllerContext) (http.Handler, bool, error) {
  27. var group = "policy"
  28. var version = "v1beta1"
  29. var resource = "poddisruptionbudgets"
  30. if !ctx.AvailableResources[schema.GroupVersionResource{Group: group, Version: version, Resource: resource}] {
  31. klog.Infof(
  32. "Refusing to start disruption because resource %q in group %q is not available.",
  33. resource, group+"/"+version)
  34. return nil, false, nil
  35. }
  36. client := ctx.ClientBuilder.ClientOrDie("disruption-controller")
  37. config := ctx.ClientBuilder.ConfigOrDie("disruption-controller")
  38. scaleKindResolver := scale.NewDiscoveryScaleKindResolver(client.Discovery())
  39. scaleClient, err := scale.NewForConfig(config, ctx.RESTMapper, dynamic.LegacyAPIPathResolverFunc, scaleKindResolver)
  40. if err != nil {
  41. return nil, false, err
  42. }
  43. go disruption.NewDisruptionController(
  44. ctx.InformerFactory.Core().V1().Pods(),
  45. ctx.InformerFactory.Policy().V1beta1().PodDisruptionBudgets(),
  46. ctx.InformerFactory.Core().V1().ReplicationControllers(),
  47. ctx.InformerFactory.Apps().V1().ReplicaSets(),
  48. ctx.InformerFactory.Apps().V1().Deployments(),
  49. ctx.InformerFactory.Apps().V1().StatefulSets(),
  50. client,
  51. ctx.RESTMapper,
  52. scaleClient,
  53. ).Run(ctx.Stop)
  54. return nil, true, nil
  55. }