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
a6145fc1
Commit
a6145fc1
authored
Oct 22, 2014
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1950 from ddysher/client-minion-interface
Add create/delete minion to client interface.
parents
cefbf272
1a8016fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
8 deletions
+69
-8
client.go
pkg/client/client.go
+25
-8
client_test.go
pkg/client/client_test.go
+34
-0
fake.go
pkg/client/fake.go
+10
-0
No files found.
pkg/client/client.go
View file @
a6145fc1
...
...
@@ -87,7 +87,9 @@ type VersionInterface interface {
}
type
MinionInterface
interface
{
CreateMinion
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
ListMinions
()
(
*
api
.
MinionList
,
error
)
DeleteMinion
(
id
string
)
error
}
// APIStatus is exposed by errors that can be converted to an api.Status object
...
...
@@ -262,12 +264,14 @@ func (c *Client) WatchEndpoints(ctx api.Context, label, field labels.Selector, r
Watch
()
}
// CreateEndpoints creates a new endpoint.
func
(
c
*
Client
)
CreateEndpoints
(
ctx
api
.
Context
,
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
{
result
:=
&
api
.
Endpoints
{}
err
:=
c
.
Post
()
.
Namespace
(
api
.
Namespace
(
ctx
))
.
Path
(
"endpoints"
)
.
Body
(
endpoints
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
// UpdateEndpoints updates an existing endpoint.
func
(
c
*
Client
)
UpdateEndpoints
(
ctx
api
.
Context
,
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
{
result
:=
&
api
.
Endpoints
{}
if
len
(
endpoints
.
ResourceVersion
)
==
0
{
...
...
@@ -297,17 +301,30 @@ func (c *Client) ServerVersion() (*version.Info, error) {
return
&
info
,
nil
}
// CreateMinion creates a new minion.
func
(
c
*
Client
)
CreateMinion
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
{
result
:=
&
api
.
Minion
{}
err
:=
c
.
Post
()
.
Path
(
"minions"
)
.
Body
(
minion
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
// ListMinions lists all the minions in the cluster.
func
(
c
*
Client
)
ListMinions
()
(
result
*
api
.
MinionList
,
err
error
)
{
result
=
&
api
.
MinionList
{}
err
=
c
.
Get
()
.
Path
(
"minions"
)
.
Do
()
.
Into
(
result
)
return
func
(
c
*
Client
)
ListMinions
()
(
*
api
.
MinionList
,
error
)
{
result
:
=
&
api
.
MinionList
{}
err
:
=
c
.
Get
()
.
Path
(
"minions"
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
func
(
c
*
Client
)
GetMinion
(
id
string
)
(
result
*
api
.
Minion
,
err
error
)
{
result
=
&
api
.
Minion
{}
err
=
c
.
Get
()
.
Path
(
"minions"
)
.
Path
(
id
)
.
Do
()
.
Into
(
result
)
return
// GetMinion returns information about a particular minion.
func
(
c
*
Client
)
GetMinion
(
id
string
)
(
*
api
.
Minion
,
error
)
{
result
:=
&
api
.
Minion
{}
err
:=
c
.
Get
()
.
Path
(
"minions"
)
.
Path
(
id
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
// DeleteMinion deletes an existing minion.
func
(
c
*
Client
)
DeleteMinion
(
id
string
)
error
{
return
c
.
Delete
()
.
Path
(
"minions"
)
.
Path
(
id
)
.
Do
()
.
Error
()
}
// CreateEvent makes a new event. Returns the copy of the event the server returns, or an error.
...
...
pkg/client/client_test.go
View file @
a6145fc1
...
...
@@ -28,6 +28,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
...
...
@@ -544,3 +545,36 @@ func TestListMinions(t *testing.T) {
response
,
err
:=
c
.
Setup
()
.
ListMinions
()
c
.
Validate
(
t
,
response
,
err
)
}
func
TestCreateMinion
(
t
*
testing
.
T
)
{
requestMinion
:=
&
api
.
Minion
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"minion-1"
,
},
HostIP
:
"123.321.456.654"
,
NodeResources
:
api
.
NodeResources
{
Capacity
:
api
.
ResourceList
{
resources
.
CPU
:
util
.
NewIntOrStringFromInt
(
1000
),
resources
.
Memory
:
util
.
NewIntOrStringFromInt
(
1024
*
1024
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"POST"
,
Path
:
"/minions"
,
Body
:
requestMinion
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
requestMinion
,
},
}
receivedMinion
,
err
:=
c
.
Setup
()
.
CreateMinion
(
requestMinion
)
c
.
Validate
(
t
,
receivedMinion
,
err
)
}
func
TestDeleteMinion
(
t
*
testing
.
T
)
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"DELETE"
,
Path
:
"/minions/foo"
},
Response
:
Response
{
StatusCode
:
200
},
}
err
:=
c
.
Setup
()
.
DeleteMinion
(
"foo"
)
c
.
Validate
(
t
,
nil
,
err
)
}
pkg/client/fake.go
View file @
a6145fc1
...
...
@@ -154,6 +154,16 @@ func (c *Fake) ListMinions() (*api.MinionList, error) {
return
&
c
.
Minions
,
nil
}
func
(
c
*
Fake
)
CreateMinion
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
{
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"create-minion"
,
Value
:
minion
})
return
&
api
.
Minion
{},
nil
}
func
(
c
*
Fake
)
DeleteMinion
(
id
string
)
error
{
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"delete-minion"
,
Value
:
id
})
return
nil
}
// CreateEvent makes a new event. Returns the copy of the event the server returns, or an error.
func
(
c
*
Fake
)
CreateEvent
(
event
*
api
.
Event
)
(
*
api
.
Event
,
error
)
{
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"get-event"
,
Value
:
event
.
ID
})
...
...
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