batch.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "fmt"
  20. "net/http"
  21. "k8s.io/apimachinery/pkg/runtime/schema"
  22. "k8s.io/kubernetes/pkg/controller/cronjob"
  23. "k8s.io/kubernetes/pkg/controller/job"
  24. )
  25. func startJobController(ctx ControllerContext) (http.Handler, bool, error) {
  26. if !ctx.AvailableResources[schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "jobs"}] {
  27. return nil, false, nil
  28. }
  29. go job.NewJobController(
  30. ctx.InformerFactory.Core().V1().Pods(),
  31. ctx.InformerFactory.Batch().V1().Jobs(),
  32. ctx.ClientBuilder.ClientOrDie("job-controller"),
  33. ).Run(int(ctx.ComponentConfig.JobController.ConcurrentJobSyncs), ctx.Stop)
  34. return nil, true, nil
  35. }
  36. func startCronJobController(ctx ControllerContext) (http.Handler, bool, error) {
  37. if !ctx.AvailableResources[schema.GroupVersionResource{Group: "batch", Version: "v1beta1", Resource: "cronjobs"}] {
  38. return nil, false, nil
  39. }
  40. cjc, err := cronjob.NewController(
  41. ctx.ClientBuilder.ClientOrDie("cronjob-controller"),
  42. )
  43. if err != nil {
  44. return nil, true, fmt.Errorf("error creating CronJob controller: %v", err)
  45. }
  46. go cjc.Run(ctx.Stop)
  47. return nil, true, nil
  48. }