mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-21 17:34:31 +00:00
proxy: remove newProxyConfig
The proxy config does not depend on proxy type. Let's not misture them. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
c41c9de839
commit
f39fa5d489
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
@ -14,8 +15,12 @@ type ccProxy struct {
|
||||
|
||||
// start is the proxy start implementation for ccProxy.
|
||||
func (p *ccProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
|
||||
config, err := newProxyConfig(sandbox.config)
|
||||
if err != nil {
|
||||
if sandbox.config == nil {
|
||||
return -1, "", fmt.Errorf("Sandbox config cannot be nil")
|
||||
}
|
||||
|
||||
config := sandbox.config.ProxyConfig
|
||||
if err := validateProxyConfig(config); err != nil {
|
||||
return -1, "", err
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,10 @@ func (p *kataProxy) consoleWatched() bool {
|
||||
// start is kataProxy start implementation for proxy interface.
|
||||
func (p *kataProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
|
||||
sandbox.Logger().Info("Starting regular Kata proxy rather than built-in")
|
||||
if sandbox.config == nil {
|
||||
return -1, "", fmt.Errorf("Sandbox config cannot be nil")
|
||||
}
|
||||
|
||||
if sandbox.agent == nil {
|
||||
return -1, "", fmt.Errorf("No agent")
|
||||
}
|
||||
@ -33,8 +37,8 @@ func (p *kataProxy) start(sandbox *Sandbox, params proxyParams) (int, string, er
|
||||
return -1, "", fmt.Errorf("AgentURL cannot be empty")
|
||||
}
|
||||
|
||||
config, err := newProxyConfig(sandbox.config)
|
||||
if err != nil {
|
||||
config := sandbox.config.ProxyConfig
|
||||
if err := validateProxyConfig(config); err != nil {
|
||||
return -1, "", err
|
||||
}
|
||||
|
||||
|
@ -119,28 +119,12 @@ func newProxy(pType ProxyType) (proxy, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// newProxyConfig returns a proxy config from a generic SandboxConfig handler,
|
||||
// after it properly checked the configuration was valid.
|
||||
func newProxyConfig(sandboxConfig *SandboxConfig) (ProxyConfig, error) {
|
||||
if sandboxConfig == nil {
|
||||
return ProxyConfig{}, fmt.Errorf("Sandbox config cannot be nil")
|
||||
func validateProxyConfig(proxyConfig ProxyConfig) error {
|
||||
if len(proxyConfig.Path) == 0 {
|
||||
return fmt.Errorf("Proxy path cannot be empty")
|
||||
}
|
||||
|
||||
var config ProxyConfig
|
||||
switch sandboxConfig.ProxyType {
|
||||
case KataProxyType:
|
||||
fallthrough
|
||||
case CCProxyType:
|
||||
config = sandboxConfig.ProxyConfig
|
||||
default:
|
||||
return ProxyConfig{}, fmt.Errorf("unknown proxy type %v", sandboxConfig.ProxyType)
|
||||
}
|
||||
|
||||
if config.Path == "" {
|
||||
return ProxyConfig{}, fmt.Errorf("Proxy path cannot be empty")
|
||||
}
|
||||
|
||||
return config, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func defaultProxyURL(sandbox *Sandbox, socketType string) (string, error) {
|
||||
|
@ -154,15 +154,15 @@ func TestNewProxyFromUnknownProxyType(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testNewProxyConfigFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfig, expected ProxyConfig) {
|
||||
result, err := newProxyConfig(&sandboxConfig)
|
||||
if err != nil {
|
||||
func testNewProxyFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfig) {
|
||||
if _, err := newProxy(sandboxConfig.ProxyType); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(result, expected) == false {
|
||||
t.Fatalf("Got %+v\nExpecting %+v", result, expected)
|
||||
if err := validateProxyConfig(sandboxConfig.ProxyConfig); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var testProxyPath = "proxy-path"
|
||||
@ -177,7 +177,7 @@ func TestNewProxyConfigFromCCProxySandboxConfig(t *testing.T) {
|
||||
ProxyConfig: proxyConfig,
|
||||
}
|
||||
|
||||
testNewProxyConfigFromSandboxConfig(t, sandboxConfig, proxyConfig)
|
||||
testNewProxyFromSandboxConfig(t, sandboxConfig)
|
||||
}
|
||||
|
||||
func TestNewProxyConfigFromKataProxySandboxConfig(t *testing.T) {
|
||||
@ -190,22 +190,11 @@ func TestNewProxyConfigFromKataProxySandboxConfig(t *testing.T) {
|
||||
ProxyConfig: proxyConfig,
|
||||
}
|
||||
|
||||
testNewProxyConfigFromSandboxConfig(t, sandboxConfig, proxyConfig)
|
||||
}
|
||||
|
||||
func TestNewProxyConfigNilSandboxConfigFailure(t *testing.T) {
|
||||
if _, err := newProxyConfig(nil); err == nil {
|
||||
t.Fatal("Should fail because SandboxConfig provided is nil")
|
||||
}
|
||||
testNewProxyFromSandboxConfig(t, sandboxConfig)
|
||||
}
|
||||
|
||||
func TestNewProxyConfigNoPathFailure(t *testing.T) {
|
||||
sandboxConfig := &SandboxConfig{
|
||||
ProxyType: CCProxyType,
|
||||
ProxyConfig: ProxyConfig{},
|
||||
}
|
||||
|
||||
if _, err := newProxyConfig(sandboxConfig); err == nil {
|
||||
if err := validateProxyConfig(ProxyConfig{}); err == nil {
|
||||
t.Fatal("Should fail because ProxyConfig has no Path")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user