in clusterloader2/pkg/measurement/common/network-policy/network-policy-enforcement-latency.go [297:351]
func (nps *networkPolicyEnforcementMeasurement) runPolicyCreationTest(depTemplateMap map[string]interface{}, config *measurement.Config) error {
klog.V(2).Infof("Starting network policy enforcement latency measurement for policy creation")
if nps.baseline {
klog.Warningf("Baseline flag is specified, which is only used for pod creation test, and means that no network policies should be created. Skipping policy creation test")
return nil
}
if err := nps.createTestClientDeployments(depTemplateMap, policyCreationTest, depTestClientPolicyCreationFilePath); err != nil {
return err
}
const (
timeout = 2 * time.Minute
waitInterval = 5 * time.Second
)
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
defer cancel()
desiredPodCount := len(nps.targetNamespaces)
options := &measurementutil.WaitForPodOptions{
DesiredPodCount: func() int { return desiredPodCount },
CallerName: nps.String(),
WaitForPodsInterval: waitInterval,
}
objectSelector := &util.ObjectSelector{
Namespace: nps.testClientNamespace,
LabelSelector: fmt.Sprintf("type = %s", policyCreationTest),
}
podStore, err := measurementutil.NewPodStore(nps.k8sClient, objectSelector)
if err != nil {
return err
}
klog.V(2).Infof("Waiting for policy creation test client pods to be running")
_, err = measurementutil.WaitForPods(ctx, podStore, options)
if err != nil {
klog.Warningf("Not all %d policy creation test client pods are running after %v", len(nps.targetNamespaces), timeout)
}
wg := sync.WaitGroup{}
wg.Add(1)
// Create load policies while allow policies are being created to take network
// policy churn into account.
go func() {
nps.createLoadPolicies(config)
wg.Done()
}()
nps.createAllowPoliciesForPolicyCreationLatency()
wg.Wait()
return nil
}