Skip to content

Commit 8a62ddb

Browse files
committed
fix: adjust scale test execution code
Signed-off-by: Alex Castilio dos Santos <[email protected]>
1 parent 2becd2c commit 8a62ddb

File tree

10 files changed

+140
-58
lines changed

10 files changed

+140
-58
lines changed

.github/workflows/scale-test.yaml

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ on:
1111
description: "AKS Cluster Name"
1212
required: true
1313
type: string
14-
location:
15-
description: "Azure Location"
14+
image_tag:
15+
description: "Image Tag (if not set, default for this commit will be used)"
1616
type: string
17-
default: ${{ vars.AZURE_LOCATION }}
1817
num_deployments:
1918
description: "Number of Traffic Deployments"
2019
default: 1000
@@ -27,20 +26,8 @@ on:
2726
description: "Number of Network Policies"
2827
default: 1000
2928
type: number
30-
num_unique_labels_per_pod:
31-
description: "Number of Unique Labels per Pod"
32-
default: 2
33-
type: number
34-
num_unique_labels_per_deployment:
35-
description: "Number of Unique Labels per Deployment"
36-
default: 2
37-
type: number
38-
num_shared_labels_per_pod:
39-
description: "Number of Shared Labels per Pod"
40-
default: 3
41-
type: number
42-
delete_labels:
43-
description: "Delete Labels"
29+
cleanup:
30+
description: "Clean up environment after test"
4431
default: true
4532
type: boolean
4633

@@ -54,10 +41,6 @@ on:
5441
description: "AKS Cluster Name"
5542
required: true
5643
type: string
57-
location:
58-
description: "Azure Location"
59-
type: string
60-
default: ${{ vars.AZURE_LOCATION }}
6144
num_deployments:
6245
description: "Number of Traffic Deployments"
6346
default: 1000
@@ -70,20 +53,8 @@ on:
7053
description: "Number of Network Policies"
7154
default: 1000
7255
type: number
73-
num_unique_labels_per_pod:
74-
description: "Number of Unique Labels per Pod"
75-
default: 2
76-
type: number
77-
num_unique_labels_per_deployment:
78-
description: "Number of Unique Labels per Deployment"
79-
default: 2
80-
type: number
81-
num_shared_labels_per_pod:
82-
description: "Number of Shared Labels per Pod"
83-
default: 3
84-
type: number
85-
delete_labels:
86-
description: "Delete Labels"
56+
cleanup:
57+
description: "Clean up environment after test"
8758
default: true
8859
type: boolean
8960

@@ -116,17 +87,16 @@ jobs:
11687
- name: Run Scale Test
11788
env:
11889
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION }}
119-
AZURE_LOCATION: ${{ input.location }}
12090
AZURE_RESOURCE_GROUP: ${{ inputs.resource_group }}
12191
CLUSTER_NAME: ${{ inputs.cluster_name }}
12292
NUM_DEPLOYMENTS: ${{ inputs.num_deployments }}
12393
NUM_REPLICAS: ${{ inputs.num_replicas }}
12494
NUM_NETPOLS: ${{ inputs.num_netpol }}
125-
NUM_UNIQUE_LABELS_PER_POD: ${{ inputs.num_unique_labels_per_pod }}
126-
NUM_SHARED_LABELS_PER_POD: ${{ inputs.num_shared_labels_per_pod }}
127-
NUM_UNIQUE_LABELS_PER_DEPLOYMENT: ${{ inputs.num_unique_labels_per_deployment }}
128-
DELETE_LABELS: ${{ inputs.delete_labels }}
95+
CLEANUP: ${{ inputs.cleanup }}
96+
IMAGE_REGISTRY: ${{ vars.ACR_NAME }}
97+
IMAGE_NAMESPACE: ${{ github.repository }}
98+
TAG: ${{ inputs.image_tag }}
12999
shell: bash
130100
run: |
131101
set -euo pipefail
132-
go test -v ./test/e2e/. -timeout 300m -tags=scale -count=1 -args -image-tag=$(make version) -image-registry=${{vars.ACR_NAME}} -image-namespace=${{github.repository}}
102+
go test -v ./test/e2e/. -timeout 300m -tags=scale -count=1 -args -image-tag=$( [[ $TAG == "" ]] && make version || echo $TAG ) -create-infra=false -delete-infra=false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
const (
2121
createTimeout = 20 * time.Minute // windows is slow
22-
deleteTimeout = 60 * time.Second
22+
deleteTimeout = 5 * time.Minute
2323
)
2424

2525
var (
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package kubernetes
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
8+
"helm.sh/helm/v3/pkg/action"
9+
"helm.sh/helm/v3/pkg/cli"
10+
)
11+
12+
type UninstallHelmChart struct {
13+
Namespace string
14+
ReleaseName string
15+
KubeConfigFilePath string
16+
}
17+
18+
func (i *UninstallHelmChart) Run() error {
19+
settings := cli.New()
20+
settings.KubeConfig = i.KubeConfigFilePath
21+
actionConfig := new(action.Configuration)
22+
23+
err := actionConfig.Init(settings.RESTClientGetter(), i.Namespace, os.Getenv("HELM_DRIVER"), log.Printf)
24+
if err != nil {
25+
return fmt.Errorf("failed to initialize helm action config: %w", err)
26+
}
27+
28+
delclient := action.NewUninstall(actionConfig)
29+
delclient.Wait = true
30+
delclient.Timeout = deleteTimeout
31+
_, err = delclient.Run(i.ReleaseName)
32+
if err != nil {
33+
return fmt.Errorf("failed to delete existing release %s: %w", i.ReleaseName, err)
34+
}
35+
36+
return nil
37+
}
38+
39+
func (i *UninstallHelmChart) Prevalidate() error {
40+
return nil
41+
}
42+
43+
func (i *UninstallHelmChart) Stop() error {
44+
return nil
45+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ func (c *CreateResources) getResources() []runtime.Object {
8585

8686
kapingerClusterRoleBinding := kapinger.GetKapingerClusterRoleBinding()
8787

88-
objs = append(objs, kapingerClusterRole, kapingerClusterRoleBinding)
88+
kapingerSA := kapinger.GetKapingerServiceAccount()
89+
90+
objs = append(objs, kapingerClusterRole, kapingerClusterRoleBinding, kapingerSA)
8991
// c.generateKwokNodes()
9092
log.Println("Finished generating YAMLs")
9193
return objs
@@ -101,6 +103,9 @@ func (c *CreateResources) generateDeployments() []runtime.Object {
101103
}
102104
template := kapinger.GetKapingerDeployment()
103105

106+
if template.Labels == nil {
107+
template.Labels = make(map[string]string)
108+
}
104109
template.Labels["is-real"] = "true"
105110
template.Spec.Template.Labels["is-real"] = "true"
106111
template.Spec.Template.Spec.NodeSelector["scale-test"] = "true"

test/e2e/framework/scaletest/templates/networkpolicy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var (
1919
"Ingress",
2020
"Egress",
2121
},
22+
PodSelector: metav1.LabelSelector{
23+
MatchLabels: map[string]string{},
24+
},
2225
},
2326
}
2427
)

test/e2e/jobs/jobs.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ func InstallRetina(kubeConfigFilePath, chartPath string) *types.Job {
8989
return job
9090
}
9191

