Skip to content

Commit

Permalink
fix(test): configuration changes and fixes needed to scale-test
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Castilio dos Santos <[email protected]>
  • Loading branch information
alexcastilio committed Nov 29, 2024
1 parent 1e2081a commit 419dc4d
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 112 deletions.
1 change: 1 addition & 0 deletions test/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
KubeSystemNamespace = "kube-system"
TestPodNamespace = "kube-system-test"
AzureAppInsightsKeyEnv = "AZURE_APP_INSIGHTS_KEY"
OutputFilePathEnv = "OUTPUT_FILEPATH"
)

var (
Expand Down
21 changes: 6 additions & 15 deletions test/e2e/framework/kubernetes/check-pod-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

const (
RetryTimeoutPodsReady = 5 * time.Minute
RetryIntervalPodsReady = 5 * time.Second
RetryTimeoutPodsReady = 5 * time.Minute
RetryIntervalPodsReady = 5 * time.Second
timeoutWaitForPodsSeconds = 1200

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

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), timeoutWaitForPodsSeconds*time.Second)
defer cancel()

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

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

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

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

Check failure on line 82 in test/e2e/framework/kubernetes/check-pod-status.go

View workflow job for this annotation

GitHub Actions / Lint (windows, amd64)

rangeValCopy: each iteration copies 1112 bytes (consider pointers or indexing) (gocritic)

Check failure on line 82 in test/e2e/framework/kubernetes/check-pod-status.go

View workflow job for this annotation

GitHub Actions / Lint (windows, arm64)

rangeValCopy: each iteration copies 1112 bytes (consider pointers or indexing) (gocritic)

Check failure on line 82 in test/e2e/framework/kubernetes/check-pod-status.go

View workflow job for this annotation

GitHub Actions / Lint (linux, arm64)

rangeValCopy: each iteration copies 1112 bytes (consider pointers or indexing) (gocritic)

Check failure on line 82 in test/e2e/framework/kubernetes/check-pod-status.go

View workflow job for this annotation

GitHub Actions / Lint (linux, amd64)

rangeValCopy: each iteration copies 1112 bytes (consider pointers or indexing) (gocritic)

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

if !podReadyMap[pod.Name] {
log.Printf("pod \"%s\" is in Running state\n", pod.Name)
podReadyMap[pod.Name] = true
}
}
log.Printf("all pods in namespace \"%s\" with label \"%s\" are in Running state\n", namespace, labelSelector)
return true, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *CreateKapingerDeployment) GetKapingerDeployment() *appsv1.Deployment {
"memory": resource.MustParse("20Mi"),
},
Limits: v1.ResourceList{
"memory": resource.MustParse("20Mi"),
"memory": resource.MustParse("40Mi"),
},
},
Ports: []v1.ContainerPort{
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/framework/kubernetes/delete-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"k8s.io/client-go/util/retry"
)

const (
deleteNamespaceTimeoutSeconds = 1200
)

