mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
api
This commit is contained in:
@@ -35,6 +35,7 @@ type ExtensionsInterface interface {
|
||||
IngressNamespacer
|
||||
ThirdPartyResourceNamespacer
|
||||
ReplicaSetsNamespacer
|
||||
PodSecurityPoliciesInterface
|
||||
}
|
||||
|
||||
// ExtensionsClient is used to interact with experimental Kubernetes features.
|
||||
@@ -44,6 +45,10 @@ type ExtensionsClient struct {
|
||||
*RESTClient
|
||||
}
|
||||
|
||||
func (c *ExtensionsClient) PodSecurityPolicies() PodSecurityPolicyInterface {
|
||||
return newPodSecurityPolicy(c)
|
||||
}
|
||||
|
||||
func (c *ExtensionsClient) HorizontalPodAutoscalers(namespace string) HorizontalPodAutoscalerInterface {
|
||||
return newHorizontalPodAutoscalers(c, namespace)
|
||||
}
|
||||
|
||||
111
pkg/client/unversioned/podsecuritypolicy.go
Normal file
111
pkg/client/unversioned/podsecuritypolicy.go
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors 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 unversioned
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
type PodSecurityPoliciesInterface interface {
|
||||
PodSecurityPolicies() PodSecurityPolicyInterface
|
||||
}
|
||||
|
||||
type PodSecurityPolicyInterface interface {
|
||||
Get(name string) (result *extensions.PodSecurityPolicy, err error)
|
||||
Create(scc *extensions.PodSecurityPolicy) (*extensions.PodSecurityPolicy, error)
|
||||
List(opts api.ListOptions) (*extensions.PodSecurityPolicyList, error)
|
||||
Delete(name string) error
|
||||
Update(*extensions.PodSecurityPolicy) (*extensions.PodSecurityPolicy, error)
|
||||
Watch(opts api.ListOptions) (watch.Interface, error)
|
||||
}
|
||||
|
||||
// podSecurityPolicy implements PodSecurityPolicyInterface
|
||||
type podSecurityPolicy struct {
|
||||
client *ExtensionsClient
|
||||
}
|
||||
|
||||
// newPodSecurityPolicy returns a podSecurityPolicy object.
|
||||
func newPodSecurityPolicy(c *ExtensionsClient) *podSecurityPolicy {
|
||||
return &podSecurityPolicy{c}
|
||||
}
|
||||
|
||||
func (s *podSecurityPolicy) Create(scc *extensions.PodSecurityPolicy) (*extensions.PodSecurityPolicy, error) {
|
||||
result := &extensions.PodSecurityPolicy{}
|
||||
err := s.client.Post().
|
||||
Resource("podsecuritypolicies").
|
||||
Body(scc).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// List returns a list of PodSecurityPolicies matching the selectors.
|
||||
func (s *podSecurityPolicy) List(opts api.ListOptions) (*extensions.PodSecurityPolicyList, error) {
|
||||
result := &extensions.PodSecurityPolicyList{}
|
||||
|
||||
err := s.client.Get().
|
||||
Resource("podsecuritypolicies").
|
||||
VersionedParams(&opts, api.ParameterCodec).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Get returns the given PodSecurityPolicy, or an error.
|
||||
func (s *podSecurityPolicy) Get(name string) (*extensions.PodSecurityPolicy, error) {
|
||||
result := &extensions.PodSecurityPolicy{}
|
||||
err := s.client.Get().
|
||||
Resource("podsecuritypolicies").
|
||||
Name(name).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Watch starts watching for PodSecurityPolicies matching the given selectors.
|
||||
func (s *podSecurityPolicy) Watch(opts api.ListOptions) (watch.Interface, error) {
|
||||
return s.client.Get().
|
||||
Prefix("watch").
|
||||
Resource("podsecuritypolicies").
|
||||
VersionedParams(&opts, api.ParameterCodec).
|
||||
Watch()
|
||||
}
|
||||
|
||||
func (s *podSecurityPolicy) Delete(name string) error {
|
||||
return s.client.Delete().
|
||||
Resource("podsecuritypolicies").
|
||||
Name(name).
|
||||
Do().
|
||||
Error()
|
||||
}
|
||||
|
||||
func (s *podSecurityPolicy) Update(psp *extensions.PodSecurityPolicy) (result *extensions.PodSecurityPolicy, err error) {
|
||||
result = &extensions.PodSecurityPolicy{}
|
||||
err = s.client.Put().
|
||||
Resource("podsecuritypolicies").
|
||||
Name(psp.Name).
|
||||
Body(psp).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
return
|
||||
}
|
||||
138
pkg/client/unversioned/podsecuritypolicy_test.go
Normal file
138
pkg/client/unversioned/podsecuritypolicy_test.go
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors 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 unversioned_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
. "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
|
||||
)
|
||||
|
||||
func TestPodSecurityPolicyCreate(t *testing.T) {
|
||||
ns := api.NamespaceNone
|
||||
scc := &extensions.PodSecurityPolicy{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc",
|
||||
},
|
||||
}
|
||||
|
||||
c := &simple.Client{
|
||||
Request: simple.Request{
|
||||
Method: "POST",
|
||||
Path: testapi.Extensions.ResourcePath(getPSPResourcename(), ns, ""),
|
||||
Query: simple.BuildQueryValues(nil),
|
||||
Body: scc,
|
||||
},
|
||||
Response: simple.Response{StatusCode: 200, Body: scc},
|
||||
}
|
||||
|
||||
response, err := c.Setup(t).PodSecurityPolicies().Create(scc)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestPodSecurityPolicyGet(t *testing.T) {
|
||||
ns := api.NamespaceNone
|
||||
scc := &extensions.PodSecurityPolicy{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc",
|
||||
},
|
||||
}
|
||||
c := &simple.Client{
|
||||
Request: simple.Request{
|
||||
Method: "GET",
|
||||
Path: testapi.Extensions.ResourcePath(getPSPResourcename(), ns, "abc"),
|
||||
Query: simple.BuildQueryValues(nil),
|
||||
Body: nil,
|
||||
},
|
||||
Response: simple.Response{StatusCode: 200, Body: scc},
|
||||
}
|
||||
|
||||
response, err := c.Setup(t).PodSecurityPolicies().Get("abc")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestPodSecurityPolicyList(t *testing.T) {
|
||||
ns := api.NamespaceNone
|
||||
sccList := &extensions.PodSecurityPolicyList{
|
||||
Items: []extensions.PodSecurityPolicy{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
c := &simple.Client{
|
||||
Request: simple.Request{
|
||||
Method: "GET",
|
||||
Path: testapi.Extensions.ResourcePath(getPSPResourcename(), ns, ""),
|
||||
Query: simple.BuildQueryValues(nil),
|
||||
Body: nil,
|
||||
},
|
||||
Response: simple.Response{StatusCode: 200, Body: sccList},
|
||||
}
|
||||
response, err := c.Setup(t).PodSecurityPolicies().List(api.ListOptions{})
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestPodSecurityPolicyUpdate(t *testing.T) {
|
||||
ns := api.NamespaceNone
|
||||
scc := &extensions.PodSecurityPolicy{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc",
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
}
|
||||
c := &simple.Client{
|
||||
Request: simple.Request{Method: "PUT", Path: testapi.Extensions.ResourcePath(getPSPResourcename(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
|
||||
Response: simple.Response{StatusCode: 200, Body: scc},
|
||||
}
|
||||
response, err := c.Setup(t).PodSecurityPolicies().Update(scc)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestPodSecurityPolicyDelete(t *testing.T) {
|
||||
ns := api.NamespaceNone
|
||||
c := &simple.Client{
|
||||
Request: simple.Request{Method: "DELETE", Path: testapi.Extensions.ResourcePath(getPSPResourcename(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
|
||||
Response: simple.Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup(t).PodSecurityPolicies().Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestPodSecurityPolicyWatch(t *testing.T) {
|
||||
c := &simple.Client{
|
||||
Request: simple.Request{
|
||||
Method: "GET",
|
||||
Path: fmt.Sprintf("%s/watch/%s", testapi.Extensions.ResourcePath("", "", ""), getPSPResourcename()),
|
||||
Query: url.Values{"resourceVersion": []string{}}},
|
||||
Response: simple.Response{StatusCode: 200},
|
||||
}
|
||||
_, err := c.Setup(t).PodSecurityPolicies().Watch(api.ListOptions{})
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func getPSPResourcename() string {
|
||||
return "podsecuritypolicies"
|
||||
}
|
||||
73
pkg/client/unversioned/testclient/fake_podsecuritypolicy.go
Normal file
73
pkg/client/unversioned/testclient/fake_podsecuritypolicy.go
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors 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 testclient
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// FakePodSecurityPolicy implements PodSecurityPolicyInterface. Meant to be
|
||||
// embedded into a struct to get a default implementation. This makes faking out just
|
||||
// the method you want to test easier.
|
||||
type FakePodSecurityPolicy struct {
|
||||
Fake *Fake
|
||||
Namespace string
|
||||
}
|
||||
|
||||
func (c *FakePodSecurityPolicy) List(opts api.ListOptions) (*extensions.PodSecurityPolicyList, error) {
|
||||
obj, err := c.Fake.Invokes(NewListAction("podsecuritypolicies", c.Namespace, opts), &extensions.PodSecurityPolicyList{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.(*extensions.PodSecurityPolicyList), err
|
||||
}
|
||||
|
||||
func (c *FakePodSecurityPolicy) Get(name string) (*extensions.PodSecurityPolicy, error) {
|
||||
obj, err := c.Fake.Invokes(NewGetAction("podsecuritypolicies", c.Namespace, name), &extensions.PodSecurityPolicy{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.PodSecurityPolicy), err
|
||||
}
|
||||
|
||||
func (c *FakePodSecurityPolicy) Create(scc *extensions.PodSecurityPolicy) (*extensions.PodSecurityPolicy, error) {
|
||||
obj, err := c.Fake.Invokes(NewCreateAction("podsecuritypolicies", c.Namespace, scc), &extensions.PodSecurityPolicy{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.PodSecurityPolicy), err
|
||||
}
|
||||
|
||||
func (c *FakePodSecurityPolicy) Update(scc *extensions.PodSecurityPolicy) (*extensions.PodSecurityPolicy, error) {
|
||||
obj, err := c.Fake.Invokes(NewUpdateAction("podsecuritypolicies", c.Namespace, scc), &extensions.PodSecurityPolicy{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.PodSecurityPolicy), err
|
||||
}
|
||||
|
||||
func (c *FakePodSecurityPolicy) Delete(name string) error {
|
||||
_, err := c.Fake.Invokes(NewDeleteAction("podsecuritypolicies", c.Namespace, name), &extensions.PodSecurityPolicy{})
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *FakePodSecurityPolicy) Watch(opts api.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.InvokesWatch(NewWatchAction("podsecuritypolicies", c.Namespace, opts))
|
||||
}
|
||||
@@ -230,6 +230,10 @@ func (c *Fake) Nodes() client.NodeInterface {
|
||||
return &FakeNodes{Fake: c}
|
||||
}
|
||||
|
||||
func (c *Fake) PodSecurityPolicies() client.PodSecurityPolicyInterface {
|
||||
return &FakePodSecurityPolicy{Fake: c}
|
||||
}
|
||||
|
||||
func (c *Fake) Events(namespace string) client.EventInterface {
|
||||
return &FakeEvents{Fake: c, Namespace: namespace}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user