batch.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 unversioned
  14. import (
  15. "k8s.io/kubernetes/pkg/apis/batch"
  16. "k8s.io/kubernetes/pkg/client/restclient"
  17. )
  18. type BatchInterface interface {
  19. JobsNamespacer
  20. ScheduledJobsNamespacer
  21. }
  22. // BatchClient is used to interact with Kubernetes batch features.
  23. type BatchClient struct {
  24. *restclient.RESTClient
  25. }
  26. func (c *BatchClient) Jobs(namespace string) JobInterface {
  27. return newJobsV1(c, namespace)
  28. }
  29. func (c *BatchClient) ScheduledJobs(namespace string) ScheduledJobInterface {
  30. return newScheduledJobs(c, namespace)
  31. }
  32. func NewBatch(c *restclient.Config) (*BatchClient, error) {
  33. config := *c
  34. if err := setGroupDefaults(batch.GroupName, &config); err != nil {
  35. return nil, err
  36. }
  37. client, err := restclient.RESTClientFor(&config)
  38. if err != nil {
  39. return nil, err
  40. }
  41. return &BatchClient{client}, nil
  42. }
  43. func NewBatchOrDie(c *restclient.Config) *BatchClient {
  44. client, err := NewBatch(c)
  45. if err != nil {
  46. panic(err)
  47. }
  48. return client
  49. }