Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,33 @@ func defaultAndValidate(cfg *Config) error {
if tcfg.Perf.ExternalIPOrFQDN == "" {
return fmt.Errorf("ExternalIPOrFQDN is required for an external thruput-latency test")
}
if tcfg.TestKind == "thruput-latency" {
if tcfg.Perf.ControlPort == 0 {
return fmt.Errorf("ControlPort is required for an external thruput-latency test")
}
if tcfg.Perf.ControlPort > 65535 || tcfg.Perf.ControlPort < 1 {
return fmt.Errorf("ControlPort must be between 1 and 65535")
}

// External ports can't be defaulted. The test tools don't work through NAT, so
// these have to match the ports the service is actually exposed on.
if tcfg.TestKind == "thruput-latency" && tcfg.Perf.ControlPort == 0 {
return fmt.Errorf("ControlPort is required for an external thruput-latency test")
}
if tcfg.Perf.TestPort == 0 {
return fmt.Errorf("TestPort is required for an external thruput-latency test")
}
if tcfg.Perf.TestPort > 65535 || tcfg.Perf.TestPort < 1 {
return fmt.Errorf("TestPort must be between 1 and 65535")
} else {
// Default the ports per-field rather than only when Perf is absent entirely. A
// config that sets some of Perf but leaves the ports out otherwise reaches the
// dataplane with port 0, and the apiserver rejects the test policy.
if tcfg.Perf.ControlPort == 0 {
tcfg.Perf.ControlPort = 32000
}
if tcfg.Perf.TestPort == 0 {
tcfg.Perf.TestPort = 32001
}
}

if tcfg.TestKind == "thruput-latency" && (tcfg.Perf.ControlPort > 65535 || tcfg.Perf.ControlPort < 1) {
return fmt.Errorf("ControlPort must be between 1 and 65535")
}
if tcfg.Perf.TestPort > 65535 || tcfg.Perf.TestPort < 1 {
return fmt.Errorf("TestPort must be between 1 and 65535")
}
}
}
return nil
Expand Down
59 changes: 59 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,62 @@ func TestTargetURLCustomValue(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "https://custom.example.org", cfg.TestConfigs[0].DNSPerf.TargetURL)
}

func TestPerfPortsDefaultedWhenPerfPartiallySpecified(t *testing.T) {
fileContent := `
- testKind: thruput-latency
Perf:
direct: true
service: true
external: false
`
filePath := "/tmp/test_configs.yaml"
err := os.WriteFile(filePath, []byte(fileContent), 0o644)
require.NoError(t, err)
defer os.Remove(filePath)

var cfg Config
cfg.TestConfigFile = filePath
err = loadTestConfigsFromFile(&cfg)
require.NoError(t, err)
assert.Equal(t, 32000, cfg.TestConfigs[0].Perf.ControlPort)
assert.Equal(t, 32001, cfg.TestConfigs[0].Perf.TestPort)
}

func TestPerfPortsStillRequiredForExternalTest(t *testing.T) {
fileContent := `
- testKind: thruput-latency
Perf:
external: true
ExternalIPOrFQDN: perf.example.com
`
filePath := "/tmp/test_configs.yaml"
err := os.WriteFile(filePath, []byte(fileContent), 0o644)
require.NoError(t, err)
defer os.Remove(filePath)

var cfg Config
cfg.TestConfigFile = filePath
err = loadTestConfigsFromFile(&cfg)
require.Error(t, err)
assert.Contains(t, err.Error(), "ControlPort is required")
}

func TestPerfPortOutOfRangeRejectedForNonExternalTest(t *testing.T) {
fileContent := `
- testKind: thruput-latency
Perf:
external: false
TestPort: 99999
`
filePath := "/tmp/test_configs.yaml"
err := os.WriteFile(filePath, []byte(fileContent), 0o644)
require.NoError(t, err)
defer os.Remove(filePath)

var cfg Config
cfg.TestConfigFile = filePath
err = loadTestConfigsFromFile(&cfg)
require.Error(t, err)
assert.Contains(t, err.Error(), "TestPort must be between 1 and 65535")
}
Loading