Skip to content

Commit 419dc4d

Browse files
committed
fix(test): configuration changes and fixes needed to scale-test
Signed-off-by: Alex Castilio dos Santos <[email protected]>
1 parent 1e2081a commit 419dc4d

13 files changed

+218
-112
lines changed

test/e2e/common/common.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
KubeSystemNamespace = "kube-system"
2323
TestPodNamespace = "kube-system-test"
2424
AzureAppInsightsKeyEnv = "AZURE_APP_INSIGHTS_KEY"
25+
OutputFilePathEnv = "OUTPUT_FILEPATH"
2526
)
2627

2728
var (

test/e2e/framework/kubernetes/check-pod-status.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
)
1515

1616
const (
17-
RetryTimeoutPodsReady = 5 * time.Minute
18-
RetryIntervalPodsReady = 5 * time.Second
17+
RetryTimeoutPodsReady = 5 * time.Minute
18+
RetryIntervalPodsReady = 5 * time.Second
19+
timeoutWaitForPodsSeconds = 1200
1920

2021
printInterval = 5 // print to stdout every 5 iterations
2122
)
@@ -48,7 +49,7 @@ func (w *WaitPodsReady) Run() error {
4849
return fmt.Errorf("error creating Kubernetes client: %w", err)
4950
}
5051

51-
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
52+
ctx, cancel := context.WithTimeout(context.Background(), timeoutWaitForPodsSeconds*time.Second)
5253
defer cancel()
5354

5455
return WaitForPodReady(ctx, clientset, w.Namespace, w.LabelSelector)
@@ -60,7 +61,6 @@ func (w *WaitPodsReady) Stop() error {
6061
}
6162

