|
|
|
@@ -84,7 +84,9 @@ type ResourceConsumer struct {
|
|
|
|
|
name string
|
|
|
|
|
controllerName string
|
|
|
|
|
kind string
|
|
|
|
|
framework *framework.Framework
|
|
|
|
|
nsName string
|
|
|
|
|
clientSet clientset.Interface
|
|
|
|
|
internalClientset *internalclientset.Clientset
|
|
|
|
|
cpu chan int
|
|
|
|
|
mem chan int
|
|
|
|
|
customMetric chan int
|
|
|
|
@@ -103,15 +105,15 @@ func GetResourceConsumerImage() string {
|
|
|
|
|
return resourceConsumerImage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewDynamicResourceConsumer(name, kind string, replicas, initCPUTotal, initMemoryTotal, initCustomMetric int, cpuLimit, memLimit int64, f *framework.Framework) *ResourceConsumer {
|
|
|
|
|
return newResourceConsumer(name, kind, replicas, initCPUTotal, initMemoryTotal, initCustomMetric, dynamicConsumptionTimeInSeconds,
|
|
|
|
|
dynamicRequestSizeInMillicores, dynamicRequestSizeInMegabytes, dynamicRequestSizeCustomMetric, cpuLimit, memLimit, f)
|
|
|
|
|
func NewDynamicResourceConsumer(name, nsName, kind string, replicas, initCPUTotal, initMemoryTotal, initCustomMetric int, cpuLimit, memLimit int64, clientset clientset.Interface, internalClientset *internalclientset.Clientset) *ResourceConsumer {
|
|
|
|
|
return newResourceConsumer(name, nsName, kind, replicas, initCPUTotal, initMemoryTotal, initCustomMetric, dynamicConsumptionTimeInSeconds,
|
|
|
|
|
dynamicRequestSizeInMillicores, dynamicRequestSizeInMegabytes, dynamicRequestSizeCustomMetric, cpuLimit, memLimit, clientset, internalClientset)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO this still defaults to replication controller
|
|
|
|
|
func NewStaticResourceConsumer(name string, replicas, initCPUTotal, initMemoryTotal, initCustomMetric int, cpuLimit, memLimit int64, f *framework.Framework) *ResourceConsumer {
|
|
|
|
|
return newResourceConsumer(name, KindRC, replicas, initCPUTotal, initMemoryTotal, initCustomMetric, staticConsumptionTimeInSeconds,
|
|
|
|
|
initCPUTotal/replicas, initMemoryTotal/replicas, initCustomMetric/replicas, cpuLimit, memLimit, f)
|
|
|
|
|
func NewStaticResourceConsumer(name, nsName string, replicas, initCPUTotal, initMemoryTotal, initCustomMetric int, cpuLimit, memLimit int64, clientset clientset.Interface, internalClientset *internalclientset.Clientset) *ResourceConsumer {
|
|
|
|
|
return newResourceConsumer(name, nsName, KindRC, replicas, initCPUTotal, initMemoryTotal, initCustomMetric, staticConsumptionTimeInSeconds,
|
|
|
|
|
initCPUTotal/replicas, initMemoryTotal/replicas, initCustomMetric/replicas, cpuLimit, memLimit, clientset, internalClientset)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@@ -121,15 +123,17 @@ initMemoryTotal argument is in megabytes
|
|
|
|
|
memLimit argument is in megabytes, memLimit is a maximum amount of memory that can be consumed by a single pod
|
|
|
|
|
cpuLimit argument is in millicores, cpuLimit is a maximum amount of cpu that can be consumed by a single pod
|
|
|
|
|
*/
|
|
|
|
|
func newResourceConsumer(name, kind string, replicas, initCPUTotal, initMemoryTotal, initCustomMetric, consumptionTimeInSeconds, requestSizeInMillicores,
|
|
|
|
|
requestSizeInMegabytes int, requestSizeCustomMetric int, cpuLimit, memLimit int64, f *framework.Framework) *ResourceConsumer {
|
|
|
|
|
func newResourceConsumer(name, nsName, kind string, replicas, initCPUTotal, initMemoryTotal, initCustomMetric, consumptionTimeInSeconds, requestSizeInMillicores,
|
|
|
|
|
requestSizeInMegabytes int, requestSizeCustomMetric int, cpuLimit, memLimit int64, clientset clientset.Interface, internalClientset *internalclientset.Clientset) *ResourceConsumer {
|
|
|
|
|
|
|
|
|
|
runServiceAndWorkloadForResourceConsumer(f.ClientSet, f.InternalClientset, f.Namespace.Name, name, kind, replicas, cpuLimit, memLimit)
|
|
|
|
|
runServiceAndWorkloadForResourceConsumer(clientset, internalClientset, nsName, name, kind, replicas, cpuLimit, memLimit)
|
|
|
|
|
rc := &ResourceConsumer{
|
|
|
|
|
name: name,
|
|
|
|
|
controllerName: name + "-ctrl",
|
|
|
|
|
kind: kind,
|
|
|
|
|
framework: f,
|
|
|
|
|
nsName: nsName,
|
|
|
|
|
clientSet: clientset,
|
|
|
|
|
internalClientset: internalClientset,
|
|
|
|
|
cpu: make(chan int),
|
|
|
|
|
mem: make(chan int),
|
|
|
|
|
customMetric: make(chan int),
|
|
|
|
@@ -235,14 +239,13 @@ func (rc *ResourceConsumer) makeConsumeCustomMetric() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rc *ResourceConsumer) sendConsumeCPURequest(millicores int) {
|
|
|
|
|
proxyRequest, err := framework.GetServicesProxyRequest(rc.framework.ClientSet, rc.framework.ClientSet.Core().RESTClient().Post())
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
err = wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
|
|
|
|
|
req := proxyRequest.Namespace(rc.framework.Namespace.Name).
|
|
|
|
|
err := wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
|
|
|
|
|
proxyRequest, err := framework.GetServicesProxyRequest(rc.clientSet, rc.clientSet.Core().RESTClient().Post())
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
req := proxyRequest.Namespace(rc.nsName).
|
|
|
|
|
Context(ctx).
|
|
|
|
|
Name(rc.controllerName).
|
|
|
|
|
Suffix("ConsumeCPU").
|
|
|
|
@@ -250,7 +253,7 @@ func (rc *ResourceConsumer) sendConsumeCPURequest(millicores int) {
|
|
|
|
|
Param("durationSec", strconv.Itoa(rc.consumptionTimeInSeconds)).
|
|
|
|
|
Param("requestSizeMillicores", strconv.Itoa(rc.requestSizeInMillicores))
|
|
|
|
|
framework.Logf("ConsumeCPU URL: %v", *req.URL())
|
|
|
|
|
_, err := req.DoRaw()
|
|
|
|
|
_, err = req.DoRaw()
|
|
|
|
|
if err != nil {
|
|
|
|
|
framework.Logf("ConsumeCPU failure: %v", err)
|
|
|
|
|
return false, nil
|
|
|
|
@@ -263,14 +266,13 @@ func (rc *ResourceConsumer) sendConsumeCPURequest(millicores int) {
|
|
|
|
|
|
|
|
|
|
// sendConsumeMemRequest sends POST request for memory consumption
|
|
|
|
|
func (rc *ResourceConsumer) sendConsumeMemRequest(megabytes int) {
|
|
|
|
|
proxyRequest, err := framework.GetServicesProxyRequest(rc.framework.ClientSet, rc.framework.ClientSet.Core().RESTClient().Post())
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
err = wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
|
|
|
|
|
req := proxyRequest.Namespace(rc.framework.Namespace.Name).
|
|
|
|
|
err := wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
|
|
|
|
|
proxyRequest, err := framework.GetServicesProxyRequest(rc.clientSet, rc.clientSet.Core().RESTClient().Post())
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
req := proxyRequest.Namespace(rc.nsName).
|
|
|
|
|
Context(ctx).
|
|
|
|
|
Name(rc.controllerName).
|
|
|
|
|
Suffix("ConsumeMem").
|
|
|
|
@@ -278,7 +280,7 @@ func (rc *ResourceConsumer) sendConsumeMemRequest(megabytes int) {
|
|
|
|
|
Param("durationSec", strconv.Itoa(rc.consumptionTimeInSeconds)).
|
|
|
|
|
Param("requestSizeMegabytes", strconv.Itoa(rc.requestSizeInMegabytes))
|
|
|
|
|
framework.Logf("ConsumeMem URL: %v", *req.URL())
|
|
|
|
|
_, err := req.DoRaw()
|
|
|
|
|
_, err = req.DoRaw()
|
|
|
|
|
if err != nil {
|
|
|
|
|
framework.Logf("ConsumeMem failure: %v", err)
|
|
|
|
|
return false, nil
|
|
|
|
@@ -291,14 +293,13 @@ func (rc *ResourceConsumer) sendConsumeMemRequest(megabytes int) {
|
|
|
|
|
|
|
|
|
|
// sendConsumeCustomMetric sends POST request for custom metric consumption
|
|
|
|
|
func (rc *ResourceConsumer) sendConsumeCustomMetric(delta int) {
|
|
|
|
|
proxyRequest, err := framework.GetServicesProxyRequest(rc.framework.ClientSet, rc.framework.ClientSet.Core().RESTClient().Post())
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
err = wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
|
|
|
|
|
req := proxyRequest.Namespace(rc.framework.Namespace.Name).
|
|
|
|
|
err := wait.PollImmediate(serviceInitializationInterval, serviceInitializationTimeout, func() (bool, error) {
|
|
|
|
|
proxyRequest, err := framework.GetServicesProxyRequest(rc.clientSet, rc.clientSet.Core().RESTClient().Post())
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
req := proxyRequest.Namespace(rc.nsName).
|
|
|
|
|
Context(ctx).
|
|
|
|
|
Name(rc.controllerName).
|
|
|
|
|
Suffix("BumpMetric").
|
|
|
|
@@ -307,7 +308,7 @@ func (rc *ResourceConsumer) sendConsumeCustomMetric(delta int) {
|
|
|
|
|
Param("durationSec", strconv.Itoa(rc.consumptionTimeInSeconds)).
|
|
|
|
|
Param("requestSizeMetrics", strconv.Itoa(rc.requestSizeCustomMetric))
|
|
|
|
|
framework.Logf("ConsumeCustomMetric URL: %v", *req.URL())
|
|
|
|
|
_, err := req.DoRaw()
|
|
|
|
|
_, err = req.DoRaw()
|
|
|
|
|
if err != nil {
|
|
|
|
|
framework.Logf("ConsumeCustomMetric failure: %v", err)
|
|
|
|
|
return false, nil
|
|
|
|
@@ -320,21 +321,21 @@ func (rc *ResourceConsumer) sendConsumeCustomMetric(delta int) {
|
|
|
|
|
func (rc *ResourceConsumer) GetReplicas() int {
|
|
|
|
|
switch rc.kind {
|
|
|
|
|
case KindRC:
|
|
|
|
|
replicationController, err := rc.framework.ClientSet.Core().ReplicationControllers(rc.framework.Namespace.Name).Get(rc.name, metav1.GetOptions{})
|
|
|
|
|
replicationController, err := rc.clientSet.Core().ReplicationControllers(rc.nsName).Get(rc.name, metav1.GetOptions{})
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
if replicationController == nil {
|
|
|
|
|
framework.Failf(rcIsNil)
|
|
|
|
|
}
|
|
|
|
|
return int(replicationController.Status.ReadyReplicas)
|
|
|
|
|
case KindDeployment:
|
|
|
|
|
deployment, err := rc.framework.ClientSet.Extensions().Deployments(rc.framework.Namespace.Name).Get(rc.name, metav1.GetOptions{})
|
|
|
|
|
deployment, err := rc.clientSet.Extensions().Deployments(rc.nsName).Get(rc.name, metav1.GetOptions{})
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
if deployment == nil {
|
|
|
|
|
framework.Failf(deploymentIsNil)
|
|
|
|
|
}
|
|
|
|
|
return int(deployment.Status.ReadyReplicas)
|
|
|
|
|
case KindReplicaSet:
|
|
|
|
|
rs, err := rc.framework.ClientSet.Extensions().ReplicaSets(rc.framework.Namespace.Name).Get(rc.name, metav1.GetOptions{})
|
|
|
|
|
rs, err := rc.clientSet.Extensions().ReplicaSets(rc.nsName).Get(rc.name, metav1.GetOptions{})
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
if rs == nil {
|
|
|
|
|
framework.Failf(rsIsNil)
|
|
|
|
@@ -402,10 +403,10 @@ func (rc *ResourceConsumer) CleanUp() {
|
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
|
kind, err := kindOf(rc.kind)
|
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
framework.ExpectNoError(framework.DeleteResourceAndPods(rc.framework.ClientSet, rc.framework.InternalClientset, kind, rc.framework.Namespace.Name, rc.name))
|
|
|
|
|
framework.ExpectNoError(rc.framework.ClientSet.Core().Services(rc.framework.Namespace.Name).Delete(rc.name, nil))
|
|
|
|
|
framework.ExpectNoError(framework.DeleteResourceAndPods(rc.framework.ClientSet, rc.framework.InternalClientset, api.Kind("ReplicationController"), rc.framework.Namespace.Name, rc.controllerName))
|
|
|
|
|
framework.ExpectNoError(rc.framework.ClientSet.Core().Services(rc.framework.Namespace.Name).Delete(rc.controllerName, nil))
|
|
|
|
|
framework.ExpectNoError(framework.DeleteResourceAndPods(rc.clientSet, rc.internalClientset, kind, rc.nsName, rc.name))
|
|
|
|
|
framework.ExpectNoError(rc.clientSet.Core().Services(rc.nsName).Delete(rc.name, nil))
|
|
|
|
|
framework.ExpectNoError(framework.DeleteResourceAndPods(rc.clientSet, rc.internalClientset, api.Kind("ReplicationController"), rc.nsName, rc.controllerName))
|
|
|
|
|
framework.ExpectNoError(rc.clientSet.Core().Services(rc.nsName).Delete(rc.controllerName, nil))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func kindOf(kind string) (schema.GroupKind, error) {
|
|
|
|
@@ -516,7 +517,7 @@ func CreateCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, ma
|
|
|
|
|
hpa := &autoscalingv1.HorizontalPodAutoscaler{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
Name: rc.name,
|
|
|
|
|
Namespace: rc.framework.Namespace.Name,
|
|
|
|
|
Namespace: rc.nsName,
|
|
|
|
|
},
|
|
|
|
|
Spec: autoscalingv1.HorizontalPodAutoscalerSpec{
|
|
|
|
|
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
|
|
|
|
@@ -528,11 +529,11 @@ func CreateCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, ma
|
|
|
|
|
TargetCPUUtilizationPercentage: &cpu,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
hpa, errHPA := rc.framework.ClientSet.Autoscaling().HorizontalPodAutoscalers(rc.framework.Namespace.Name).Create(hpa)
|
|
|
|
|
hpa, errHPA := rc.clientSet.Autoscaling().HorizontalPodAutoscalers(rc.nsName).Create(hpa)
|
|
|
|
|
framework.ExpectNoError(errHPA)
|
|
|
|
|
return hpa
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteHorizontalPodAutoscaler(rc *ResourceConsumer, autoscalerName string) {
|
|
|
|
|
rc.framework.ClientSet.Autoscaling().HorizontalPodAutoscalers(rc.framework.Namespace.Name).Delete(autoscalerName, nil)
|
|
|
|
|
rc.clientSet.Autoscaling().HorizontalPodAutoscalers(rc.nsName).Delete(autoscalerName, nil)
|
|
|
|
|
}
|
|
|
|
|