type DeleteNamespace struct {
Namespace string
KubeConfigFilePath string
Expand All @@ -30,7 +34,7 @@ func (d *DeleteNamespace) Run() error {
return fmt.Errorf("error creating Kubernetes client: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), deleteNamespaceTimeoutSeconds*time.Second)
defer cancel()

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

backoff := wait.Backoff{
Steps: 6,
Steps: 9,

Check failure on line 48 in test/e2e/framework/kubernetes/delete-namespace.go

View workflow job for this annotation

GitHub Actions / Lint (windows, amd64)

Magic number: 9, in <assign> detected (mnd)

Check failure on line 48 in test/e2e/framework/kubernetes/delete-namespace.go

View workflow job for this annotation

GitHub Actions / Lint (windows, arm64)

Magic number: 9, in <assign> detected (mnd)

Check failure on line 48 in test/e2e/framework/kubernetes/delete-namespace.go

View workflow job for this annotation

GitHub Actions / Lint (linux, arm64)

Magic number: 9, in <assign> detected (mnd)

Check failure on line 48 in test/e2e/framework/kubernetes/delete-namespace.go

View workflow job for this annotation

GitHub Actions / Lint (linux, amd64)

Magic number: 9, in <assign> detected (mnd)
Duration: 10 * time.Second,
Factor: 2.0,
// Jitter: 0.1,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/framework/kubernetes/install-retina-helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (i *InstallHelmChart) Run() error {
chart.Values["image"].(map[string]interface{})["repository"] = imageRegistry + "/" + imageNamespace + "/retina-agent"
chart.Values["image"].(map[string]interface{})["initRepository"] = imageRegistry + "/" + imageNamespace + "/retina-init"
chart.Values["operator"].(map[string]interface{})["repository"] = imageRegistry + "/" + imageNamespace + "/retina-operator"
chart.Values["operator"].(map[string]interface{})["enabled"] = true

getclient := action.NewGet(actionConfig)
release, err := getclient.Run(i.ReleaseName)
Expand Down
54 changes: 37 additions & 17 deletions test/e2e/framework/scaletest/add-shared-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"time"

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

const (
timeoutToLabelAllPodsMinutes = 120
)

type patchStringValue struct {
Op string `json:"op"`
Path string `json:"path"`
Expand Down Expand Up @@ -50,32 +55,21 @@ func (a *AddSharedLabelsToAllPods) Run() error {
return fmt.Errorf("error creating Kubernetes client: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
ctx, cancel := contextToLabelAllPods()
defer cancel()

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

patch := []patchStringValue{}

for i := 0; i < a.NumSharedLabelsPerPod; i++ {
patch = append(patch, patchStringValue{
Op: "add",
Path: "/metadata/labels/shared-lab-" + fmt.Sprintf("%05d", i),
Value: "val",
})
}

patchBytes, err := json.Marshal(patch)
patchBytes, err := getSharedLabelsPatch(a.NumSharedLabelsPerPod)
if err != nil {
return fmt.Errorf("error marshalling patch: %w", err)
}

for _, resource := range resources.Items {
clientset.CoreV1().Pods(a.Namespace).Patch(ctx, resource.Name,
types.JSONPatchType,
patchBytes,
metav1.PatchOptions{},
)
err = patchLabel(ctx, clientset, a.Namespace, resource.Name, patchBytes)
if err != nil {
log.Printf("Error adding shared labels to pod %s: %s\n", resource.Name, err)
}
}

return nil
Expand All @@ -85,3 +79,29 @@ func (a *AddSharedLabelsToAllPods) Run() error {
func (a *AddSharedLabelsToAllPods) Stop() error {
return nil
}

func patchLabel(ctx context.Context, clientset *kubernetes.Clientset, namespace, podName string, patchBytes []byte) error {
log.Println("Labeling Pod", podName)
_, err := clientset.CoreV1().Pods(namespace).Patch(ctx, podName,
types.JSONPatchType,
patchBytes,
metav1.PatchOptions{},
)
return err

Check failure on line 90 in test/e2e/framework/scaletest/add-shared-labels.go

View workflow job for this annotation

GitHub Actions / Lint (windows, amd64)

error returned from interface method should be wrapped: sig: func (k8s.io/client-go/kubernetes/typed/core/v1.PodInterface).Patch(ctx context.Context, name string, pt k8s.io/apimachinery/pkg/types.PatchType, data []byte, opts k8s.io/apimachinery/pkg/apis/meta/v1.PatchOptions, subresources ...string) (result *k8s.io/api/core/v1.Pod, err error) (wrapcheck)

Check failure on line 90 in test/e2e/framework/scaletest/add-shared-labels.go

View workflow job for this annotation

GitHub Actions / Lint (windows, arm64)

error returned from interface method should be wrapped: sig: func (k8s.io/client-go/kubernetes/typed/core/v1.PodInterface).Patch(ctx context.Context, name string, pt k8s.io/apimachinery/pkg/types.PatchType, data []byte, opts k8s.io/apimachinery/pkg/apis/meta/v1.PatchOptions, subresources ...string) (result *k8s.io/api/core/v1.Pod, err error) (wrapcheck)

Check failure on line 90 in test/e2e/framework/scaletest/add-shared-labels.go

View workflow job for this annotation

GitHub Actions / Lint (linux, arm64)

error returned from interface method should be wrapped: sig: func (k8s.io/client-go/kubernetes/typed/core/v1.PodInterface).Patch(ctx context.Context, name string, pt k8s.io/apimachinery/pkg/types.PatchType, data []byte, opts k8s.io/apimachinery/pkg/apis/meta/v1.PatchOptions, subresources ...string) (result *k8s.io/api/core/v1.Pod, err error) (wrapcheck)

Check failure on line 90 in test/e2e/framework/scaletest/add-shared-labels.go

View workflow job for this annotation

GitHub Actions / Lint (linux, amd64)

error returned from interface method should be wrapped: sig: func (k8s.io/client-go/kubernetes/typed/core/v1.PodInterface).Patch(ctx context.Context, name string, pt k8s.io/apimachinery/pkg/types.PatchType, data []byte, opts k8s.io/apimachinery/pkg/apis/meta/v1.PatchOptions, subresources ...string) (result *k8s.io/api/core/v1.Pod, err error) (wrapcheck)
}

func getSharedLabelsPatch(numLabels int) ([]byte, error) {
patch := []patchStringValue{}
for i := 0; i < numLabels; i++ {
patch = append(patch, patchStringValue{
Op: "add",
Path: "/metadata/labels/shared-lab-" + fmt.Sprintf("%05d", i),
Value: "val",
})
}
return json.Marshal(patch)
}

func contextToLabelAllPods() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), timeoutToLabelAllPodsMinutes*time.Minute)
}
42 changes: 21 additions & 21 deletions test/e2e/framework/scaletest/add-unique-labels.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package scaletest

import (
"context"
"encoding/json"
"fmt"
"time"

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

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
ctx, cancel := contextToLabelAllPods()
defer cancel()

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

count := 0

for _, resource := range resources.Items {
patch := []patchStringValue{}

for i := 0; i < a.NumUniqueLabelsPerPod; i++ {
patch = append(patch, patchStringValue{
Op: "add",
Path: "/metadata/labels/uni-lab-" + fmt.Sprintf("%05d", count),
Value: "val",
})
count++
}

patchBytes, err := json.Marshal(patch)
patchBytes, err := getUniqueLabelsPatch(a.NumUniqueLabelsPerPod, &count)
if err != nil {
return fmt.Errorf("error marshalling patch: %w", err)
}

clientset.CoreV1().Pods(a.Namespace).Patch(ctx, resource.Name,
types.JSONPatchType,
patchBytes,
metav1.PatchOptions{},
)
err = patchLabel(ctx, clientset, a.Namespace, resource.Name, patchBytes)
if err != nil {
return fmt.Errorf("error adding label to pod: %w", err)
}
}

return nil
Expand All @@ -82,3 +67,18 @@ func (a *AddUniqueLabelsToAllPods) Run() error {
func (a *AddUniqueLabelsToAllPods) Stop() error {
return nil
}

func getUniqueLabelsPatch(numLabels int, counter *int) ([]byte, error) {
patch := []patchStringValue{}

for i := 0; i < numLabels; i++ {
patch = append(patch, patchStringValue{
Op: "add",
Path: "/metadata/labels/uni-lab-" + fmt.Sprintf("%05d", *counter),
Value: "val",
})
(*counter)++
}

return json.Marshal(patch)
}
37 changes: 26 additions & 11 deletions test/e2e/framework/scaletest/create-resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
"time"

e2ekubernetes "github.com/microsoft/retina/test/e2e/framework/kubernetes"
"github.com/microsoft/retina/test/retry"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

const (
timeoutCreateResourcesSeconds = 1200
)

type CreateResources struct {
Namespace string
KubeConfigFilePath string
Expand Down Expand Up @@ -48,11 +53,18 @@ func (c *CreateResources) Run() error {
return fmt.Errorf("error creating Kubernetes client: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), timeoutCreateResourcesSeconds*time.Second)
defer cancel()

retrier := retry.Retrier{Attempts: defaultRetryAttempts, Delay: defaultRetryDelay}

for _, resource := range resources {
e2ekubernetes.CreateResource(ctx, resource, clientset)
err := retrier.Do(ctx, func() error {
return e2ekubernetes.CreateResource(ctx, resource, clientset)
})
if err != nil {
return fmt.Errorf("error creating resource: %w", err)
}
}

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

realDeployments := c.generateDeployments()
objs = append(objs, realDeployments...)

services := c.generateServices("real")
objs = append(objs, services...)

kapinger := e2ekubernetes.CreateKapingerDeployment{
KapingerNamespace: c.Namespace,
KubeConfigFilePath: c.KubeConfigFilePath,
Expand All @@ -88,6 +94,13 @@ func (c *CreateResources) getResources() []runtime.Object {
kapingerSA := kapinger.GetKapingerServiceAccount()

objs = append(objs, kapingerClusterRole, kapingerClusterRoleBinding, kapingerSA)

realDeployments := c.generateDeployments()
objs = append(objs, realDeployments...)

services := c.generateServices()
objs = append(objs, services...)

// c.generateKwokNodes()
log.Println("Finished generating YAMLs")
return objs
Expand Down Expand Up @@ -118,6 +131,8 @@ func (c *CreateResources) generateDeployments() []runtime.Object {
labelPrefix := fmt.Sprintf("%s-dep-lab", name)

deployment.Name = name
deployment.Labels["name"] = name
deployment.Spec.Template.Labels["name"] = name

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

func (c *CreateResources) generateServices(svcKind string) []runtime.Object {
func (c *CreateResources) generateServices() []runtime.Object {
objs := []runtime.Object{}

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

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

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

objs = append(objs, template)
}
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/framework/scaletest/delete-and-re-add-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (d *DeleteAndReAddLabels) Run() error {
return fmt.Errorf("error creating Kubernetes client: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second)
ctx, cancel := contextToLabelAllPods()
defer cancel()

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

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

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

0 comments on commit 419dc4d

Please sign in to comment.