2015-04-09 21:50:27 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-04-09 21:50:27 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package framework
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2015-12-02 09:46:27 +00:00
|
|
|
"net"
|
2015-04-09 21:50:27 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2015-12-21 05:27:49 +00:00
|
|
|
goruntime "runtime"
|
2015-04-09 21:50:27 +00:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2015-08-05 22:05:17 +00:00
|
|
|
"github.com/golang/glog"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
2016-03-16 14:17:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2016-04-15 22:30:15 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/apps"
|
2016-02-08 14:03:59 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
2016-02-17 22:06:35 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/batch"
|
2016-04-15 01:09:24 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/certificates"
|
2015-12-08 14:21:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2016-05-07 00:03:43 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/policy"
|
2016-05-25 21:25:56 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
2016-09-01 15:29:26 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/storage"
|
2016-02-05 21:58:03 +00:00
|
|
|
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
2015-09-03 21:40:58 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/record"
|
2016-02-12 18:58:43 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/restclient"
|
2015-09-03 21:43:19 +00:00
|
|
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
2015-10-06 09:12:00 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller"
|
2015-10-10 03:58:57 +00:00
|
|
|
replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
|
2015-11-16 21:46:00 +00:00
|
|
|
"k8s.io/kubernetes/pkg/genericapiserver"
|
2016-07-12 20:44:36 +00:00
|
|
|
"k8s.io/kubernetes/pkg/genericapiserver/authorizer"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl"
|
2015-10-27 13:18:45 +00:00
|
|
|
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/master"
|
2015-12-21 05:27:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2016-04-20 04:11:39 +00:00
|
|
|
"k8s.io/kubernetes/pkg/storage/storagebackend"
|
2016-07-04 14:52:55 +00:00
|
|
|
utilnet "k8s.io/kubernetes/pkg/util/net"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/plugin/pkg/admission/admit"
|
2016-06-12 20:33:31 +00:00
|
|
|
|
2016-08-18 15:12:26 +00:00
|
|
|
"github.com/go-openapi/spec"
|
2016-06-12 20:33:31 +00:00
|
|
|
"github.com/pborman/uuid"
|
2016-09-14 00:11:36 +00:00
|
|
|
"k8s.io/kubernetes/pkg/generated/openapi"
|
2015-04-09 21:50:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-05-21 21:10:25 +00:00
|
|
|
// Timeout used in benchmarks, to eg: scale an rc
|
2015-04-09 21:50:27 +00:00
|
|
|
DefaultTimeout = 30 * time.Minute
|
|
|
|
|
|
|
|
// Rc manifest used to create pods for benchmarks.
|
|
|
|
// TODO: Convert this to a full path?
|
|
|
|
TestRCManifest = "benchmark-controller.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MasterComponents is a control struct for all master components started via NewMasterComponents.
|
|
|
|
// TODO: Include all master components (scheduler, nodecontroller).
|
|
|
|
// TODO: Reconcile with integration.go, currently the master used there doesn't understand
|
|
|
|
// how to restart cleanly, which is required for each iteration of a benchmark. The integration
|
|
|
|
// tests also don't make it easy to isolate and turn off components at will.
|
|
|
|
type MasterComponents struct {
|
|
|
|
// Raw http server in front of the master
|
|
|
|
ApiServer *httptest.Server
|
2015-07-24 11:09:49 +00:00
|
|
|
// Kubernetes master, contains an embedded etcd storage
|
2015-04-09 21:50:27 +00:00
|
|
|
KubeMaster *master.Master
|
|
|
|
// Restclient used to talk to the kubernetes master
|
|
|
|
RestClient *client.Client
|
|
|
|
// Replication controller manager
|
2015-07-31 11:38:04 +00:00
|
|
|
ControllerManager *replicationcontroller.ReplicationManager
|
2015-04-09 21:50:27 +00:00
|
|
|
// Channel for stop signals to rc manager
|
|
|
|
rcStopCh chan struct{}
|
|
|
|
// Used to stop master components individually, and via MasterComponents.Stop
|
|
|
|
once sync.Once
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config is a struct of configuration directives for NewMasterComponents.
|
|
|
|
type Config struct {
|
|
|
|
// If nil, a default is used, partially filled configs will not get populated.
|
|
|
|
MasterConfig *master.Config
|
|
|
|
StartReplicationManager bool
|
|
|
|
// Client throttling qps
|
|
|
|
QPS float32
|
|
|
|
// Client burst qps, also burst replicas allowed in rc manager
|
|
|
|
Burst int
|
|
|
|
// TODO: Add configs for endpoints controller, scheduler etc
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMasterComponents creates, initializes and starts master components based on the given config.
|
|
|
|
func NewMasterComponents(c *Config) *MasterComponents {
|
2015-09-30 07:56:51 +00:00
|
|
|
m, s := startMasterOrDie(c.MasterConfig)
|
2015-04-09 21:50:27 +00:00
|
|
|
// TODO: Allow callers to pipe through a different master url and create a client/start components using it.
|
|
|
|
glog.Infof("Master %+v", s.URL)
|
2016-01-15 05:00:58 +00:00
|
|
|
// TODO: caesarxuchao: remove this client when the refactoring of client libraray is done.
|
2016-02-12 18:58:43 +00:00
|
|
|
restClient := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}, QPS: c.QPS, Burst: c.Burst})
|
|
|
|
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}, QPS: c.QPS, Burst: c.Burst})
|
2015-04-09 21:50:27 +00:00
|
|
|
rcStopCh := make(chan struct{})
|
2016-04-14 18:00:52 +00:00
|
|
|
controllerManager := replicationcontroller.NewReplicationManagerFromClient(clientset, controller.NoResyncPeriodFunc, c.Burst, 4096)
|
2015-04-09 21:50:27 +00:00
|
|
|
|
|
|
|
// TODO: Support events once we can cleanly shutdown an event recorder.
|
|
|
|
controllerManager.SetEventRecorder(&record.FakeRecorder{})
|
|
|
|
if c.StartReplicationManager {
|
2015-12-21 05:27:49 +00:00
|
|
|
go controllerManager.Run(goruntime.NumCPU(), rcStopCh)
|
2015-04-09 21:50:27 +00:00
|
|
|
}
|
|
|
|
return &MasterComponents{
|
|
|
|
ApiServer: s,
|
|
|
|
KubeMaster: m,
|
|
|
|
RestClient: restClient,
|
|
|
|
ControllerManager: controllerManager,
|
|
|
|
rcStopCh: rcStopCh,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// startMasterOrDie starts a kubernetes master and an httpserver to handle api requests
|
2015-09-30 07:56:51 +00:00
|
|
|
func startMasterOrDie(masterConfig *master.Config) (*master.Master, *httptest.Server) {
|
2015-04-09 21:50:27 +00:00
|
|
|
var m *master.Master
|
|
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
m.Handler.ServeHTTP(w, req)
|
|
|
|
}))
|
|
|
|
|
|
|
|
if masterConfig == nil {
|
2015-12-02 09:46:27 +00:00
|
|
|
masterConfig = NewMasterConfig()
|
2016-09-28 18:52:28 +00:00
|
|
|
masterConfig.GenericConfig.EnableProfiling = true
|
|
|
|
masterConfig.GenericConfig.EnableSwaggerSupport = true
|
|
|
|
masterConfig.GenericConfig.EnableOpenAPISupport = true
|
|
|
|
masterConfig.GenericConfig.OpenAPIInfo = spec.Info{
|
2016-08-18 15:12:26 +00:00
|
|
|
InfoProps: spec.InfoProps{
|
|
|
|
Title: "Kubernetes",
|
|
|
|
Version: "unversioned",
|
|
|
|
},
|
|
|
|
}
|
2016-09-28 18:52:28 +00:00
|
|
|
masterConfig.GenericConfig.OpenAPIDefaultResponse = spec.Response{
|
2016-08-18 15:12:26 +00:00
|
|
|
ResponseProps: spec.ResponseProps{
|
|
|
|
Description: "Default Response.",
|
|
|
|
},
|
|
|
|
}
|
2015-04-09 21:50:27 +00:00
|
|
|
}
|
2016-09-27 15:52:31 +00:00
|
|
|
m, err := masterConfig.Complete().New()
|
2016-02-03 22:26:11 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("error in bringing up the master: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-08-26 15:06:27 +00:00
|
|
|
// TODO have this start method actually use the normal start sequence for the API server
|
|
|
|
// this method never actually calls the `Run` method for the API server
|
|
|
|
// fire the post hooks ourselves
|
|
|
|
m.GenericAPIServer.RunPostStartHooks(genericapiserver.PostStartHookContext{})
|
|
|
|
|
2015-09-30 07:56:51 +00:00
|
|
|
return m, s
|
2015-04-09 21:50:27 +00:00
|
|
|
}
|
2015-12-02 09:46:27 +00:00
|
|
|
|
2016-07-04 14:52:55 +00:00
|
|
|
func parseCIDROrDie(cidr string) *net.IPNet {
|
|
|
|
_, parsed, err := net.ParseCIDR(cidr)
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("error while parsing CIDR: %s", cidr)
|
|
|
|
}
|
|
|
|
return parsed
|
|
|
|
}
|
|
|
|
|
2015-12-02 09:46:27 +00:00
|
|
|
// Returns a basic master config.
|
|
|
|
func NewMasterConfig() *master.Config {
|
2016-04-20 04:11:39 +00:00
|
|
|
config := storagebackend.Config{
|
2016-06-20 08:40:49 +00:00
|
|
|
ServerList: []string{GetEtcdURLFromEnv()},
|
2016-06-16 21:27:12 +00:00
|
|
|
// This causes the integration tests to exercise the etcd
|
|
|
|
// prefix code, so please don't change without ensuring
|
|
|
|
// sufficient coverage in other ways.
|
2016-06-12 20:33:31 +00:00
|
|
|
Prefix: uuid.New(),
|
2016-03-16 14:17:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-23 19:00:28 +00:00
|
|
|
negotiatedSerializer := NewSingleContentTypeSerializer(api.Scheme, testapi.Default.Codec(), runtime.ContentTypeJSON)
|
2016-03-16 14:17:04 +00:00
|
|
|
|
2016-04-23 19:00:28 +00:00
|
|
|
storageFactory := genericapiserver.NewDefaultStorageFactory(config, runtime.ContentTypeJSON, negotiatedSerializer, genericapiserver.NewDefaultResourceEncodingConfig(), master.DefaultAPIResourceConfigSource())
|
2016-03-16 14:17:04 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: api.GroupName, Resource: genericapiserver.AllResources},
|
2016-04-23 19:00:28 +00:00
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Default.Codec(), runtime.ContentTypeJSON))
|
2016-03-16 14:17:04 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: autoscaling.GroupName, Resource: genericapiserver.AllResources},
|
2016-04-23 19:00:28 +00:00
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Autoscaling.Codec(), runtime.ContentTypeJSON))
|
2016-03-16 14:17:04 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: batch.GroupName, Resource: genericapiserver.AllResources},
|
2016-04-23 19:00:28 +00:00
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Batch.Codec(), runtime.ContentTypeJSON))
|
2016-03-16 14:17:04 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: apps.GroupName, Resource: genericapiserver.AllResources},
|
2016-04-23 19:00:28 +00:00
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Apps.Codec(), runtime.ContentTypeJSON))
|
2016-03-16 14:17:04 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: extensions.GroupName, Resource: genericapiserver.AllResources},
|
2016-04-23 19:00:28 +00:00
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Extensions.Codec(), runtime.ContentTypeJSON))
|
2016-05-07 00:03:43 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: policy.GroupName, Resource: genericapiserver.AllResources},
|
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Policy.Codec(), runtime.ContentTypeJSON))
|
2016-05-25 21:25:56 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: rbac.GroupName, Resource: genericapiserver.AllResources},
|
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Rbac.Codec(), runtime.ContentTypeJSON))
|
2016-04-15 01:09:24 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: certificates.GroupName, Resource: genericapiserver.AllResources},
|
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Certificates.Codec(), runtime.ContentTypeJSON))
|
2016-09-01 15:29:26 +00:00
|
|
|
storageFactory.SetSerializer(
|
|
|
|
unversioned.GroupResource{Group: storage.GroupName, Resource: genericapiserver.AllResources},
|
|
|
|
"",
|
|
|
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Storage.Codec(), runtime.ContentTypeJSON))
|
2015-12-02 09:46:27 +00:00
|
|
|
|
|
|
|
return &master.Config{
|
2016-09-28 18:52:28 +00:00
|
|
|
GenericConfig: &genericapiserver.Config{
|
2016-03-22 16:45:23 +00:00
|
|
|
APIResourceConfigSource: master.DefaultAPIResourceConfigSource(),
|
|
|
|
APIPrefix: "/api",
|
|
|
|
APIGroupPrefix: "/apis",
|
2016-07-12 20:44:36 +00:00
|
|
|
Authorizer: authorizer.NewAlwaysAllowAuthorizer(),
|
2016-03-22 16:45:23 +00:00
|
|
|
AdmissionControl: admit.NewAlwaysAdmit(),
|
|
|
|
Serializer: api.Codecs,
|
2016-07-04 14:52:55 +00:00
|
|
|
// Set those values to avoid annoying warnings in logs.
|
|
|
|
ServiceClusterIPRange: parseCIDROrDie("10.0.0.0/24"),
|
|
|
|
ServiceNodePortRange: utilnet.PortRange{Base: 30000, Size: 2768},
|
2016-09-06 11:20:36 +00:00
|
|
|
EnableVersion: true,
|
2016-09-14 00:11:36 +00:00
|
|
|
OpenAPIDefinitions: openapi.OpenAPIDefinitions,
|
|
|
|
EnableOpenAPISupport: true,
|
2015-11-16 21:46:00 +00:00
|
|
|
},
|
2016-09-19 18:52:41 +00:00
|
|
|
StorageFactory: storageFactory,
|
|
|
|
EnableWatchCache: true,
|
|
|
|
KubeletClient: kubeletclient.FakeKubeletClient{},
|
2015-12-02 09:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the master config appropriate for most integration tests.
|
|
|
|
func NewIntegrationTestMasterConfig() *master.Config {
|
|
|
|
masterConfig := NewMasterConfig()
|
|
|
|
masterConfig.EnableCoreControllers = true
|
2016-09-28 18:52:28 +00:00
|
|
|
masterConfig.GenericConfig.EnableIndex = true
|
|
|
|
masterConfig.GenericConfig.EnableVersion = true
|
|
|
|
masterConfig.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
|
|
|
masterConfig.GenericConfig.APIResourceConfigSource = master.DefaultAPIResourceConfigSource()
|
2015-12-02 09:46:27 +00:00
|
|
|
return masterConfig
|
|
|
|
}
|
2015-04-09 21:50:27 +00:00
|
|
|
|
|
|
|
func (m *MasterComponents) stopRCManager() {
|
|
|
|
close(m.rcStopCh)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MasterComponents) Stop(apiServer, rcManager bool) {
|
|
|
|
glog.Infof("Stopping master components")
|
|
|
|
if rcManager {
|
|
|
|
// Ordering matters because the apiServer will only shutdown when pending
|
|
|
|
// requests are done
|
|
|
|
m.once.Do(m.stopRCManager)
|
|
|
|
}
|
|
|
|
if apiServer {
|
2016-04-21 11:50:55 +00:00
|
|
|
m.ApiServer.Close()
|
2015-04-09 21:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 12:53:41 +00:00
|
|
|
func CreateTestingNamespace(baseName string, apiserver *httptest.Server, t *testing.T) *api.Namespace {
|
|
|
|
// TODO: Create a namespace with a given basename.
|
|
|
|
// Currently we neither create the namespace nor delete all its contents at the end.
|
|
|
|
// But as long as tests are not using the same namespaces, this should work fine.
|
|
|
|
return &api.Namespace{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
// TODO: Once we start creating namespaces, switch to GenerateName.
|
|
|
|
Name: baseName,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteTestingNamespace(ns *api.Namespace, apiserver *httptest.Server, t *testing.T) {
|
|
|
|
// TODO: Remove all resources from a given namespace once we implement CreateTestingNamespace.
|
|
|
|
}
|
|
|
|
|
2015-04-09 21:50:27 +00:00
|
|
|
// RCFromManifest reads a .json file and returns the rc in it.
|
|
|
|
func RCFromManifest(fileName string) *api.ReplicationController {
|
|
|
|
data, err := ioutil.ReadFile(fileName)
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Unexpected error reading rc manifest %v", err)
|
|
|
|
}
|
|
|
|
var controller api.ReplicationController
|
2015-12-21 05:27:49 +00:00
|
|
|
if err := runtime.DecodeInto(testapi.Default.Codec(), data, &controller); err != nil {
|
2015-04-09 21:50:27 +00:00
|
|
|
glog.Fatalf("Unexpected error reading rc manifest %v", err)
|
|
|
|
}
|
|
|
|
return &controller
|
|
|
|
}
|
|
|
|
|
|
|
|
// StopRC stops the rc via kubectl's stop library
|
2016-09-21 14:20:25 +00:00
|
|
|
func StopRC(rc *api.ReplicationController, clientset clientset.Interface) error {
|
|
|
|
reaper, err := kubectl.ReaperFor(api.Kind("ReplicationController"), clientset)
|
2015-04-09 21:50:27 +00:00
|
|
|
if err != nil || reaper == nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-12 14:42:29 +00:00
|
|
|
err = reaper.Stop(rc.Namespace, rc.Name, 0, nil)
|
2015-04-09 21:50:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:10:25 +00:00
|
|
|
// ScaleRC scales the given rc to the given replicas.
|
2016-09-21 14:20:25 +00:00
|
|
|
func ScaleRC(name, ns string, replicas int32, clientset clientset.Interface) (*api.ReplicationController, error) {
|
|
|
|
scaler, err := kubectl.ScalerFor(api.Kind("ReplicationController"), clientset)
|
2015-04-09 21:50:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-08-08 01:52:23 +00:00
|
|
|
retry := &kubectl.RetryParams{Interval: 50 * time.Millisecond, Timeout: DefaultTimeout}
|
|
|
|
waitForReplicas := &kubectl.RetryParams{Interval: 50 * time.Millisecond, Timeout: DefaultTimeout}
|
2015-05-21 21:10:25 +00:00
|
|
|
err = scaler.Scale(ns, name, uint(replicas), nil, retry, waitForReplicas)
|
2015-04-09 21:50:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-09-21 14:20:25 +00:00
|
|
|
scaled, err := clientset.Core().ReplicationControllers(ns).Get(name)
|
2015-04-09 21:50:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-05-21 21:10:25 +00:00
|
|
|
return scaled, nil
|
2015-04-09 21:50:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 13:16:13 +00:00
|
|
|
func RunAMaster(masterConfig *master.Config) (*master.Master, *httptest.Server) {
|
|
|
|
if masterConfig == nil {
|
|
|
|
masterConfig = NewMasterConfig()
|
2016-09-28 18:52:28 +00:00
|
|
|
masterConfig.GenericConfig.EnableProfiling = true
|
2016-02-03 22:26:11 +00:00
|
|
|
}
|
2016-07-04 13:16:13 +00:00
|
|
|
return startMasterOrDie(masterConfig)
|
2015-04-09 21:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Task is a function passed to worker goroutines by RunParallel.
|
|
|
|
// The function needs to implement its own thread safety.
|
|
|
|
type Task func(id int) error
|
|
|
|
|
|
|
|
// RunParallel spawns a goroutine per task in the given queue
|
|
|
|
func RunParallel(task Task, numTasks, numWorkers int) {
|
|
|
|
start := time.Now()
|
|
|
|
if numWorkers <= 0 {
|
|
|
|
numWorkers = numTasks
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
glog.Infof("RunParallel took %v for %d tasks and %d workers", time.Since(start), numTasks, numWorkers)
|
|
|
|
}()
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
semCh := make(chan struct{}, numWorkers)
|
|
|
|
wg.Add(numTasks)
|
|
|
|
for id := 0; id < numTasks; id++ {
|
|
|
|
go func(id int) {
|
|
|
|
semCh <- struct{}{}
|
|
|
|
err := task(id)
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Worker failed with %v", err)
|
|
|
|
}
|
|
|
|
<-semCh
|
|
|
|
wg.Done()
|
|
|
|
}(id)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
close(semCh)
|
|
|
|
}
|