util.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2015 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 benchmark
  14. import (
  15. "k8s.io/apimachinery/pkg/runtime/schema"
  16. clientset "k8s.io/client-go/kubernetes"
  17. restclient "k8s.io/client-go/rest"
  18. "k8s.io/kubernetes/pkg/scheduler/factory"
  19. "k8s.io/kubernetes/test/integration/util"
  20. )
  21. // mustSetupScheduler starts the following components:
  22. // - k8s api server (a.k.a. master)
  23. // - scheduler
  24. // It returns scheduler config factory and destroyFunc which should be used to
  25. // remove resources after finished.
  26. // Notes on rate limiter:
  27. // - client rate limit is set to 5000.
  28. func mustSetupScheduler() (factory.Configurator, util.ShutdownFunc) {
  29. apiURL, apiShutdown := util.StartApiserver()
  30. clientSet := clientset.NewForConfigOrDie(&restclient.Config{
  31. Host: apiURL,
  32. ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}},
  33. QPS: 5000.0,
  34. Burst: 5000,
  35. })
  36. schedulerConfig, schedulerShutdown := util.StartScheduler(clientSet)
  37. shutdownFunc := func() {
  38. schedulerShutdown()
  39. apiShutdown()
  40. }
  41. return schedulerConfig, shutdownFunc
  42. }