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
771c5389
Commit
771c5389
authored
Dec 12, 2014
by
Brendan Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2864 from deads2k/deads-tighten-validation-on-bad-gets
tighten validation for client resource gets
parents
592095c7
fa900e5d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
13 deletions
+101
-13
client_test.go
pkg/client/client_test.go
+55
-0
endpoints.go
pkg/client/endpoints.go
+8
-3
events.go
pkg/client/events.go
+8
-3
minions.go
pkg/client/minions.go
+15
-7
pods.go
pkg/client/pods.go
+5
-0
replication_controllers.go
pkg/client/replication_controllers.go
+5
-0
services.go
pkg/client/services.go
+5
-0
No files found.
pkg/client/client_test.go
View file @
771c5389
...
@@ -38,6 +38,7 @@ import (
...
@@ -38,6 +38,7 @@ import (
// TODO: Move this to a common place, it's needed in multiple tests.
// TODO: Move this to a common place, it's needed in multiple tests.
const
apiPath
=
"/api/v1beta1"
const
apiPath
=
"/api/v1beta1"
const
nameRequiredError
=
"name is required parameter to Get"
type
testRequest
struct
{
type
testRequest
struct
{
Method
string
Method
string
...
@@ -255,6 +256,17 @@ func TestGetPod(t *testing.T) {
...
@@ -255,6 +256,17 @@ func TestGetPod(t *testing.T) {
c
.
Validate
(
t
,
receivedPod
,
err
)
c
.
Validate
(
t
,
receivedPod
,
err
)
}
}
func
TestGetPodWithNoName
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Error
:
true
}
receivedPod
,
err
:=
c
.
Setup
()
.
Pods
(
ns
)
.
Get
(
""
)
if
(
err
!=
nil
)
&&
(
err
.
Error
()
!=
nameRequiredError
)
{
t
.
Errorf
(
"Expected error: %v, but got %v"
,
nameRequiredError
,
err
)
}
c
.
Validate
(
t
,
receivedPod
,
err
)
}
func
TestDeletePod
(
t
*
testing
.
T
)
{
func
TestDeletePod
(
t
*
testing
.
T
)
{
c
:=
&
testClient
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"DELETE"
,
Path
:
"/pods/foo"
},
Request
:
testRequest
{
Method
:
"DELETE"
,
Path
:
"/pods/foo"
},
...
@@ -361,6 +373,17 @@ func TestGetController(t *testing.T) {
...
@@ -361,6 +373,17 @@ func TestGetController(t *testing.T) {
c
.
Validate
(
t
,
receivedController
,
err
)
c
.
Validate
(
t
,
receivedController
,
err
)
}
}
func
TestGetControllerWithNoName
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Error
:
true
}
receivedPod
,
err
:=
c
.
Setup
()
.
ReplicationControllers
(
ns
)
.
Get
(
""
)
if
(
err
!=
nil
)
&&
(
err
.
Error
()
!=
nameRequiredError
)
{
t
.
Errorf
(
"Expected error: %v, but got %v"
,
nameRequiredError
,
err
)
}
c
.
Validate
(
t
,
receivedPod
,
err
)
}
func
TestUpdateController
(
t
*
testing
.
T
)
{
func
TestUpdateController
(
t
*
testing
.
T
)
{
requestController
:=
&
api
.
ReplicationController
{
requestController
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
},
...
@@ -502,6 +525,17 @@ func TestGetService(t *testing.T) {
...
@@ -502,6 +525,17 @@ func TestGetService(t *testing.T) {
c
.
Validate
(
t
,
response
,
err
)
c
.
Validate
(
t
,
response
,
err
)
}
}
func
TestGetServiceWithNoName
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Error
:
true
}
receivedPod
,
err
:=
c
.
Setup
()
.
Services
(
ns
)
.
Get
(
""
)
if
(
err
!=
nil
)
&&
(
err
.
Error
()
!=
nameRequiredError
)
{
t
.
Errorf
(
"Expected error: %v, but got %v"
,
nameRequiredError
,
err
)
}
c
.
Validate
(
t
,
receivedPod
,
err
)
}
func
TestCreateService
(
t
*
testing
.
T
)
{
func
TestCreateService
(
t
*
testing
.
T
)
{
c
:=
&
testClient
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"POST"
,
Path
:
"/services"
,
Body
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"service-1"
}}},
Request
:
testRequest
{
Method
:
"POST"
,
Path
:
"/services"
,
Body
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"service-1"
}}},
...
@@ -557,6 +591,17 @@ func TestGetEndpoints(t *testing.T) {
...
@@ -557,6 +591,17 @@ func TestGetEndpoints(t *testing.T) {
c
.
Validate
(
t
,
response
,
err
)
c
.
Validate
(
t
,
response
,
err
)
}
}
func
TestGetEndpointWithNoName
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Error
:
true
}
receivedPod
,
err
:=
c
.
Setup
()
.
Endpoints
(
ns
)
.
Get
(
""
)
if
(
err
!=
nil
)
&&
(
err
.
Error
()
!=
nameRequiredError
)
{
t
.
Errorf
(
"Expected error: %v, but got %v"
,
nameRequiredError
,
err
)
}
c
.
Validate
(
t
,
receivedPod
,
err
)
}
func
TestGetServerVersion
(
t
*
testing
.
T
)
{
func
TestGetServerVersion
(
t
*
testing
.
T
)
{
expect
:=
version
.
Info
{
expect
:=
version
.
Info
{
Major
:
"foo"
,
Major
:
"foo"
,
...
@@ -625,6 +670,16 @@ func TestGetMinion(t *testing.T) {
...
@@ -625,6 +670,16 @@ func TestGetMinion(t *testing.T) {
c
.
Validate
(
t
,
response
,
err
)
c
.
Validate
(
t
,
response
,
err
)
}
}
func
TestGetMinionWithNoName
(
t
*
testing
.
T
)
{
c
:=
&
testClient
{
Error
:
true
}
receivedPod
,
err
:=
c
.
Setup
()
.
Nodes
()
.
Get
(
""
)
if
(
err
!=
nil
)
&&
(
err
.
Error
()
!=
nameRequiredError
)
{
t
.
Errorf
(
"Expected error: %v, but got %v"
,
nameRequiredError
,
err
)
}
c
.
Validate
(
t
,
receivedPod
,
err
)
}
func
TestCreateMinion
(
t
*
testing
.
T
)
{
func
TestCreateMinion
(
t
*
testing
.
T
)
{
requestMinion
:=
&
api
.
Node
{
requestMinion
:=
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
...
...
pkg/client/endpoints.go
View file @
771c5389
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
client
package
client
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -33,7 +34,7 @@ type EndpointsNamespacer interface {
...
@@ -33,7 +34,7 @@ type EndpointsNamespacer interface {
type
EndpointsInterface
interface
{
type
EndpointsInterface
interface
{
Create
(
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
Create
(
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
List
(
selector
labels
.
Selector
)
(
*
api
.
EndpointsList
,
error
)
List
(
selector
labels
.
Selector
)
(
*
api
.
EndpointsList
,
error
)
Get
(
id
string
)
(
*
api
.
Endpoints
,
error
)
Get
(
name
string
)
(
*
api
.
Endpoints
,
error
)
Update
(
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
Update
(
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
Watch
(
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
Watch
(
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
}
}
...
@@ -64,9 +65,13 @@ func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, e
...
@@ -64,9 +65,13 @@ func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, e
}
}
// Get returns information about the endpoints for a particular service.
// Get returns information about the endpoints for a particular service.
func
(
c
*
endpoints
)
Get
(
id
string
)
(
result
*
api
.
Endpoints
,
err
error
)
{
func
(
c
*
endpoints
)
Get
(
name
string
)
(
result
*
api
.
Endpoints
,
err
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
=
&
api
.
Endpoints
{}
result
=
&
api
.
Endpoints
{}
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"endpoints"
)
.
Path
(
id
)
.
Do
()
.
Into
(
result
)
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"endpoints"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
return
return
}
}
...
...
pkg/client/events.go
View file @
771c5389
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
client
package
client
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -34,7 +35,7 @@ type EventNamespacer interface {
...
@@ -34,7 +35,7 @@ type EventNamespacer interface {
type
EventInterface
interface
{
type
EventInterface
interface
{
Create
(
event
*
api
.
Event
)
(
*
api
.
Event
,
error
)
Create
(
event
*
api
.
Event
)
(
*
api
.
Event
,
error
)
List
(
label
,
field
labels
.
Selector
)
(
*
api
.
EventList
,
error
)
List
(
label
,
field
labels
.
Selector
)
(
*
api
.
EventList
,
error
)
Get
(
id
string
)
(
*
api
.
Event
,
error
)
Get
(
name
string
)
(
*
api
.
Event
,
error
)
Watch
(
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
Watch
(
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
// Search finds events about the specified object
// Search finds events about the specified object
Search
(
objOrRef
runtime
.
Object
)
(
*
api
.
EventList
,
error
)
Search
(
objOrRef
runtime
.
Object
)
(
*
api
.
EventList
,
error
)
...
@@ -86,11 +87,15 @@ func (e *events) List(label, field labels.Selector) (*api.EventList, error) {
...
@@ -86,11 +87,15 @@ func (e *events) List(label, field labels.Selector) (*api.EventList, error) {
}
}
// Get returns the given event, or an error.
// Get returns the given event, or an error.
func
(
e
*
events
)
Get
(
id
string
)
(
*
api
.
Event
,
error
)
{
func
(
e
*
events
)
Get
(
name
string
)
(
*
api
.
Event
,
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
:=
&
api
.
Event
{}
result
:=
&
api
.
Event
{}
err
:=
e
.
client
.
Get
()
.
err
:=
e
.
client
.
Get
()
.
Path
(
"events"
)
.
Path
(
"events"
)
.
Path
(
id
)
.
Path
(
name
)
.
Namespace
(
e
.
namespace
)
.
Namespace
(
e
.
namespace
)
.
Do
()
.
Do
()
.
Into
(
result
)
Into
(
result
)
...
...
pkg/client/minions.go
View file @
771c5389
...
@@ -16,17 +16,21 @@ limitations under the License.
...
@@ -16,17 +16,21 @@ limitations under the License.
package
client
package
client
import
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
import
(
"errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
type
NodesInterface
interface
{
type
NodesInterface
interface
{
Nodes
()
NodeInterface
Nodes
()
NodeInterface
}
}
type
NodeInterface
interface
{
type
NodeInterface
interface
{
Get
(
id
string
)
(
result
*
api
.
Node
,
err
error
)
Get
(
name
string
)
(
result
*
api
.
Node
,
err
error
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
List
()
(
*
api
.
NodeList
,
error
)
List
()
(
*
api
.
NodeList
,
error
)
Delete
(
id
string
)
error
Delete
(
name
string
)
error
}
}
// nodes implements NodesInterface
// nodes implements NodesInterface
...
@@ -63,13 +67,17 @@ func (c *nodes) List() (*api.NodeList, error) {
...
@@ -63,13 +67,17 @@ func (c *nodes) List() (*api.NodeList, error) {
}
}
// Get gets an existing minion
// Get gets an existing minion
func
(
c
*
nodes
)
Get
(
id
string
)
(
*
api
.
Node
,
error
)
{
func
(
c
*
nodes
)
Get
(
name
string
)
(
*
api
.
Node
,
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
:=
&
api
.
Node
{}
result
:=
&
api
.
Node
{}
err
:=
c
.
r
.
Get
()
.
Path
(
c
.
resourceName
())
.
Path
(
id
)
.
Do
()
.
Into
(
result
)
err
:=
c
.
r
.
Get
()
.
Path
(
c
.
resourceName
())
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
return
result
,
err
return
result
,
err
}
}
// Delete deletes an existing minion.
// Delete deletes an existing minion.
func
(
c
*
nodes
)
Delete
(
id
string
)
error
{
func
(
c
*
nodes
)
Delete
(
name
string
)
error
{
return
c
.
r
.
Delete
()
.
Path
(
c
.
resourceName
())
.
Path
(
id
)
.
Do
()
.
Error
()
return
c
.
r
.
Delete
()
.
Path
(
c
.
resourceName
())
.
Path
(
name
)
.
Do
()
.
Error
()
}
}
pkg/client/pods.go
View file @
771c5389
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
client
package
client
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -60,6 +61,10 @@ func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
...
@@ -60,6 +61,10 @@ func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
// GetPod takes the name of the pod, and returns the corresponding Pod object, and an error if it occurs
// GetPod takes the name of the pod, and returns the corresponding Pod object, and an error if it occurs
func
(
c
*
pods
)
Get
(
name
string
)
(
result
*
api
.
Pod
,
err
error
)
{
func
(
c
*
pods
)
Get
(
name
string
)
(
result
*
api
.
Pod
,
err
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
=
&
api
.
Pod
{}
result
=
&
api
.
Pod
{}
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"pods"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"pods"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
return
return
...
...
pkg/client/replication_controllers.go
View file @
771c5389
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
client
package
client
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -59,6 +60,10 @@ func (c *replicationControllers) List(selector labels.Selector) (result *api.Rep
...
@@ -59,6 +60,10 @@ func (c *replicationControllers) List(selector labels.Selector) (result *api.Rep
// Get returns information about a particular replication controller.
// Get returns information about a particular replication controller.
func
(
c
*
replicationControllers
)
Get
(
name
string
)
(
result
*
api
.
ReplicationController
,
err
error
)
{
func
(
c
*
replicationControllers
)
Get
(
name
string
)
(
result
*
api
.
ReplicationController
,
err
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
=
&
api
.
ReplicationController
{}
result
=
&
api
.
ReplicationController
{}
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"replicationControllers"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"replicationControllers"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
return
return
...
...
pkg/client/services.go
View file @
771c5389
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
client
package
client
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -59,6 +60,10 @@ func (c *services) List(selector labels.Selector) (result *api.ServiceList, err
...
@@ -59,6 +60,10 @@ func (c *services) List(selector labels.Selector) (result *api.ServiceList, err
// Get returns information about a particular service.
// Get returns information about a particular service.
func
(
c
*
services
)
Get
(
name
string
)
(
result
*
api
.
Service
,
err
error
)
{
func
(
c
*
services
)
Get
(
name
string
)
(
result
*
api
.
Service
,
err
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
=
&
api
.
Service
{}
result
=
&
api
.
Service
{}
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"services"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Path
(
"services"
)
.
Path
(
name
)
.
Do
()
.
Into
(
result
)
return
return
...
...
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