Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
91ab8fe1
Commit
91ab8fe1
authored
Oct 18, 2017
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NewOptions doesn't need to return error in signature.
parent
1d589600
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
51 deletions
+7
-51
server.go
cmd/kube-proxy/app/server.go
+4
-8
server_test.go
cmd/kube-proxy/app/server_test.go
+3
-43
No files found.
cmd/kube-proxy/app/server.go
View file @
91ab8fe1
...
@@ -163,15 +163,13 @@ func AddFlags(options *Options, fs *pflag.FlagSet) {
...
@@ -163,15 +163,13 @@ func AddFlags(options *Options, fs *pflag.FlagSet) {
utilfeature
.
DefaultFeatureGate
.
AddFlag
(
fs
)
utilfeature
.
DefaultFeatureGate
.
AddFlag
(
fs
)
}
}
func
NewOptions
()
(
*
Options
,
error
)
{
func
NewOptions
()
*
Options
{
o
:=
&
Options
{
return
&
Options
{
config
:
new
(
proxyconfig
.
KubeProxyConfiguration
),
config
:
new
(
proxyconfig
.
KubeProxyConfiguration
),
healthzPort
:
ports
.
ProxyHealthzPort
,
healthzPort
:
ports
.
ProxyHealthzPort
,
scheme
:
scheme
.
Scheme
,
scheme
:
scheme
.
Scheme
,
codecs
:
scheme
.
Codecs
,
codecs
:
scheme
.
Codecs
,
}
}
return
o
,
nil
}
}
// Complete completes all the required options.
// Complete completes all the required options.
...
@@ -316,10 +314,7 @@ func (o *Options) ApplyDefaults(in *proxyconfig.KubeProxyConfiguration) (*proxyc
...
@@ -316,10 +314,7 @@ func (o *Options) ApplyDefaults(in *proxyconfig.KubeProxyConfiguration) (*proxyc
// NewProxyCommand creates a *cobra.Command object with default parameters
// NewProxyCommand creates a *cobra.Command object with default parameters
func
NewProxyCommand
()
*
cobra
.
Command
{
func
NewProxyCommand
()
*
cobra
.
Command
{
opts
,
err
:=
NewOptions
()
opts
:=
NewOptions
()
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to initialize command options: %v"
,
err
)
}
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"kube-proxy"
,
Use
:
"kube-proxy"
,
...
@@ -338,6 +333,7 @@ with the apiserver API to configure the proxy.`,
...
@@ -338,6 +333,7 @@ with the apiserver API to configure the proxy.`,
},
},
}
}
var
err
error
opts
.
config
,
err
=
opts
.
ApplyDefaults
(
opts
.
config
)
opts
.
config
,
err
=
opts
.
ApplyDefaults
(
opts
.
config
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"unable to create flag defaults: %v"
,
err
)
glog
.
Fatalf
(
"unable to create flag defaults: %v"
,
err
)
...
...
cmd/kube-proxy/app/server_test.go
View file @
91ab8fe1
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
app
package
app
import
(
import
(
"errors"
"fmt"
"fmt"
"reflect"
"reflect"
"runtime"
"runtime"
...
@@ -28,11 +27,9 @@ import (
...
@@ -28,11 +27,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
k8sRuntime
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/proxy/apis/proxyconfig"
"k8s.io/kubernetes/pkg/proxy/apis/proxyconfig"
"k8s.io/kubernetes/pkg/proxy/apis/proxyconfig/v1alpha1"
"k8s.io/kubernetes/pkg/util/configz"
"k8s.io/kubernetes/pkg/util/configz"
"k8s.io/kubernetes/pkg/util/iptables"
"k8s.io/kubernetes/pkg/util/iptables"
utilpointer
"k8s.io/kubernetes/pkg/util/pointer"
utilpointer
"k8s.io/kubernetes/pkg/util/pointer"
...
@@ -138,39 +135,6 @@ func Test_getProxyMode(t *testing.T) {
...
@@ -138,39 +135,6 @@ func Test_getProxyMode(t *testing.T) {
}
}
}
}
// TestNewOptionsFailures tests failure modes for NewOptions()
func
TestNewOptionsFailures
(
t
*
testing
.
T
)
{
// Create a fake scheme builder that generates an error
errString
:=
fmt
.
Sprintf
(
"Simulated error"
)
genError
:=
func
(
scheme
*
k8sRuntime
.
Scheme
)
error
{
return
errors
.
New
(
errString
)
}
fakeSchemeBuilder
:=
k8sRuntime
.
NewSchemeBuilder
(
genError
)
simulatedErrorTest
:=
func
(
target
string
)
{
var
addToScheme
*
func
(
s
*
k8sRuntime
.
Scheme
)
error
if
target
==
proxyconfig
.
GroupName
{
addToScheme
=
&
proxyconfig
.
AddToScheme
}
else
{
addToScheme
=
&
v1alpha1
.
AddToScheme
}
restoreValue
:=
*
addToScheme
restore
:=
func
()
{
*
addToScheme
=
restoreValue
}
defer
restore
()
*
addToScheme
=
fakeSchemeBuilder
.
AddToScheme
_
,
err
:=
NewOptions
()
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"Simulated error in component %s"
,
target
))
}
// Simulate errors in calls to AddToScheme()
faultTargets
:=
[]
string
{
proxyconfig
.
GroupName
,
"v1alpha1"
}
for
_
,
target
:=
range
faultTargets
{
simulatedErrorTest
(
target
)
}
}
// This test verifies that NewProxyServer does not crash when CleanupAndExit is true.
// This test verifies that NewProxyServer does not crash when CleanupAndExit is true.
func
TestProxyServerWithCleanupAndExit
(
t
*
testing
.
T
)
{
func
TestProxyServerWithCleanupAndExit
(
t
*
testing
.
T
)
{
// Each bind address below is a separate test case
// Each bind address below is a separate test case
...
@@ -179,10 +143,7 @@ func TestProxyServerWithCleanupAndExit(t *testing.T) {
...
@@ -179,10 +143,7 @@ func TestProxyServerWithCleanupAndExit(t *testing.T) {
"::"
,
"::"
,
}
}
for
_
,
addr
:=
range
bindAddresses
{
for
_
,
addr
:=
range
bindAddresses
{
options
,
err
:=
NewOptions
()
options
:=
NewOptions
()
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error with address %s: %v"
,
addr
,
err
)
}
options
.
config
=
&
proxyconfig
.
KubeProxyConfiguration
{
options
.
config
=
&
proxyconfig
.
KubeProxyConfiguration
{
BindAddress
:
addr
,
BindAddress
:
addr
,
...
@@ -410,8 +371,7 @@ udpTimeoutMilliseconds: 123ms
...
@@ -410,8 +371,7 @@ udpTimeoutMilliseconds: 123ms
UDPIdleTimeout
:
metav1
.
Duration
{
Duration
:
123
*
time
.
Millisecond
},
UDPIdleTimeout
:
metav1
.
Duration
{
Duration
:
123
*
time
.
Millisecond
},
}
}
options
,
err
:=
NewOptions
()
options
:=
NewOptions
()
assert
.
NoError
(
t
,
err
,
"unexpected error for %s: %v"
,
tc
.
name
,
err
)
yaml
:=
fmt
.
Sprintf
(
yaml
:=
fmt
.
Sprintf
(
yamlTemplate
,
tc
.
bindAddress
,
tc
.
clusterCIDR
,
yamlTemplate
,
tc
.
bindAddress
,
tc
.
clusterCIDR
,
...
@@ -449,7 +409,7 @@ func TestLoadConfigFailures(t *testing.T) {
...
@@ -449,7 +409,7 @@ func TestLoadConfigFailures(t *testing.T) {
}
}
version
:=
"apiVersion: kubeproxy.k8s.io/v1alpha1"
version
:=
"apiVersion: kubeproxy.k8s.io/v1alpha1"
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
options
,
_
:=
NewOptions
()
options
:=
NewOptions
()
config
:=
fmt
.
Sprintf
(
"%s
\n
%s"
,
version
,
tc
.
config
)
config
:=
fmt
.
Sprintf
(
"%s
\n
%s"
,
version
,
tc
.
config
)
_
,
err
:=
options
.
loadConfig
([]
byte
(
config
))
_
,
err
:=
options
.
loadConfig
([]
byte
(
config
))
if
assert
.
Error
(
t
,
err
,
tc
.
name
)
{
if
assert
.
Error
(
t
,
err
,
tc
.
name
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment