WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9aea775

Browse files
committed
test: automate scale test execution
Signed-off-by: Alex Castilio dos Santos <[email protected]>
1 parent b3cd0ec commit 9aea775

File tree

8 files changed

+208
-44
lines changed

8 files changed

+208
-44
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Daily Scale Test
2+
3+
on:
4+
push:
5+
branches:
6+
- alexcastilio/scale-test-workflow
7+
# schedule:
8+
# - cron: "0 0 * * *"
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
jobs:
15+
call-scale-test:
16+
uses: ./.github/workflows/scale-test.yaml
17+
with:
18+
num_deployments: 10
19+
num_replicas: 10
20+
# TODO: Fix value
21+
num_netpol: 0
22+
cleanup: false
23+
secrets: inherit

.github/workflows/scale-test.yaml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,17 @@ on:
3636

3737
workflow_call:
3838
inputs:
39-
resource_group:
40-
description: "Azure Resource Group"
41-
required: true
42-
type: string
43-
cluster_name:
44-
description: "AKS Cluster Name"
45-
required: true
46-
type: string
4739
num_deployments:
4840
description: "Number of Traffic Deployments"
49-
default: 1000
41+
default: 100
5042
type: number
5143
num_replicas:
5244
description: "Number of Traffic Replicas per Deployment"
53-
default: 40
45+
default: 10
5446
type: number
5547
num_netpol:
5648
description: "Number of Network Policies"
57-
default: 1000
49+
default: 100
5850
type: number
5951
cleanup:
6052
description: "Clean up environment after test"
@@ -100,8 +92,13 @@ jobs:
10092
IMAGE_NAMESPACE: ${{ github.repository }}
10193
TAG: ${{ inputs.image_tag }}
10294
AZURE_APP_INSIGHTS_KEY: ${{ secrets.AZURE_APP_INSIGHTS_KEY }}
95+
# TODO: FIX VALUE
96+
NODES_PER_POOL: ""
97+
# TODO: DELETE
98+
WORKFLOW_NAME: ${{ github.event_name }}
99+
WORKFLOW_CALL: ${{ github.event.workflow == '.github/workflows/daily-scale-test.yaml' }}
103100
shell: bash
104101
run: |
105102
set -euo pipefail
106103
[[ $TAG == "" ]] && TAG=$(make version)
107-
go test -v ./test/e2e/. -timeout 300m -tags=scale -count=1 -args -create-infra=false -delete-infra=false
104+
go test -v ./test/e2e/. -timeout 300m -tags=scale -count=1 -args -create-infra=$(echo $WORKFLOW_CALL) -delete-infra=false

test/e2e/common/common.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ package common
66

77
import (
88
"flag"
9-
"os"
109
"os/user"
1110
"strconv"
1211
"testing"
1312
"time"
1413

14+
"github.com/microsoft/retina/test/e2e/framework/params"
1515
"github.com/stretchr/testify/require"
1616
)
1717

@@ -30,10 +30,61 @@ var (
3030
Architectures = []string{"amd64", "arm64"}
3131
CreateInfra = flag.Bool("create-infra", true, "create a Resource group, vNET and AKS cluster for testing")
3232
DeleteInfra = flag.Bool("delete-infra", true, "delete a Resource group, vNET and AKS cluster for testing")
33+
ScaleTestInfra = ScaleTestInfraHandler{
34+
location: params.Location,
35+
subscriptionID: params.SubscriptionID,
36+
resourceGroup: params.ResourceGroup,
37+
clusterName: params.ClusterName,
38+
nodesPerPool: params.NodesPerPool,
39+
}
3340
)
3441

42+
type ScaleTestInfraHandler struct {
43+
location string
44+
subscriptionID string
45+
resourceGroup string
46+
clusterName string
47+
nodesPerPool string
48+
}
49+
50+
func (s ScaleTestInfraHandler) GetSubscriptionID(t *testing.T) string {
51+
require.NotEmpty(t, s.subscriptionID)
52+
return s.subscriptionID
53+
}
54+
55+
func (s ScaleTestInfraHandler) GetLocation(t *testing.T) string {
56+
if s.location == "" {
57+
return "westus2"
58+
}
59+
return s.location
60+
}
61+
62+
func (s ScaleTestInfraHandler) GetResourceGroup(t *testing.T) string {
63+
if s.resourceGroup != "" {
64+
return s.resourceGroup
65+
}
66+
// Use the cluster name as the resource group name by default.
67+
return s.GetClusterName(t)
68+
}
69+
70+
func (s ScaleTestInfraHandler) GetNodesPerPool(t *testing.T) int32 {
71+
if s.nodesPerPool == "" {
72+
return 5
73+
}
74+
nodesPerPool, err := strconv.Atoi(s.nodesPerPool)
75+
require.NoError(t, err, "NODES_PER_POOL must be an integer")
76+
return int32(nodesPerPool)
77+
}
78+
79+
func (s ScaleTestInfraHandler) GetClusterName(t *testing.T) string {
80+
if s.clusterName != "" {
81+
return s.clusterName
82+
}
83+
return "retina-scale-test"
84+
}
85+
3586
func ClusterNameForE2ETest(t *testing.T) string {
36-
clusterName := os.Getenv("CLUSTER_NAME")
87+
clusterName := params.ClusterName
3788
if clusterName == "" {
3889
curuser, err := user.Current()
3990
require.NoError(t, err)

test/e2e/framework/azure/create-cluster-with-npm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const (
2222
clusterCreateTicker = 30 * time.Second
2323
pollFrequency = 5 * time.Second
2424
AgentARMSKU = "Standard_D4pls_v5"
25-
AuxilaryNodeCount = 1
2625
)
2726

2827
type CreateNPMCluster struct {
@@ -35,6 +34,7 @@ type CreateNPMCluster struct {
3534
PodCidr string
3635
DNSServiceIP string
3736
ServiceCidr string
37+
NodesPerPool int32
3838
}
3939

4040
func (c *CreateNPMCluster) Prevalidate() error {
@@ -55,7 +55,7 @@ func (c *CreateNPMCluster) Run() error {
5555
npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ //nolint:all
5656
Type: to.Ptr(armcontainerservice.AgentPoolTypeVirtualMachineScaleSets),
5757
// AvailabilityZones: []*string{to.Ptr("1")},
58-
Count: to.Ptr[int32](AuxilaryNodeCount),
58+
Count: to.Ptr[int32](c.NodesPerPool),
5959
EnableNodePublicIP: to.Ptr(false),
6060
Mode: to.Ptr(armcontainerservice.AgentPoolModeUser),
6161
OSType: to.Ptr(armcontainerservice.OSTypeWindows),
@@ -86,7 +86,7 @@ func (c *CreateNPMCluster) Run() error {
8686
npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ //nolint:all
8787
Type: to.Ptr(armcontainerservice.AgentPoolTypeVirtualMachineScaleSets),
8888
// AvailabilityZones: []*string{to.Ptr("1")},
89-
Count: to.Ptr[int32](AuxilaryNodeCount),
89+
Count: to.Ptr[int32](c.NodesPerPool),
9090
EnableNodePublicIP: to.Ptr(false),
9191
Mode: to.Ptr(armcontainerservice.AgentPoolModeUser),
9292
OSType: to.Ptr(armcontainerservice.OSTypeLinux),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package params
2+
3+
import (
4+
"os"
5+
)
6+
7+
var (
8+
Location = os.Getenv("LOCATION")
9+
SubscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID")
10+
ResourceGroup = os.Getenv("AZURE_RESOURCE_GROUP")
11+
ClusterName = os.Getenv("CLUSTER_NAME")
12+
NodesPerPool = os.Getenv("NODES_PER_POOL")
13+
NumDeployments = os.Getenv("NUM_DEPLOYMENTS")
14+
NumReplicas = os.Getenv("NUM_REPLICAS")
15+
NumNetworkPolicies = os.Getenv("NUM_NET_POL")
16+
CleanUp = os.Getenv("CLEANUP")
17+
)

test/e2e/jobs/jobs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func CreateTestInfra(subID, rg, clusterName, location, kubeConfigFilePath string
4343
PodCidr: "10.128.0.0/9",
4444
DNSServiceIP: "192.168.0.10",
4545
ServiceCidr: "192.168.0.0/28",
46+
NodesPerPool: 1,
4647
}, nil)
4748

4849
job.AddStep(&azure.GetAKSKubeConfig{

test/e2e/jobs/scale.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,49 @@ import (
55
"time"
66

77
"github.com/microsoft/retina/test/e2e/common"
8+
"github.com/microsoft/retina/test/e2e/framework/azure"
9+
"github.com/microsoft/retina/test/e2e/framework/generic"
810
"github.com/microsoft/retina/test/e2e/framework/kubernetes"
911
"github.com/microsoft/retina/test/e2e/framework/scaletest"
1012
"github.com/microsoft/retina/test/e2e/framework/types"
1113
)
1214

1315
func DefaultScaleTestOptions() scaletest.Options {
16+
// var NumRealDeployments int
17+
// var NumReplicas int
18+
// var err error
19+
//
20+
// if env.NumDeployments != "" {
21+
// NumRealDeployments, err = strconv.Atoi(env.NumDeployments)
22+
// require.NoError(t, err, "Failed to convert NUM_DEPLOYMENTS to int")
23+
// } else {
24+
// NumRealDeployments = 1000
25+
// }
26+
//
27+
// if env.NumReplicas != "" {
28+
// NumReplicas, err = strconv.Atoi(env.NumReplicas)
29+
// require.NoError(t, err, "Failed to convert NUM_REPLICAS to int")
30+
// } else {
31+
// NumReplicas = "40"
32+
// NumNetworkPolicies := env.NumNetworkPolicies
33+
// CleanUp := env.CleanUp
34+
//
35+
// if NumDeployments != "" {
36+
// } else {
37+
// NumRealDeployments = 1000
38+
// }
39+
// if NumReplicas != "" {
40+
// opt.NumRealReplicas, err = strconv.Atoi(NumReplicas)
41+
// require.NoError(t, err)
42+
// }
43+
// if NumNetworkPolicies != "" {
44+
// opt.NumNetworkPolicies, err = strconv.Atoi(NumNetworkPolicies)
45+
// require.NoError(t, err)
46+
// }
47+
// if CleanUp != "" {
48+
// opt.DeleteLabels, err = strconv.ParseBool(CleanUp)
49+
// require.NoError(t, err)
50+
// }
1451
return scaletest.Options{
1552
Namespace: "scale-test",
1653
MaxKwokPodsPerNode: 0,
@@ -45,6 +82,57 @@ func DefaultScaleTestOptions() scaletest.Options {
4582
}
4683
}
4784

85+
func GetScaleTestInfra(subID, rg, clusterName, location, kubeConfigFilePath string, nodesPerPool int32, createInfra bool) *types.Job {
86+
job := types.NewJob("Get scale test infrastructure")
87+
88+
if createInfra {
89+
job.AddStep(&azure.CreateResourceGroup{
90+
SubscriptionID: subID,
91+
ResourceGroupName: rg,
92+
Location: location,
93+
}, nil)
94+
95+
job.AddStep(&azure.CreateVNet{
96+
VnetName: "testvnet",
97+
VnetAddressSpace: "10.0.0.0/9",
98+
}, nil)
99+
100+
job.AddStep(&azure.CreateSubnet{
101+
SubnetName: "testsubnet",
102+
SubnetAddressSpace: "10.0.0.0/12",
103+
}, nil)
104+
105+
job.AddStep(&azure.CreateNPMCluster{
106+
ClusterName: clusterName,
107+
PodCidr: "10.128.0.0/9",
108+
DNSServiceIP: "192.168.0.10",
109+
ServiceCidr: "192.168.0.0/28",
110+
NodesPerPool: nodesPerPool,
111+
}, nil)
112+
113+
job.AddStep(&azure.GetAKSKubeConfig{
114+
KubeConfigFilePath: kubeConfigFilePath,
115+
}, nil)
116+
117+
} else {
118+
job.AddStep(&azure.GetAKSKubeConfig{
119+
KubeConfigFilePath: kubeConfigFilePath,
120+
ClusterName: clusterName,
121+
SubscriptionID: subID,
122+
ResourceGroupName: rg,
123+
Location: location,
124+
}, nil)
125+
}
126+
127+
job.AddStep(&generic.LoadFlags{
128+
TagEnv: generic.DefaultTagEnv,
129+
ImageNamespaceEnv: generic.DefaultImageNamespace,
130+
ImageRegistryEnv: generic.DefaultImageRegistry,
131+
}, nil)
132+
133+
return job
134+
}
135+
48136
func ScaleTest(opt *scaletest.Options) *types.Job {
49137
job := types.NewJob("Scale Test")
50138

test/e2e/scale_test.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package retina
44

55
import (
6-
"crypto/rand"
7-
"math/big"
86
"os"
97
"path/filepath"
108
"strconv"
@@ -14,6 +12,7 @@ import (
1412
"github.com/microsoft/retina/test/e2e/framework/azure"
1513
"github.com/microsoft/retina/test/e2e/framework/generic"
1614
"github.com/microsoft/retina/test/e2e/framework/helpers"
15+
"github.com/microsoft/retina/test/e2e/framework/params"
1716
"github.com/microsoft/retina/test/e2e/framework/types"
1817
jobs "github.com/microsoft/retina/test/e2e/jobs"
1918
"github.com/stretchr/testify/require"
@@ -23,25 +22,11 @@ func TestE2ERetina_Scale(t *testing.T) {
2322
ctx, cancel := helpers.Context(t)
2423
defer cancel()
2524

26-
clusterName := common.ClusterNameForE2ETest(t)
27-
28-
subID := os.Getenv("AZURE_SUBSCRIPTION_ID")
29-
require.NotEmpty(t, subID)
30-
31-
location := os.Getenv("AZURE_LOCATION")
32-
if location == "" {
33-
nBig, err := rand.Int(rand.Reader, big.NewInt(int64(len(common.AzureLocations))))
34-
if err != nil {
35-
t.Fatal("Failed to generate a secure random index", err)
36-
}
37-
location = common.AzureLocations[nBig.Int64()]
38-
}
39-
40-
rg := os.Getenv("AZURE_RESOURCE_GROUP")
41-
if rg == "" {
42-
// Use the cluster name as the resource group name by default.
43-
rg = clusterName
44-
}
25+
clusterName := common.ScaleTestInfra.GetClusterName(t)
26+
subID := common.ScaleTestInfra.GetSubscriptionID(t)
27+
location := common.ScaleTestInfra.GetLocation(t)
28+
rg := common.ScaleTestInfra.GetResourceGroup(t)
29+
nodesPerPool := common.ScaleTestInfra.GetNodesPerPool(t)
4530

4631
cwd, err := os.Getwd()
4732
require.NoError(t, err)
@@ -56,10 +41,10 @@ func TestE2ERetina_Scale(t *testing.T) {
5641
opt := jobs.DefaultScaleTestOptions()
5742
opt.KubeconfigPath = kubeConfigFilePath
5843

59-
NumDeployments := os.Getenv("NUM_DEPLOYMENTS")
60-
NumReplicas := os.Getenv("NUM_REPLICAS")
61-
NumNetworkPolicies := os.Getenv("NUM_NETPOLS")
62-
CleanUp := os.Getenv("CLEANUP")
44+
NumDeployments := params.NumDeployments
45+
NumReplicas := params.NumReplicas
46+
NumNetworkPolicies := params.NumNetworkPolicies
47+
CleanUp := params.CleanUp
6348

6449
if NumDeployments != "" {
6550
opt.NumRealDeployments, err = strconv.Atoi(NumDeployments)
@@ -89,9 +74,11 @@ func TestE2ERetina_Scale(t *testing.T) {
8974

9075
opt.LabelsToGetMetrics = map[string]string{"k8s-app": "retina"}
9176

77+
createInfra := *common.CreateInfra
78+
9279
// CreateTestInfra
93-
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, rg, clusterName, location, kubeConfigFilePath, *common.CreateInfra))
94-
createTestInfra.Run(ctx)
80+
infra := types.NewRunner(t, jobs.GetScaleTestInfra(subID, rg, clusterName, location, kubeConfigFilePath, nodesPerPool, createInfra))
81+
infra.Run(ctx)
9582

9683
t.Cleanup(func() {
9784
if *common.DeleteInfra {

0 commit comments

Comments
 (0)