92+
func UninstallRetina(kubeConfigFilePath, chartPath string) *types.Job {
93+
job := types.NewJob("Uninstall Retina")
94+
95+
job.AddStep(&kubernetes.UninstallHelmChart{
96+
Namespace: common.KubeSystemNamespace,
97+
ReleaseName: "retina",
98+
KubeConfigFilePath: kubeConfigFilePath,
99+
}, nil)
100+
101+
return job
102+
}
103+
92104
func InstallAndTestRetinaBasicMetrics(kubeConfigFilePath, chartPath string, testPodNamespace string) *types.Job {
93105
job := types.NewJob("Install and test Retina with basic metrics")
94106

test/e2e/jobs/scale.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ func DefaultScaleTestOptions() scaletest.Options {
1515
NumKwokDeployments: 0,
1616
NumKwokReplicas: 0,
1717
MaxRealPodsPerNode: 100,
18-
NumRealDeployments: 3,
19-
RealPodType: "agnhost",
20-
NumRealReplicas: 2,
21-
NumRealServices: 1,
18+
NumRealDeployments: 1000,
19+
RealPodType: "kapinger",
20+
NumRealReplicas: 40,
21+
NumRealServices: 1000,
2222
NumNetworkPolicies: 10,
2323
NumUnapliedNetworkPolicies: 10,
24-
NumUniqueLabelsPerPod: 2,
25-
NumUniqueLabelsPerDeployment: 2,
24+
NumUniqueLabelsPerPod: 0,
25+
NumUniqueLabelsPerDeployment: 1,
2626
NumSharedLabelsPerPod: 3,
2727
KubeconfigPath: "",
2828
RestartNpmPods: false,
@@ -95,6 +95,8 @@ func ScaleTest(opt *scaletest.Options) *types.Job {
9595
NumSharedLabelsPerPod: opt.NumSharedLabelsPerPod,
9696
}, nil)
9797

98+
// job.AddStep(&kubernetes.DeleteNamespace{}, nil)
99+
98100
// TODO: Add steps to get the state of the cluster
99101

100102
// job.AddStep(&kubernetes.GetDeployment{})

test/e2e/retina_e2e_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
package retina
24

35
import (
@@ -18,12 +20,6 @@ import (
1820
"github.com/stretchr/testify/require"
1921
)
2022

21-
var (
22-
locations = []string{"eastus2", "centralus", "southcentralus", "uksouth", "centralindia", "westus2"}
23-
createInfra = flag.Bool("create-infra", true, "create a Resource group, vNET and AKS cluster for testing")
24-
deleteInfra = flag.Bool("delete-infra", true, "delete a Resource group, vNET and AKS cluster for testing")
25-
)
26-
2723
// TestE2ERetina tests all e2e scenarios for retina
2824
func TestE2ERetina(t *testing.T) {
2925
ctx, cancel := helpers.Context(t)

test/e2e/scale_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package retina
44

55
import (
66
"crypto/rand"
7+
"flag"
78
"math/big"
89
"os"
910
"os/user"
@@ -26,7 +27,19 @@ func TestE2ERetina_Scale(t *testing.T) {
2627
curuser, err := user.Current()
2728
require.NoError(t, err)
2829

29-
clusterName := curuser.Username + common.NetObsRGtag + strconv.FormatInt(time.Now().Unix(), 10)
30+
flag.Parse()
31+
32+
clusterName := os.Getenv("CLUSTER_NAME")
33+
if clusterName == "" {
34+
username := curuser.Username
35+
// Truncate the username to 8 characters
36+
if len(username) > 8 {
37+
username = username[:8]
38+
t.Logf("Username is too long, truncating to 8 characters: %s", username)
39+
}
40+
clusterName = username + common.NetObsRGtag + strconv.FormatInt(time.Now().Unix(), 10)
41+
t.Logf("CLUSTER_NAME is not set, generating a random cluster name: %s", clusterName)
42+
}
3043

3144
subID := os.Getenv("AZURE_SUBSCRIPTION_ID")
3245
require.NotEmpty(t, subID)
@@ -70,11 +83,36 @@ func TestE2ERetina_Scale(t *testing.T) {
7083
installRetina := types.NewRunner(t, jobs.InstallRetina(kubeConfigFilePath, chartPath))
7184
installRetina.Run(ctx)
7285

86+
t.Cleanup(func() {
87+
_ = jobs.UninstallRetina(kubeConfigFilePath, chartPath).Run()
88+
})
89+
7390
// Scale test
7491
opt := jobs.DefaultScaleTestOptions()
7592
opt.KubeconfigPath = kubeConfigFilePath
76-
opt.RealPodType = "kapinger"
77-
opt.DeleteLabels = true
93+
94+
NumDeployments := os.Getenv("NUM_DEPLOYMENTS")
95+
NumReplicas := os.Getenv("NUM_REPLICAS")
96+
NumNetworkPolicies := os.Getenv("NUM_NET_POL")
97+
CleanUp := os.Getenv("CLEANUP")
98+
99+
if NumDeployments != "" {
100+
opt.NumRealDeployments, err = strconv.Atoi(NumDeployments)
101+
opt.NumRealServices = opt.NumRealDeployments
102+
require.NoError(t, err)
103+
}
104+
if NumReplicas != "" {
105+
opt.NumRealReplicas, err = strconv.Atoi(NumReplicas)
106+
require.NoError(t, err)
107+
}
108+
if NumNetworkPolicies != "" {
109+
opt.NumNetworkPolicies, err = strconv.Atoi(NumNetworkPolicies)
110+
require.NoError(t, err)
111+
}
112+
if CleanUp != "" {
113+
opt.DeleteLabels, err = strconv.ParseBool(CleanUp)
114+
require.NoError(t, err)
115+
}
78116

79117
scale := types.NewRunner(t, jobs.ScaleTest(&opt))
80118
scale.Run(ctx)

test/e2e/shared_vars.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build scale || e2e
2+
3+
package retina
4+
5+
import "flag"
6+
7+
var (
8+
locations = []string{"eastus2", "centralus", "southcentralus", "uksouth", "centralindia", "westus2"}
9+
createInfra = flag.Bool("create-infra", true, "create a Resource group, vNET and AKS cluster for testing")
10+
deleteInfra = flag.Bool("delete-infra", true, "delete a Resource group, vNET and AKS cluster for testing")
11+
)

0 commit comments

Comments
 (0)