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
27ee6ea0
Commit
27ee6ea0
authored
Apr 20, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move port splitting to common place; add to node resource location
parent
996ded35
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
19 deletions
+125
-19
rest.go
pkg/registry/minion/rest.go
+13
-2
rest.go
pkg/registry/pod/rest.go
+4
-9
rest.go
pkg/registry/service/rest.go
+3
-8
port_split.go
pkg/util/port_split.go
+40
-0
port_split_test.go
pkg/util/port_split_test.go
+65
-0
No files found.
pkg/registry/minion/rest.go
View file @
27ee6ea0
...
@@ -24,12 +24,14 @@ import (
...
@@ -24,12 +24,14 @@ import (
"strconv"
"strconv"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
)
)
...
@@ -129,12 +131,21 @@ func MatchNode(label labels.Selector, field fields.Selector) generic.Matcher {
...
@@ -129,12 +131,21 @@ func MatchNode(label labels.Selector, field fields.Selector) generic.Matcher {
// ResourceLocation returns a URL to which one can send traffic for the specified node.
// ResourceLocation returns a URL to which one can send traffic for the specified node.
func
ResourceLocation
(
getter
ResourceGetter
,
connection
client
.
ConnectionInfoGetter
,
ctx
api
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
ResourceLocation
(
getter
ResourceGetter
,
connection
client
.
ConnectionInfoGetter
,
ctx
api
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
nodeObj
,
err
:=
getter
.
Get
(
ctx
,
id
)
name
,
portReq
,
valid
:=
util
.
SplitPort
(
id
)
if
!
valid
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"invalid node request %q"
,
id
))
}
nodeObj
,
err
:=
getter
.
Get
(
ctx
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
node
:=
nodeObj
.
(
*
api
.
Node
)
node
:=
nodeObj
.
(
*
api
.
Node
)
host
:=
node
.
Name
host
:=
node
.
Name
// TODO: use node's IP, don't expect the name to resolve.
if
portReq
!=
""
{
return
&
url
.
URL
{
Host
:
net
.
JoinHostPort
(
host
,
portReq
)},
nil
,
nil
}
scheme
,
port
,
transport
,
err
:=
connection
.
GetConnectionInfo
(
host
)
scheme
,
port
,
transport
,
err
:=
connection
.
GetConnectionInfo
(
host
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/pod/rest.go
View file @
27ee6ea0
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"net"
"net"
"net/http"
"net/http"
"net/url"
"net/url"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
...
@@ -31,6 +30,7 @@ import (
...
@@ -31,6 +30,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
)
)
...
@@ -150,16 +150,11 @@ func getPod(getter ResourceGetter, ctx api.Context, name string) (*api.Pod, erro
...
@@ -150,16 +150,11 @@ func getPod(getter ResourceGetter, ctx api.Context, name string) (*api.Pod, erro
func
ResourceLocation
(
getter
ResourceGetter
,
ctx
api
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
ResourceLocation
(
getter
ResourceGetter
,
ctx
api
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
// Allow ID as "podname" or "podname:port". If port is not specified,
// Allow ID as "podname" or "podname:port". If port is not specified,
// try to use the first defined port on the pod.
// try to use the first defined port on the pod.
parts
:=
strings
.
Split
(
id
,
":"
)
name
,
port
,
valid
:=
util
.
SplitPort
(
id
)
if
len
(
parts
)
>
2
{
if
!
valid
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"invalid pod request %q"
,
id
))
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"invalid pod request %q"
,
id
))
}
}
name
:=
parts
[
0
]
// TODO: if port is not a number but a "(container)/(portname)", do a name lookup.
port
:=
""
if
len
(
parts
)
==
2
{
// TODO: if port is not a number but a "(container)/(portname)", do a name lookup.
port
=
parts
[
1
]
}
pod
,
err
:=
getPod
(
getter
,
ctx
,
name
)
pod
,
err
:=
getPod
(
getter
,
ctx
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/service/rest.go
View file @
27ee6ea0
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"strconv"
"strconv"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
...
@@ -34,6 +33,7 @@ import (
...
@@ -34,6 +33,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/endpoint"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/endpoint"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -206,15 +206,10 @@ var _ = rest.Redirector(&REST{})
...
@@ -206,15 +206,10 @@ var _ = rest.Redirector(&REST{})
// ResourceLocation returns a URL to which one can send traffic for the specified service.
// ResourceLocation returns a URL to which one can send traffic for the specified service.
func
(
rs
*
REST
)
ResourceLocation
(
ctx
api
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
(
rs
*
REST
)
ResourceLocation
(
ctx
api
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
// Allow ID as "svcname" or "svcname:port".
// Allow ID as "svcname" or "svcname:port".
parts
:=
strings
.
Split
(
id
,
":"
)
svcName
,
portStr
,
valid
:=
util
.
SplitPort
(
id
)
if
len
(
parts
)
>
2
{
if
!
valid
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"invalid service request %q"
,
id
))
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"invalid service request %q"
,
id
))
}
}
svcName
:=
parts
[
0
]
portStr
:=
""
if
len
(
parts
)
==
2
{
portStr
=
parts
[
1
]
}
eps
,
err
:=
rs
.
endpoints
.
GetEndpoints
(
ctx
,
svcName
)
eps
,
err
:=
rs
.
endpoints
.
GetEndpoints
(
ctx
,
svcName
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/util/port_split.go
0 → 100644
View file @
27ee6ea0
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"strings"
)
// Takes a string of the form "name:port" or "name".
// * If id is of the form "name" or "name:", then return (name, "", true)
// * If id is of the form "name:port", then return (name, port, true)
// * Otherwise, return ("", "", false)
// Additionally, name must be non-empty or valid will be returned false.
//
// Port is returned as a string, and it is not required to be numeric (could be
// used for a named port, for example).
func
SplitPort
(
id
string
)
(
name
,
port
string
,
valid
bool
)
{
parts
:=
strings
.
Split
(
id
,
":"
)
if
len
(
parts
)
>
2
{
return
""
,
""
,
false
}
if
len
(
parts
)
==
2
{
return
parts
[
0
],
parts
[
1
],
len
(
parts
[
0
])
>
0
}
return
id
,
""
,
len
(
id
)
>
0
}
pkg/util/port_split_test.go
0 → 100644
View file @
27ee6ea0
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"testing"
)
func
TestSplitPort
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
in
string
name
,
port
string
valid
bool
}{
{
in
:
"aoeu:asdf"
,
name
:
"aoeu"
,
port
:
"asdf"
,
valid
:
true
,
},
{
in
:
"aoeu:"
,
name
:
"aoeu"
,
valid
:
true
,
},
{
in
:
":asdf"
,
name
:
""
,
port
:
"asdf"
,
},
{
in
:
"aoeu:asdf:htns"
,
},
{
in
:
"aoeu"
,
name
:
"aoeu"
,
valid
:
true
,
},
{
in
:
""
,
},
}
for
_
,
item
:=
range
table
{
name
,
port
,
valid
:=
SplitPort
(
item
.
in
)
if
e
,
a
:=
item
.
name
,
name
;
e
!=
a
{
t
.
Errorf
(
"%q: Wanted %q, got %q"
,
item
.
in
,
e
,
a
)
}
if
e
,
a
:=
item
.
port
,
port
;
e
!=
a
{
t
.
Errorf
(
"%q: Wanted %q, got %q"
,
item
.
in
,
e
,
a
)
}
if
e
,
a
:=
item
.
valid
,
valid
;
e
!=
a
{
t
.
Errorf
(
"%q: Wanted %q, got %q"
,
item
.
in
,
e
,
a
)
}
}
}
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