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
14193b45
Commit
14193b45
authored
Aug 26, 2015
by
Jerzy Szczepkowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13134 from jszczepkowski/client-proxy
Added ProxyGet method to services client.
parents
1a8b400c
08594dab
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
15 deletions
+87
-15
request.go
pkg/client/unversioned/request.go
+7
-0
services.go
pkg/client/unversioned/services.go
+17
-2
services_test.go
pkg/client/unversioned/services_test.go
+15
-0
actions.go
pkg/client/unversioned/testclient/actions.go
+37
-0
fake_services.go
pkg/client/unversioned/testclient/fake_services.go
+6
-0
horizontalpodautoscaler_controller.go
...ntroller/autoscaler/horizontalpodautoscaler_controller.go
+5
-13
No files found.
pkg/client/unversioned/request.go
View file @
14193b45
...
...
@@ -52,6 +52,13 @@ type HTTPClient interface {
Do
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
}
// ResponseWrapper is an interface for getting a response.
// The response may be either accessed as a raw data (the whole output is put into memory) or as a stream.
type
ResponseWrapper
interface
{
DoRaw
()
([]
byte
,
error
)
Stream
()
(
io
.
ReadCloser
,
error
)
}
// RequestConstructionError is returned when there's an error assembling a request.
type
RequestConstructionError
struct
{
Err
error
...
...
pkg/client/unversioned/services.go
View file @
14193b45
...
...
@@ -36,15 +36,16 @@ type ServiceInterface interface {
Update
(
srv
*
api
.
Service
)
(
*
api
.
Service
,
error
)
Delete
(
name
string
)
error
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
ProxyGet
(
name
,
path
string
,
params
map
[
string
]
string
)
ResponseWrapper
}
// services implements
Pod
sNamespacer interface
// services implements
Service
sNamespacer interface
type
services
struct
{
r
*
Client
ns
string
}
// newServices returns a
PodsClient
// newServices returns a
services
func
newServices
(
c
*
Client
,
namespace
string
)
*
services
{
return
&
services
{
c
,
namespace
}
}
...
...
@@ -98,3 +99,17 @@ func (c *services) Watch(label labels.Selector, field fields.Selector, resourceV
FieldsSelectorParam
(
field
)
.
Watch
()
}
// ProxyGet returns a response of the service by calling it through the proxy.
func
(
c
*
services
)
ProxyGet
(
name
,
path
string
,
params
map
[
string
]
string
)
ResponseWrapper
{
request
:=
c
.
r
.
Get
()
.
Prefix
(
"proxy"
)
.
Namespace
(
c
.
ns
)
.
Resource
(
"services"
)
.
Name
(
name
)
.
Suffix
(
path
)
for
k
,
v
:=
range
params
{
request
=
request
.
Param
(
k
,
v
)
}
return
request
}
pkg/client/unversioned/services_test.go
View file @
14193b45
...
...
@@ -152,3 +152,18 @@ func TestDeleteService(t *testing.T) {
err
:=
c
.
Setup
()
.
Services
(
ns
)
.
Delete
(
"1"
)
c
.
Validate
(
t
,
nil
,
err
)
}
func
TestServiceProxyGet
(
t
*
testing
.
T
)
{
body
:=
"OK"
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"GET"
,
Path
:
testapi
.
ResourcePathWithPrefix
(
"proxy"
,
"services"
,
ns
,
"service-1"
)
+
"/foo"
,
Query
:
buildQueryValues
(
url
.
Values
{
"param-name"
:
[]
string
{
"param-value"
}}),
},
Response
:
Response
{
StatusCode
:
200
,
RawBody
:
&
body
},
}
response
,
err
:=
c
.
Setup
()
.
Services
(
ns
)
.
ProxyGet
(
"service-1"
,
"foo"
,
map
[
string
]
string
{
"param-name"
:
"param-value"
})
.
DoRaw
()
c
.
ValidateRaw
(
t
,
response
,
err
)
}
pkg/client/unversioned/testclient/actions.go
View file @
14193b45
...
...
@@ -138,6 +138,17 @@ func NewWatchAction(resource, namespace string, label labels.Selector, field fie
return
action
}
func
NewProxyGetAction
(
resource
,
namespace
,
name
,
path
string
,
params
map
[
string
]
string
)
ProxyGetActionImpl
{
action
:=
ProxyGetActionImpl
{}
action
.
Verb
=
"get"
action
.
Resource
=
resource
action
.
Namespace
=
namespace
action
.
Name
=
name
action
.
Path
=
path
action
.
Params
=
params
return
action
}
type
ListRestrictions
struct
{
Labels
labels
.
Selector
Fields
fields
.
Selector
...
...
@@ -191,6 +202,13 @@ type WatchAction interface {
GetWatchRestrictions
()
WatchRestrictions
}
type
ProxyGetAction
interface
{
Action
GetName
()
string
GetPath
()
string
GetParams
()
map
[
string
]
string
}
type
ActionImpl
struct
{
Namespace
string
Verb
string
...
...
@@ -277,3 +295,22 @@ type WatchActionImpl struct {
func
(
a
WatchActionImpl
)
GetWatchRestrictions
()
WatchRestrictions
{
return
a
.
WatchRestrictions
}
type
ProxyGetActionImpl
struct
{
ActionImpl
Name
string
Path
string
Params
map
[
string
]
string
}
func
(
a
ProxyGetActionImpl
)
GetName
()
string
{
return
a
.
Name
}
func
(
a
ProxyGetActionImpl
)
GetPath
()
string
{
return
a
.
Path
}
func
(
a
ProxyGetActionImpl
)
GetParams
()
map
[
string
]
string
{
return
a
.
Params
}
pkg/client/unversioned/testclient/fake_services.go
View file @
14193b45
...
...
@@ -18,6 +18,7 @@ package testclient
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
...
...
@@ -75,3 +76,8 @@ func (c *FakeServices) Watch(label labels.Selector, field fields.Selector, resou
c
.
Fake
.
Invokes
(
NewWatchAction
(
"services"
,
c
.
Namespace
,
label
,
field
,
resourceVersion
),
nil
)
return
c
.
Fake
.
Watch
,
nil
}
func
(
c
*
FakeServices
)
ProxyGet
(
name
,
path
string
,
params
map
[
string
]
string
)
unversioned
.
ResponseWrapper
{
c
.
Fake
.
Invokes
(
NewProxyGetAction
(
"services"
,
c
.
Namespace
,
name
,
path
,
params
),
nil
)
return
nil
}
pkg/controller/autoscaler/horizontalpodautoscaler_controller.go
View file @
14193b45
...
...
@@ -40,7 +40,7 @@ const (
)
type
HorizontalPodAutoscalerController
struct
{
client
*
client
.
Client
client
client
.
Interface
expClient
client
.
ExperimentalInterface
}
...
...
@@ -71,8 +71,7 @@ var heapsterQueryStart, _ = time.ParseDuration("-5m")
var
downscaleForbiddenWindow
,
_
=
time
.
ParseDuration
(
"20m"
)
var
upscaleForbiddenWindow
,
_
=
time
.
ParseDuration
(
"3m"
)
func
New
(
client
*
client
.
Client
,
expClient
client
.
ExperimentalInterface
)
*
HorizontalPodAutoscalerController
{
//TODO: switch to client.Interface
func
New
(
client
client
.
Interface
,
expClient
client
.
ExperimentalInterface
)
*
HorizontalPodAutoscalerController
{
return
&
HorizontalPodAutoscalerController
{
client
:
client
,
expClient
:
expClient
,
...
...
@@ -126,16 +125,9 @@ func (a *HorizontalPodAutoscalerController) reconcileAutoscalers() error {
strings
.
Join
(
podNames
,
","
),
metricSpec
.
name
)
resultRaw
,
err
:=
a
.
client
.
Get
()
.
Prefix
(
"proxy"
)
.
Resource
(
"services"
)
.
Namespace
(
heapsterNamespace
)
.
Name
(
heapsterService
)
.
Suffix
(
metricPath
)
.
Param
(
"start"
,
startTime
.
Format
(
time
.
RFC3339
))
.
Do
()
.
Raw
()
resultRaw
,
err
:=
a
.
client
.
Services
(
heapsterNamespace
)
.
ProxyGet
(
heapsterService
,
metricPath
,
map
[
string
]
string
{
"start"
:
startTime
.
Format
(
time
.
RFC3339
)})
.
DoRaw
()
if
err
!=
nil
{
glog
.
Warningf
(
"Failed to get pods metrics for %s: %v"
,
reference
,
err
)
...
...
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