6263
func WaitForPodReady(ctx context.Context, clientset *kubernetes.Clientset, namespace, labelSelector string) error {
63-
podReadyMap := make(map[string]bool)
6464

6565
printIterator := 0
6666
conditionFunc := wait.ConditionWithContextFunc(func(context.Context) (bool, error) {
@@ -78,13 +78,8 @@ func WaitForPodReady(ctx context.Context, clientset *kubernetes.Clientset, names
7878
return false, nil
7979
}
8080

81-
// check each indviidual pod to see if it's in Running state
82-
for i := range podList.Items {
83-
var pod *corev1.Pod
84-
pod, err = clientset.CoreV1().Pods(namespace).Get(ctx, podList.Items[i].Name, metav1.GetOptions{})
85-
if err != nil {
86-
return false, fmt.Errorf("error getting Pod: %w", err)
87-
}
81+
// check each individual pod to see if it's in Running state
82+
for _, pod := range podList.Items {
8883

8984
// Check the Pod phase
9085
if pod.Status.Phase != corev1.PodRunning {
@@ -102,10 +97,6 @@ func WaitForPodReady(ctx context.Context, clientset *kubernetes.Clientset, names
10297
}
10398
}
10499

105-
if !podReadyMap[pod.Name] {
106-
log.Printf("pod \"%s\" is in Running state\n", pod.Name)
107-
podReadyMap[pod.Name] = true
108-
}
109100
}
110101
log.Printf("all pods in namespace \"%s\" with label \"%s\" are in Running state\n", namespace, labelSelector)
111102
return true, nil

test/e2e/framework/kubernetes/create-kapinger-deployment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (c *CreateKapingerDeployment) GetKapingerDeployment() *appsv1.Deployment {
138138
"memory": resource.MustParse("20Mi"),
139139
},
140140
Limits: v1.ResourceList{
141-
"memory": resource.MustParse("20Mi"),
141+
"memory": resource.MustParse("40Mi"),
142142
},
143143
},
144144
Ports: []v1.ContainerPort{

test/e2e/framework/kubernetes/delete-namespace.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
"k8s.io/client-go/util/retry"
1515
)
1616

17+
const (
18+
deleteNamespaceTimeoutSeconds = 1200
19+
)
20+
1721
type DeleteNamespace struct {
1822
Namespace string
1923
KubeConfigFilePath string
@@ -30,7 +34,7 @@ func (d *DeleteNamespace) Run() error {
3034
return fmt.Errorf("error creating Kubernetes client: %w", err)
3135
}
3236

33-
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
37+
ctx, cancel := context.WithTimeout(context.Background(), deleteNamespaceTimeoutSeconds*time.Second)
3438
defer cancel()
3539

3640
err = clientset.CoreV1().Namespaces().Delete(ctx, d.Namespace, metaV1.DeleteOptions{})
@@ -41,7 +45,7 @@ func (d *DeleteNamespace) Run() error {
4145
}
4246

4347
backoff := wait.Backoff{
44-
Steps: 6,
48+
Steps: 9,
4549
Duration: 10 * time.Second,
4650
Factor: 2.0,
4751
// Jitter: 0.1,

test/e2e/framework/kubernetes/install-retina-helm.go

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (i *InstallHelmChart) Run() error {
9191
chart.Values["image"].(map[string]interface{})["repository"] = imageRegistry + "/" + imageNamespace + "/retina-agent"
9292
chart.Values["image"].(map[string]interface{})["initRepository"] = imageRegistry + "/" + imageNamespace + "/retina-init"
9393
chart.Values["operator"].(map[string]interface{})["repository"] = imageRegistry + "/" + imageNamespace + "/retina-operator"
94+
chart.Values["operator"].(map[string]interface{})["enabled"] = true
9495

9596
getclient := action.NewGet(actionConfig)
9697
release, err := getclient.Run(i.ReleaseName)

test/e2e/framework/scaletest/add-shared-labels.go

+37-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"log"
78
"time"
89

910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -12,6 +13,10 @@ import (
1213
"k8s.io/client-go/tools/clientcmd"
1314
)
1415

16+
const (
17+
timeoutToLabelAllPodsMinutes = 120
18+
)
19+
1520
type patchStringValue struct {
1621
Op string `json:"op"`
1722
Path string `json:"path"`
@@ -50,32 +55,21 @@ func (a *AddSharedLabelsToAllPods) Run() error {
5055
return fmt.Errorf("error creating Kubernetes client: %w", err)
5156
}
5257

53-
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
58+
ctx, cancel := contextToLabelAllPods()
5459
defer cancel()
5560

5661
resources, err := clientset.CoreV1().Pods(a.Namespace).List(ctx, metav1.ListOptions{})
5762

58-
patch := []patchStringValue{}
59-
60-
for i := 0; i < a.NumSharedLabelsPerPod; i++ {
61-
patch = append(patch, patchStringValue{
62-
Op: "add",
63-
Path: "/metadata/labels/shared-lab-" + fmt.Sprintf("%05d", i),
64-
Value: "val",
65-
})
66-
}
67-
68-
patchBytes, err := json.Marshal(patch)
63+
patchBytes, err := getSharedLabelsPatch(a.NumSharedLabelsPerPod)
6964
if err != nil {
7065
return fmt.Errorf("error marshalling patch: %w", err)
7166
}
7267

7368
for _, resource := range resources.Items {
74-
clientset.CoreV1().Pods(a.Namespace).Patch(ctx, resource.Name,
75-
types.JSONPatchType,
76-
patchBytes,
77-
metav1.PatchOptions{},
78-
)
69+
err = patchLabel(ctx, clientset, a.Namespace, resource.Name, patchBytes)
70+
if err != nil {
71+
log.Printf("Error adding shared labels to pod %s: %s\n", resource.Name, err)
72+
}
7973
}
8074

8175
return nil
@@ -85,3 +79,29 @@ func (a *AddSharedLabelsToAllPods) Run() error {
8579
func (a *AddSharedLabelsToAllPods) Stop() error {
8680
return nil
8781
}
82+
83+
func patchLabel(ctx context.Context, clientset *kubernetes.Clientset, namespace, podName string, patchBytes []byte) error {
84+
log.Println("Labeling Pod", podName)
85+
_, err := clientset.CoreV1().Pods(namespace).Patch(ctx, podName,
86+
types.JSONPatchType,
87+
patchBytes,
88+
metav1.PatchOptions{},
89+
)
90+
return err
91+
}
92+
93+
func getSharedLabelsPatch(numLabels int) ([]byte, error) {
94+
patch := []patchStringValue{}
95+
for i := 0; i < numLabels; i++ {
96+
patch = append(patch, patchStringValue{
97+
Op: "add",
98+
Path: "/metadata/labels/shared-lab-" + fmt.Sprintf("%05d", i),
99+
Value: "val",
100+
})
101+
}
102+
return json.Marshal(patch)
103+
}
104+
105+
func contextToLabelAllPods() (context.Context, context.CancelFunc) {
106+
return context.WithTimeout(context.Background(), timeoutToLabelAllPodsMinutes*time.Minute)
107+
}

test/e2e/framework/scaletest/add-unique-labels.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package scaletest
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
7-
"time"
86

97
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
"k8s.io/apimachinery/pkg/types"
118
"k8s.io/client-go/kubernetes"
129
"k8s.io/client-go/tools/clientcmd"
1310
)
@@ -44,35 +41,23 @@ func (a *AddUniqueLabelsToAllPods) Run() error {
4441
return fmt.Errorf("error creating Kubernetes client: %w", err)
4542
}
4643

47-
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
44+
ctx, cancel := contextToLabelAllPods()
4845
defer cancel()
4946

5047
resources, err := clientset.CoreV1().Pods(a.Namespace).List(ctx, metav1.ListOptions{})
5148

5249
count := 0
5350

5451
for _, resource := range resources.Items {
55-
patch := []patchStringValue{}
56-
57-
for i := 0; i < a.NumUniqueLabelsPerPod; i++ {
58-
patch = append(patch, patchStringValue{
59-
Op: "add",
60-
Path: "/metadata/labels/uni-lab-" + fmt.Sprintf("%05d", count),
61-
Value: "val",
62-
})
63-
count++
64-
}
65-
66-
patchBytes, err := json.Marshal(patch)
52+
patchBytes, err := getUniqueLabelsPatch(a.NumUniqueLabelsPerPod, &count)
6753
if err != nil {
6854
return fmt.Errorf("error marshalling patch: %w", err)
6955
}
7056

71-
clientset.CoreV1().Pods(a.Namespace).Patch(ctx, resource.Name,
72-
types.JSONPatchType,
73-
patchBytes,
74-
metav1.PatchOptions{},
75-
)
57+
err = patchLabel(ctx, clientset, a.Namespace, resource.Name, patchBytes)
58+
if err != nil {
59+
return fmt.Errorf("error adding label to pod: %w", err)
60+
}
7661
}
7762

7863
return nil
@@ -82,3 +67,18 @@ func (a *AddUniqueLabelsToAllPods) Run() error {
8267
func (a *AddUniqueLabelsToAllPods) Stop() error {
8368
return nil
8469
}
70+
71+
func getUniqueLabelsPatch(numLabels int, counter *int) ([]byte, error) {
72+
patch := []patchStringValue{}
73+
74+
for i := 0; i < numLabels; i++ {
75+
patch = append(patch, patchStringValue{
76+
Op: "add",
77+
Path: "/metadata/labels/uni-lab-" + fmt.Sprintf("%05d", *counter),
78+
Value: "val",
79+
})
80+
(*counter)++
81+
}
82+
83+
return json.Marshal(patch)
84+
}

test/e2e/framework/scaletest/create-resources.go

+26-11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import (
77
"time"
88

99
e2ekubernetes "github.com/microsoft/retina/test/e2e/framework/kubernetes"
10+
"github.com/microsoft/retina/test/retry"
1011
"k8s.io/apimachinery/pkg/runtime"
1112
"k8s.io/client-go/kubernetes"
1213
"k8s.io/client-go/tools/clientcmd"
1314
)
1415

16+
const (
17+
timeoutCreateResourcesSeconds = 1200
18+
)
19+
1520
type CreateResources struct {
1621
Namespace string
1722
KubeConfigFilePath string
@@ -48,11 +53,18 @@ func (c *CreateResources) Run() error {
4853
return fmt.Errorf("error creating Kubernetes client: %w", err)
4954
}
5055

51-
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
56+
ctx, cancel := context.WithTimeout(context.Background(), timeoutCreateResourcesSeconds*time.Second)
5257
defer cancel()
5358

59+
retrier := retry.Retrier{Attempts: defaultRetryAttempts, Delay: defaultRetryDelay}
60+
5461
for _, resource := range resources {
55-
e2ekubernetes.CreateResource(ctx, resource, clientset)
62+
err := retrier.Do(ctx, func() error {
63+
return e2ekubernetes.CreateResource(ctx, resource, clientset)
64+
})
65+
if err != nil {
66+
return fmt.Errorf("error creating resource: %w", err)
67+
}
5668
}
5769

5870
return nil
@@ -71,12 +83,6 @@ func (c *CreateResources) getResources() []runtime.Object {
7183
// kwokDeployments := c.generateDeployments(c.NumKwokDeployments, c.NumKwokReplicas, "kwok")
7284
// objs = append(objs, kwokDeployments...)
7385

74-
realDeployments := c.generateDeployments()
75-
objs = append(objs, realDeployments...)
76-
77-
services := c.generateServices("real")
78-
objs = append(objs, services...)
79-
8086
kapinger := e2ekubernetes.CreateKapingerDeployment{
8187
KapingerNamespace: c.Namespace,
8288
KubeConfigFilePath: c.KubeConfigFilePath,
@@ -88,6 +94,13 @@ func (c *CreateResources) getResources() []runtime.Object {
8894
kapingerSA := kapinger.GetKapingerServiceAccount()
8995

9096
objs = append(objs, kapingerClusterRole, kapingerClusterRoleBinding, kapingerSA)
97+
98+
realDeployments := c.generateDeployments()
99+
objs = append(objs, realDeployments...)
100+
101+
services := c.generateServices()
102+
objs = append(objs, services...)
103+
91104
// c.generateKwokNodes()
92105
log.Println("Finished generating YAMLs")
93106
return objs
@@ -118,6 +131,8 @@ func (c *CreateResources) generateDeployments() []runtime.Object {
118131
labelPrefix := fmt.Sprintf("%s-dep-lab", name)
119132

120133
deployment.Name = name
134+
deployment.Labels["name"] = name
135+
deployment.Spec.Template.Labels["name"] = name
121136

122137
r := int32(c.NumRealReplicas)
123138
deployment.Spec.Replicas = &r
@@ -135,7 +150,7 @@ func (c *CreateResources) generateDeployments() []runtime.Object {
135150
return objs
136151
}
137152

138-
func (c *CreateResources) generateServices(svcKind string) []runtime.Object {
153+
func (c *CreateResources) generateServices() []runtime.Object {
139154
objs := []runtime.Object{}
140155

141156
kapingerSvc := e2ekubernetes.CreateKapingerDeployment{
@@ -146,10 +161,10 @@ func (c *CreateResources) generateServices(svcKind string) []runtime.Object {
146161
for i := 0; i < c.NumRealServices; i++ {
147162
template := kapingerSvc.GetKapingerService()
148163

149-
name := fmt.Sprintf("%s-svc-%05d", svcKind, i)
164+
name := fmt.Sprintf("%s-svc-%05d", c.RealPodType, i)
150165
template.Name = name
151166

152-
template.Spec.Selector["name"] = fmt.Sprintf("%s-%s-dep-%05d", svcKind, c.RealPodType, i)
167+
template.Spec.Selector["name"] = fmt.Sprintf("%s-dep-%05d", c.RealPodType, i)
153168

154169
objs = append(objs, template)
155170
}

test/e2e/framework/scaletest/delete-and-re-add-labels.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (d *DeleteAndReAddLabels) Run() error {
4848
return fmt.Errorf("error creating Kubernetes client: %w", err)
4949
}
5050

51-
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
51+
ctx, cancel := contextToLabelAllPods()
5252
defer cancel()
5353

5454
labelsToDelete := `"shared-lab-00000": null, "shared-lab-00001": null, "shared-lab-00002": null`
@@ -91,6 +91,7 @@ func (d *DeleteAndReAddLabels) Run() error {
9191
func (d *DeleteAndReAddLabels) addLabels(ctx context.Context, clientset *kubernetes.Clientset, pods *corev1.PodList, patch string) error {
9292

9393
for _, pod := range pods.Items {
94+
log.Println("Labeling Pod", pod.Name)
9495
_, err := clientset.CoreV1().Pods(d.Namespace).Patch(ctx, pod.Name, types.StrategicMergePatchType, []byte(patch), metav1.PatchOptions{})
9596
if err != nil {
9697
return fmt.Errorf("error patching pod: %w", err)
@@ -103,6 +104,7 @@ func (d *DeleteAndReAddLabels) addLabels(ctx context.Context, clientset *kuberne
103104
func (d *DeleteAndReAddLabels) deleteLabels(ctx context.Context, clientset *kubernetes.Clientset, pods *corev1.PodList, patch string) error {
104105

105106
for _, pod := range pods.Items {
107+
log.Println("Deleting label from Pod", pod.Name)
106108
_, err := clientset.CoreV1().Pods(d.Namespace).Patch(ctx, pod.Name, types.StrategicMergePatchType, []byte(patch), metav1.PatchOptions{})
107109
if err != nil {
108110
return fmt.Errorf("error patching pod: %w", err)

0 commit comments

Comments
 (0)