Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new tests to improve coverage and removes unused params passed to proxy server. #14946

Merged
merged 2 commits into from
Oct 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 9 additions & 25 deletions cmd/kube-proxy/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,10 @@ type ProxyServerConfig struct {
}

type ProxyServer struct {
Client *kubeclient.Client
Config *ProxyServerConfig
EndpointsConfig *proxyconfig.EndpointsConfig
EndpointsHandler proxyconfig.EndpointsConfigHandler
IptInterface utiliptables.Interface
OOMAdjuster *oom.OOMAdjuster
Proxier proxy.ProxyProvider
Recorder record.EventRecorder
ServiceConfig *proxyconfig.ServiceConfig
Config *ProxyServerConfig
IptInterface utiliptables.Interface
Proxier proxy.ProxyProvider
Recorder record.EventRecorder
}

// AddFlags adds flags for a specific ProxyServer to the specified FlagSet
Expand Down Expand Up @@ -122,25 +117,15 @@ func NewProxyConfig() *ProxyServerConfig {

func NewProxyServer(
config *ProxyServerConfig,
client *kubeclient.Client,
endpointsConfig *proxyconfig.EndpointsConfig,
endpointsHandler proxyconfig.EndpointsConfigHandler,
iptInterface utiliptables.Interface,
oomAdjuster *oom.OOMAdjuster,
proxier proxy.ProxyProvider,
recorder record.EventRecorder,
serviceConfig *proxyconfig.ServiceConfig,
) (*ProxyServer, error) {
return &ProxyServer{
Client: client,
Config: config,
EndpointsConfig: endpointsConfig,
EndpointsHandler: endpointsHandler,
IptInterface: iptInterface,
OOMAdjuster: oomAdjuster,
Proxier: proxier,
Recorder: recorder,
ServiceConfig: serviceConfig,
Config: config,
IptInterface: iptInterface,
Proxier: proxier,
Recorder: recorder,
}, nil
}

Expand Down Expand Up @@ -272,8 +257,7 @@ func NewProxyServerDefault(config *ProxyServerConfig) (*ProxyServer, error) {
UID: types.UID(hostname),
Namespace: "",
}

return NewProxyServer(config, client, endpointsConfig, endpointsHandler, iptInterface, oomAdjuster, proxier, recorder, serviceConfig)
return NewProxyServer(config, iptInterface, proxier, recorder)
}

// Run runs the specified ProxyServer. This should never exit (unless CleanupAndExit is set).
Expand Down
22 changes: 22 additions & 0 deletions cmd/kube-proxy/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package app
import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/kubernetes/pkg/api"
)

Expand Down Expand Up @@ -59,3 +60,24 @@ func Test_mayTryIptablesProxy(t *testing.T) {
}
}
}

//This test verifies that Proxy Server does not crash that means
//Config and iptinterface are not nil when CleanupAndExit is true.
//To avoid proxy crash: https://github.com/kubernetes/kubernetes/pull/14736
func TestProxyServerWithCleanupAndExit(t *testing.T) {

//creates default config
config := NewProxyConfig()

//sets CleanupAndExit manually
config.CleanupAndExit = true

//creates new proxy server
proxyserver, err := NewProxyServerDefault(config)

//verifies that nothing is nill except error
assert.Nil(t, err)
assert.NotNil(t, proxyserver)
assert.NotNil(t, proxyserver.Config)
assert.NotNil(t, proxyserver.IptInterface)
}