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
477da920
Commit
477da920
authored
Nov 12, 2015
by
harry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move hostIP detection from master to server
Add PublicAddress in test files Move valid public addr into util
parent
fc927e87
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
18 deletions
+47
-18
integration.go
cmd/integration/integration.go
+8
-1
server.go
cmd/kube-apiserver/app/server.go
+9
-4
master.go
pkg/master/master.go
+0
-13
master_test.go
pkg/master/master_test.go
+1
-0
util.go
pkg/util/util.go
+14
-0
auth_test.go
test/integration/auth_test.go
+10
-0
scheduler_test.go
test/integration/scheduler_test.go
+3
-0
secret_test.go
test/integration/secret_test.go
+2
-0
No files found.
cmd/integration/integration.go
View file @
477da920
...
...
@@ -170,6 +170,13 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
glog
.
Fatalf
(
"No public address for %s"
,
host
)
}
// The caller of master.New should guarantee pulicAddress is properly set
hostIP
,
err
:=
util
.
ValidPublicAddrForMaster
(
publicAddress
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to find suitable network address.error='%v' . "
+
"Fail to get a valid public address for master."
,
err
)
}
// Create a master and install handlers into mux.
m
:=
master
.
New
(
&
master
.
Config
{
StorageDestinations
:
storageDestinations
,
...
...
@@ -182,7 +189,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
Authorizer
:
apiserver
.
NewAlwaysAllowAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
ReadWritePort
:
portNumber
,
PublicAddress
:
publicAddress
,
PublicAddress
:
hostIP
,
CacheTimeout
:
2
*
time
.
Second
,
StorageVersions
:
storageVersions
,
})
...
...
cmd/kube-apiserver/app/server.go
View file @
477da920
...
...
@@ -367,12 +367,17 @@ func (s *APIServer) Run(_ []string) error {
s
.
verifyClusterIPFlags
()
// If advertise-address is not specified, use bind-address. If bind-address
// is not usable (unset, 0.0.0.0, or loopback), setDefaults() in
// pkg/master/master.go will do the right thing and use the host's default
// interface.
// is not usable (unset, 0.0.0.0, or loopback), we will use the host's default
// interface as valid public addr for master (see: util#ValidPublicAddrForMaster)
if
s
.
AdvertiseAddress
==
nil
||
s
.
AdvertiseAddress
.
IsUnspecified
()
{
s
.
AdvertiseAddress
=
s
.
BindAddress
hostIP
,
err
:=
util
.
ValidPublicAddrForMaster
(
s
.
BindAddress
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to find suitable network address.error='%v' . "
+
"Try to set the AdvertiseAddress directly or provide a valid BindAddress to fix this."
,
err
)
}
s
.
AdvertiseAddress
=
hostIP
}
glog
.
Infof
(
"Will report %v as public IP address."
,
s
.
AdvertiseAddress
)
if
(
s
.
EtcdConfigFile
!=
""
&&
len
(
s
.
EtcdServerList
)
!=
0
)
||
(
s
.
EtcdConfigFile
==
""
&&
len
(
s
.
EtcdServerList
)
==
0
)
{
glog
.
Fatalf
(
"Specify either --etcd-servers or --etcd-config"
)
...
...
pkg/master/master.go
View file @
477da920
...
...
@@ -401,19 +401,6 @@ func setDefaults(c *Config) {
if
c
.
CacheTimeout
==
0
{
c
.
CacheTimeout
=
5
*
time
.
Second
}
for
c
.
PublicAddress
==
nil
||
c
.
PublicAddress
.
IsUnspecified
()
||
c
.
PublicAddress
.
IsLoopback
()
{
// TODO: This should be done in the caller and just require a
// valid value to be passed in.
hostIP
,
err
:=
util
.
ChooseHostInterface
()
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to find suitable network address.error='%v' . "
+
"Will try again in 5 seconds. Set the public address directly to avoid this wait."
,
err
)
time
.
Sleep
(
5
*
time
.
Second
)
continue
}
c
.
PublicAddress
=
hostIP
glog
.
Infof
(
"Will report %v as public IP address."
,
c
.
PublicAddress
)
}
if
c
.
RequestContextMapper
==
nil
{
c
.
RequestContextMapper
=
api
.
NewRequestContextMapper
()
}
...
...
pkg/master/master_test.go
View file @
477da920
...
...
@@ -74,6 +74,7 @@ func setUp(t *testing.T) (Master, *etcdtesting.EtcdTestServer, Config, *assert.A
storageVersions
[
""
]
=
testapi
.
Default
.
Version
()
storageVersions
[
"extensions"
]
=
testapi
.
Extensions
.
GroupAndVersion
()
config
.
StorageVersions
=
storageVersions
config
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
master
.
nodeRegistry
=
registrytest
.
NewNodeRegistry
([]
string
{
"node1"
,
"node2"
},
api
.
NodeResources
{})
return
master
,
server
,
config
,
assert
.
New
(
t
)
...
...
pkg/util/util.go
View file @
477da920
...
...
@@ -512,3 +512,17 @@ func ReadDirNoExit(dirname string) ([]os.FileInfo, []error, error) {
return
list
,
errs
,
nil
}
// If bind-address is usable, return it directly
// If bind-address is not usable (unset, 0.0.0.0, or loopback), we will use the host's default
// interface.
func
ValidPublicAddrForMaster
(
bindAddress
net
.
IP
)
(
net
.
IP
,
error
)
{
if
bindAddress
==
nil
||
bindAddress
.
IsUnspecified
()
||
bindAddress
.
IsLoopback
()
{
hostIP
,
err
:=
ChooseHostInterface
()
if
err
!=
nil
{
return
nil
,
err
}
bindAddress
=
hostIP
}
return
bindAddress
,
nil
}
test/integration/auth_test.go
View file @
477da920
...
...
@@ -28,6 +28,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
"net/url"
...
...
@@ -420,6 +421,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
Authorizer
:
apiserver
.
NewAlwaysAllowAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
transport
:=
http
.
DefaultTransport
...
...
@@ -549,6 +551,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
Authorizer
:
apiserver
.
NewAlwaysDenyAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
transport
:=
http
.
DefaultTransport
...
...
@@ -630,6 +633,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
Authorizer
:
allowAliceAuthorizer
{},
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
previousResourceVersion
:=
make
(
map
[
string
]
float64
)
...
...
@@ -730,6 +734,7 @@ func TestBobIsForbidden(t *testing.T) {
Authorizer
:
allowAliceAuthorizer
{},
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
transport
:=
http
.
DefaultTransport
...
...
@@ -804,6 +809,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
Authorizer
:
allowAliceAuthorizer
{},
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
transport
:=
http
.
DefaultTransport
...
...
@@ -903,6 +909,7 @@ func TestAuthorizationAttributeDetermination(t *testing.T) {
Authorizer
:
trackingAuthorizer
,
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
transport
:=
http
.
DefaultTransport
...
...
@@ -997,6 +1004,7 @@ func TestNamespaceAuthorization(t *testing.T) {
Authorizer
:
a
,
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
previousResourceVersion
:=
make
(
map
[
string
]
float64
)
...
...
@@ -1125,6 +1133,7 @@ func TestKindAuthorization(t *testing.T) {
Authorizer
:
a
,
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
previousResourceVersion
:=
make
(
map
[
string
]
float64
)
...
...
@@ -1240,6 +1249,7 @@ func TestReadOnlyAuthorization(t *testing.T) {
Authorizer
:
a
,
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
transport
:=
http
.
DefaultTransport
...
...
test/integration/scheduler_test.go
View file @
477da920
...
...
@@ -22,6 +22,7 @@ package integration
import
(
"fmt"
"net"
"net/http"
"net/http/httptest"
"sync"
...
...
@@ -91,6 +92,7 @@ func TestUnschedulableNodes(t *testing.T) {
Authorizer
:
apiserver
.
NewAlwaysAllowAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
restClient
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
GroupVersion
:
testapi
.
Default
.
GroupVersion
()})
...
...
@@ -341,6 +343,7 @@ func BenchmarkScheduling(b *testing.B) {
Authorizer
:
apiserver
.
NewAlwaysAllowAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
c
:=
client
.
NewOrDie
(
&
client
.
Config
{
...
...
test/integration/secret_test.go
View file @
477da920
...
...
@@ -21,6 +21,7 @@ package integration
// This file tests use of the secrets API resource.
import
(
"net"
"net/http"
"net/http/httptest"
"testing"
...
...
@@ -81,6 +82,7 @@ func TestSecrets(t *testing.T) {
Authorizer
:
apiserver
.
NewAlwaysAllowAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
StorageVersions
:
storageVersions
,
PublicAddress
:
net
.
ParseIP
(
"192.168.10.4"
),
})
framework
.
DeleteAllEtcdKeys
()
...
...
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