Skip to content

Commit 540dd16

Browse files
lwr20tomastigera
andauthored
Picks of bugfixes into 0.5.0 (#30)
* label each pod with at least as many labels as policies (#26) * label each pod with at least as many labels as policies * allow for no test to run, just setup env * generate total mesh of policies that are not groupped * Use Command and Args properly (#29) --------- Co-authored-by: Tomas Hruby <49207409+tomastigera@users.noreply.github.com>
1 parent 74b48ee commit 540dd16

File tree

10 files changed

+98
-71
lines changed

10 files changed

+98
-71
lines changed

cmd/benchmark.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func main() {
8383
thisResult := results.Result{}
8484
thisResult.Config = *testConfig
8585
switch testConfig.TestKind {
86+
case config.TestKindNone:
87+
// No test to run
8688
case config.TestKindIperf:
8789
var iperfResults []*iperf.Results
8890
err = policy.CreateTestPolicy(ctx, clients, testPolicyName, testConfig.TestNamespace, []int{testConfig.Perf.TestPort})

pkg/cluster/cluster.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,14 @@ func SetupStandingConfig(ctx context.Context, clients config.Clients, testConfig
427427
if err != nil {
428428
return err
429429
}
430+
431+
labels := []string{}
432+
for i := 0; i < testConfig.NumPolicies; i++ {
433+
labels = append(labels, fmt.Sprintf("policy-%d", i))
434+
}
435+
430436
// Deploy pods
431-
deployment := makeDeployment(namespace, "standing-deployment", int32(testConfig.NumPods), false, webServerImage, []string{})
437+
deployment := makeDeployment(namespace, "standing-deployment", int32(testConfig.NumPods), false, webServerImage, labels)
432438
deployment, err = utils.GetOrCreateDeployment(ctx, clients, deployment)
433439
if err != nil {
434440
return err
@@ -447,7 +453,7 @@ func SetupStandingConfig(ctx context.Context, clients config.Clients, testConfig
447453

448454
// Deploy services
449455
// start by making a 10-pod deployment to back the services
450-
deployment = makeDeployment(namespace, "standing-svc", 10, false, webServerImage, []string{})
456+
deployment = makeDeployment(namespace, "standing-svc", 10, false, webServerImage, []string{"svc-backend"})
451457
deployment, err = utils.GetOrCreateDeployment(ctx, clients, deployment)
452458
if err != nil {
453459
log.WithError(err).Error("error creating deployment standing-svc")

pkg/cluster/cluster_internal.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,19 @@ func makeSvc(namespace string, depname, svcname string) corev1.Service {
597597
return svc
598598
}
599599

600-
func makeDeployment(namespace string, depname string, replicas int32, hostnetwork bool, image string, args []string) appsv1.Deployment {
600+
601+
func makeDeployment(namespace string, depname string, replicas int32, hostnetwork bool, image string, labels []string) appsv1.Deployment {
601602
log.Debug("entering makeDeployment function")
602603
depname = utils.SanitizeString(depname)
604+
605+
lbls := map[string]string{
606+
"app": "standing",
607+
"dep": depname,
608+
}
609+
for _, label := range labels {
610+
lbls[label] = "true"
611+
}
612+
603613
dep := appsv1.Deployment{
604614
ObjectMeta: metav1.ObjectMeta{
605615
Labels: map[string]string{
@@ -619,10 +629,7 @@ func makeDeployment(namespace string, depname string, replicas int32, hostnetwor
619629
},
620630
Template: corev1.PodTemplateSpec{
621631
ObjectMeta: metav1.ObjectMeta{
622-
Labels: map[string]string{
623-
"app": "standing",
624-
"dep": depname,
625-
},
632+
Labels: lbls,
626633
},
627634
Spec: corev1.PodSpec{
628635
AutomountServiceAccountToken: utils.BoolPtr(false),
@@ -638,7 +645,6 @@ func makeDeployment(namespace string, depname string, replicas int32, hostnetwor
638645
{
639646
Name: depname,
640647
Image: image,
641-
Args: args,
642648
SecurityContext: &corev1.SecurityContext{
643649
Privileged: utils.BoolPtr(false),
644650
AllowPrivilegeEscalation: utils.BoolPtr(false),

pkg/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type TestKind string
7878

7979
// TestKind possible values.
8080
const (
81+
TestKindNone TestKind = "none"
8182
TestKindDNSPerf TestKind = "dnsperf"
8283
TestKindIperf TestKind = "iperf"
8384
TestKindQperf TestKind = "thruput-latency"
@@ -120,7 +121,7 @@ const (
120121

121122
// TestConfig represents a test to run on a cluster, and the configuration for the test.
122123
type TestConfig struct {
123-
TestKind TestKind `validate:"required,oneof=dnsperf iperf thruput-latency ttfr"`
124+
TestKind TestKind `validate:"required,oneof=none dnsperf iperf thruput-latency ttfr"`
124125
Encap Encap `validate:"omitempty,oneof=none vxlan ipip"`
125126
Dataplane DataPlane `validate:"omitempty,oneof=iptables bpf nftables"`
126127
NumPolicies int `validate:"gte=0"`

pkg/dnsperf/dnsperf.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func runDNSPerfTest(ctx context.Context, srcPod *corev1.Pod, target string) (Cur
342342
cmd := fmt.Sprintf("%s %s:8080", cmdfrag, target)
343343
stdout, _, err := utils.ExecCommandInPod(ctx, srcPod, cmd, 10)
344344
if err != nil {
345-
if ctx.Err() == nil { // Only log error if context is still valid
345+
if ctx.Err() == nil { // Only log error if context is still valid
346346
log.WithError(err).Error("failed to run curl command")
347347
}
348348
result.Success = false
@@ -550,10 +550,10 @@ func makeDNSPerfPod(nodename string, namespace string, podname string, image str
550550
},
551551
Containers: []corev1.Container{
552552
{
553-
Name: "dnsperf",
554-
Image: image,
553+
Name: "dnsperf",
554+
Image: image,
555+
Command: []string{"/bin/sh", "-c"},
555556
Args: []string{
556-
"sh", "-c",
557557
"while true; do echo `date`: MARK; sleep 10; done",
558558
},
559559
SecurityContext: &corev1.SecurityContext{

pkg/iperf/iperf.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,10 @@ func makePod(nodename string, namespace string, podname string, hostnetwork bool
338338
},
339339
Containers: []corev1.Container{
340340
{
341-
Name: "iperf",
342-
Image: image,
341+
Name: "iperf",
342+
Image: image,
343+
Command: []string{"/bin/sh", "-c"},
343344
Args: []string{
344-
"/bin/sh",
345-
"-c",
346345
command,
347346
},
348347
SecurityContext: &corev1.SecurityContext{

pkg/policy/policy.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,9 @@ func DeployPolicies(ctx context.Context, clients config.Clients, numPolicies int
5151
}
5252
if numPolicies > currentNumPolicies {
5353
// If we do not have enough policies, create them
54-
podSelector := metav1.LabelSelector{
55-
MatchExpressions: []metav1.LabelSelectorRequirement{
56-
{Key: "app", Operator: metav1.LabelSelectorOpExists},
57-
},
58-
}
54+
podSelector := metav1.LabelSelector{}
5955

60-
ingressPeers := []networkingv1.NetworkPolicyPeer{
61-
{
62-
PodSelector: &podSelector,
63-
},
64-
}
65-
return BulkCreatePolicies(ctx, clients, namespace, "policy", podSelector, ingressPeers, currentNumPolicies, numPolicies)
56+
return BulkCreatePolicies(ctx, clients, namespace, "policy", podSelector, nil, currentNumPolicies, numPolicies)
6657

6758
} else if numPolicies < currentNumPolicies {
6859
// if we have too many policies, delete some
@@ -124,12 +115,34 @@ func BulkCreatePolicies(ctx context.Context, clients config.Clients, namespace s
124115
sem := make(chan struct{}, numThreads)
125116
for i, v := range policyIndexes {
126117
name := fmt.Sprintf("%s-%.5d", prefix, v)
118+
peers := ingressPeers
119+
if peers == nil {
120+
peers = []networkingv1.NetworkPolicyPeer{
121+
{
122+
PodSelector: &metav1.LabelSelector{
123+
MatchExpressions: []metav1.LabelSelectorRequirement{
124+
{Key: fmt.Sprintf("policy-%d", v), Operator: metav1.LabelSelectorOpExists},
125+
},
126+
},
127+
},
128+
}
129+
}
130+
podMatch := podSelector.MatchExpressions
131+
selector := podSelector
132+
if podMatch == nil {
133+
selector = metav1.LabelSelector{
134+
MatchExpressions: []metav1.LabelSelectorRequirement{
135+
{Key: fmt.Sprintf("policy-%d", v), Operator: metav1.LabelSelectorOpExists},
136+
{Key: fmt.Sprintf("blah-%d", v), Operator: metav1.LabelSelectorOpDoesNotExist},
137+
},
138+
}
139+
}
127140
sem <- struct{}{}
128141
wg.Add(1)
129142
go func() {
130143
defer wg.Done()
131144
defer func() { <-sem }()
132-
errors[i] = createPolicy(ctx, clients, name, namespace, podSelector, ingressPeers, []int{80})
145+
errors[i] = createPolicy(ctx, clients, name, namespace, selector, peers, []int{80})
133146
}()
134147
}
135148
wg.Wait()

pkg/qperf/qperf.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ func makeQperfPod(nodename string, namespace string, podname string, image strin
367367
},
368368
Containers: []corev1.Container{
369369
{
370-
Name: "qperf",
371-
Image: image,
370+
Name: "qperf",
371+
Image: image,
372+
Command: []string{"/usr/bin/qperf"},
372373
Args: []string{
373-
"qperf",
374374
"-lp",
375375
controlPortStr,
376376
},

pkg/results/results.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type Result struct {
3030
ClusterDetails cluster.Details `json:"ClusterDetails"`
3131
// CalicoNodeCPU stats.MinMaxAvg `json:"CalicoNodeCPU,omitempty"`
3232
// CalicoNodeMemory stats.MinMaxAvg `json:"CalicoNodeMemory,omitempty"`
33-
TTFR []*ttfr.ResultSummary `json:"ttfr,omitempty"`
34-
IPerf *iperf.ResultSummary `json:"iperf,omitempty"`
35-
QPerf *qperf.ResultSummary `json:"thruput-latency,omitempty"`
36-
DNSPerf *dnsperf.Results `json:"dnsperf,omitempty"`
33+
TTFR []*ttfr.ResultSummary `json:"ttfr,omitempty"`
34+
IPerf *iperf.ResultSummary `json:"iperf,omitempty"`
35+
QPerf *qperf.ResultSummary `json:"thruput-latency,omitempty"`
36+
DNSPerf *dnsperf.Results `json:"dnsperf,omitempty"`
3737
}

pkg/stats/stats_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ func TestSummarizeResults(t *testing.T) {
8282
name: "summarize positive numbers",
8383
input: []float64{1, 2, 3, 4, 5},
8484
expected: ResultSummary{
85-
Min: 1,
86-
Max: 5,
87-
Average: 3,
88-
P50: 3,
89-
P75: 4,
90-
P90: 5,
91-
P99: 5,
85+
Min: 1,
86+
Max: 5,
87+
Average: 3,
88+
P50: 3,
89+
P75: 4,
90+
P90: 5,
91+
P99: 5,
9292
NumDataPoints: 5,
9393
},
9494
err: false,
@@ -97,13 +97,13 @@ func TestSummarizeResults(t *testing.T) {
9797
name: "summarize negative numbers",
9898
input: []float64{-1, -2, -3, -4, -5},
9999
expected: ResultSummary{
100-
Min: -5,
101-
Max: -1,
102-
Average: -3,
103-
P50: -3,
104-
P75: -2,
105-
P90: -1,
106-
P99: -1,
100+
Min: -5,
101+
Max: -1,
102+
Average: -3,
103+
P50: -3,
104+
P75: -2,
105+
P90: -1,
106+
P99: -1,
107107
NumDataPoints: 5,
108108
},
109109
err: false,
@@ -112,13 +112,13 @@ func TestSummarizeResults(t *testing.T) {
112112
name: "summarize mixed numbers",
113113
input: []float64{-1, 2, -3, 4, -5},
114114
expected: ResultSummary{
115-
Min: -5,
116-
Max: 4,
117-
Average: -0.6,
118-
P50: -1,
119-
P75: 2,
120-
P90: 4,
121-
P99: 4,
115+
Min: -5,
116+
Max: 4,
117+
Average: -0.6,
118+
P50: -1,
119+
P75: 2,
120+
P90: 4,
121+
P99: 4,
122122
NumDataPoints: 5,
123123
},
124124
err: false,
@@ -127,13 +127,13 @@ func TestSummarizeResults(t *testing.T) {
127127
name: "summarize empty slice",
128128
input: []float64{},
129129
expected: ResultSummary{
130-
Min: 0,
131-
Max: 0,
132-
Average: 0,
133-
P50: 0,
134-
P75: 0,
135-
P90: 0,
136-
P99: 0,
130+
Min: 0,
131+
Max: 0,
132+
Average: 0,
133+
P50: 0,
134+
P75: 0,
135+
P90: 0,
136+
P99: 0,
137137
NumDataPoints: 0,
138138
},
139139
err: true,
@@ -142,13 +142,13 @@ func TestSummarizeResults(t *testing.T) {
142142
name: "summarize single element",
143143
input: []float64{42},
144144
expected: ResultSummary{
145-
Min: 42,
146-
Max: 42,
147-
Average: 42,
148-
P50: 42,
149-
P75: 42,
150-
P90: 42,
151-
P99: 42,
145+
Min: 42,
146+
Max: 42,
147+
Average: 42,
148+
P50: 42,
149+
P75: 42,
150+
P90: 42,
151+
P99: 42,
152152
NumDataPoints: 1,
153153
},
154154
err: false,

0 commit comments

Comments
 (0)