This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from everpeace/stress-test
stress test in e2e
- Loading branch information
Showing
7 changed files
with
199 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
nodes: | ||
- role: control-plane | ||
kubeadmConfigPatches: | ||
- | | ||
kind: ClusterConfiguration | ||
controllerManager: | ||
extraArgs: | ||
node-cidr-mask-size: "23" | ||
- | | ||
kind: InitConfiguration | ||
nodeRegistration: | ||
kubeletExtraArgs: | ||
max-pods: "300" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to Shingo Omura under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Shingo Omura licenses this file to you 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 integration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/everpeace/kube-throttler/pkg/apis/schedule/v1alpha1" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var _ = Describe("Clusterthrottle Stress Test", func() { | ||
ctx := context.Background() | ||
|
||
var nClThr = 50 | ||
var nNs = 10 | ||
var nPodsInNs = 10 | ||
var totalCpuReq = fmt.Sprintf("%dm", nNs*nPodsInNs) | ||
thrName := func(i int) string { return fmt.Sprintf("clthr-%d", i) } | ||
nsName := func(i int) string { return fmt.Sprintf("ns-%d", i) } | ||
podName := func(i int) string { return fmt.Sprintf("pod-%d", i) } | ||
|
||
Context(fmt.Sprintf("%d clusterthrottle x (%d pod x %d namespace)", nClThr, nPodsInNs, nNs), func() { | ||
nsKey, nsVal := "targetns", "true" | ||
thrKey, thrVal := "clthr-target", "true" | ||
|
||
clthrs := make([]*v1alpha1.ClusterThrottle, nClThr) | ||
nss := make([]*corev1.Namespace, nNs) | ||
pods := make([]*corev1.Pod, nNs*nPodsInNs) | ||
|
||
AfterEach(func() { | ||
MustDeleteAllClusterThrottlesInNs(ctx) | ||
for _, ns := range nss { | ||
MustDeleteAllPodsInNs(ctx, ns.Name) | ||
MustDeleteNs(ctx, ns.Name) | ||
} | ||
}) | ||
|
||
BeforeEach(func() { | ||
for i := range clthrs { | ||
clthrs[i] = MustCreateClusterThrottle(ctx, | ||
MakeClusterThrottle(thrName(i)).Selectors(nsKey, nsVal, thrKey, thrVal). | ||
ThresholdPod(nNs*nPodsInNs). | ||
ThresholdCpu(totalCpuReq). | ||
Obj(), | ||
) | ||
} | ||
for i := range nss { | ||
nss[i] = MustCreateNamespace(ctx, MakeNamespace(nsName(i)).Label(nsKey, nsVal).Obj()) | ||
for j := 0; j < nPodsInNs; j++ { | ||
pods[i*nPodsInNs+j] = MustCreatePod(ctx, MakePod(nss[i].Name, podName(j), "1m").Label(thrKey, thrVal).Obj()) | ||
} | ||
} | ||
}) | ||
It("works correctly", func() { | ||
Eventually(AsyncAll( | ||
WakeupBackoffPod(ctx), | ||
AsyncPods(pods, func(p *corev1.Pod) func(g Gomega) { return PodIsScheduled(ctx, p.Namespace, p.Name) }), | ||
AsyncClusterThrottles(clthrs, func(thr *v1alpha1.ClusterThrottle) func(g Gomega) { | ||
return ClusterThottleHasStatus(ctx, thr.Name, | ||
ClthrOpts.WithCalculatedThreshold(thr.Spec.Threshold), | ||
ClthrOpts.WithUsedPod(nNs*nPodsInNs), | ||
ClthrOpts.WithUsedCpuReq(totalCpuReq), | ||
ClthrOpts.WithPodThrottled(true), ClthrOpts.WithCpuThrottled(true), | ||
) | ||
}), | ||
)).Should(Succeed()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed to Shingo Omura under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Shingo Omura licenses this file to you 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 integration | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func MustCreateNamespace(ctx context.Context, ns *corev1.Namespace) *corev1.Namespace { | ||
var err error | ||
created, err := k8sCli.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
return created | ||
} | ||
|
||
func MustDeleteNs(ctx context.Context, ns string) { | ||
Expect( | ||
k8sCli.CoreV1().Namespaces().Delete(ctx, ns, metav1.DeleteOptions{}), | ||
).NotTo(HaveOccurred()) | ||
Eventually(func(g Gomega) { | ||
_, err := k8sCli.CoreV1().Namespaces().Get(ctx, ns, metav1.GetOptions{}) | ||
g.Expect(err).To(HaveOccurred()) | ||
g.Expect(apierrors.IsNotFound(err)).Should(BeTrue()) | ||
}, 10*time.Second).Should(Succeed()) | ||
} | ||
|
||
type namespaceWrapper struct { | ||
corev1.Namespace | ||
} | ||
|
||
func MakeNamespace(name string) *namespaceWrapper { | ||
return &namespaceWrapper{ | ||
Namespace: corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: name, Labels: map[string]string{}}}, | ||
} | ||
} | ||
|
||
func (w *namespaceWrapper) Label(key, val string) *namespaceWrapper { | ||
w.Labels[key] = val | ||
return w | ||
} | ||
|
||
func (w *namespaceWrapper) Obj() *corev1.Namespace { | ||
return &w.Namespace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters