Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/authorization/registry/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand Down Expand Up @@ -103,6 +104,10 @@ func (r *Etcd) DeletePolicy(ctx kapi.Context, name string) error {
return r.policyRegistry.Delete(ctx, name)
}

func (r *Etcd) WatchPolicies(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error) {
return r.policyRegistry.Watch(ctx, &generic.SelectionPredicate{label, field, getAttrs}, resourceVersion)
}

func makePolicyBindingListKey(ctx kapi.Context) string {
return kubeetcd.MakeEtcdListKey(ctx, PolicyBindingPath)
}
Expand Down Expand Up @@ -148,3 +153,7 @@ func (r *Etcd) UpdatePolicyBinding(ctx kapi.Context, newPolicyBinding *authoriza
func (r *Etcd) DeletePolicyBinding(ctx kapi.Context, name string) error {
return r.policyBindingRegistry.Delete(ctx, name)
}

func (r *Etcd) WatchPolicyBindings(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error) {
return r.policyBindingRegistry.Watch(ctx, &generic.SelectionPredicate{label, field, getAttrs}, resourceVersion)
}
3 changes: 3 additions & 0 deletions pkg/authorization/registry/policy/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package policy
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand All @@ -19,4 +20,6 @@ type Registry interface {
UpdatePolicy(ctx kapi.Context, policy *authorizationapi.Policy) error
// DeletePolicy deletes a policy.
DeletePolicy(ctx kapi.Context, id string) error
// WatchPolicyBindings watches policyBindings.
WatchPolicies(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error)
}
6 changes: 6 additions & 0 deletions pkg/authorization/registry/policy/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand Down Expand Up @@ -52,3 +53,8 @@ func (r *REST) Delete(ctx kapi.Context, id string) (<-chan apiserver.RESTResult,
return &kapi.Status{Status: kapi.StatusSuccess}, r.registry.DeletePolicy(ctx, id)
}), nil
}

// Watch begins watching for new, changed, or deleted PolicyBindings.
func (r *REST) Watch(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error) {
return r.registry.WatchPolicies(ctx, label, field, resourceVersion)
}
3 changes: 3 additions & 0 deletions pkg/authorization/registry/policybinding/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package policybinding
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand All @@ -19,4 +20,6 @@ type Registry interface {
UpdatePolicyBinding(ctx kapi.Context, policyBinding *authorizationapi.PolicyBinding) error
// DeletePolicyBinding deletes a policyBinding.
DeletePolicyBinding(ctx kapi.Context, id string) error
// WatchPolicyBindings watches policyBindings.
WatchPolicyBindings(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error)
}
6 changes: 6 additions & 0 deletions pkg/authorization/registry/policybinding/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
"github.com/openshift/origin/pkg/authorization/api/validation"
Expand Down Expand Up @@ -84,6 +85,11 @@ func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (<-chan apiserver.RE
}), nil
}

// Watch begins watching for new, changed, or deleted PolicyBindings.
func (r *REST) Watch(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error) {
return r.registry.WatchPolicyBindings(ctx, label, field, resourceVersion)
}

func NewEmptyPolicyBinding(namespace, policyNamespace string) *authorizationapi.PolicyBinding {
policyBinding := &authorizationapi.PolicyBinding{}
policyBinding.Name = policyNamespace
Expand Down
5 changes: 5 additions & 0 deletions pkg/authorization/registry/test/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand Down Expand Up @@ -76,3 +77,7 @@ func (r *PolicyRegistry) DeletePolicy(ctx kapi.Context, id string) error {
r.DeletedPolicyName = id
return r.Err
}

func (r *PolicyRegistry) WatchPolicies(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error) {
return nil, r.Err
}
5 changes: 5 additions & 0 deletions pkg/authorization/registry/test/policybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand Down Expand Up @@ -79,3 +80,7 @@ func (r *PolicyBindingRegistry) DeletePolicyBinding(ctx kapi.Context, id string)
r.DeletedPolicyBindingName = id
return r.Err
}

func (r *PolicyBindingRegistry) WatchPolicyBindings(ctx kapi.Context, label, field klabels.Selector, resourceVersion string) (watch.Interface, error) {
return nil, r.Err
}
6 changes: 6 additions & 0 deletions pkg/client/fake_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand All @@ -24,3 +25,8 @@ func (c *FakePolicies) Delete(name string) error {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-policy", Value: name})
return nil
}

func (c *FakePolicies) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-policy"})
return nil, nil
}
6 changes: 6 additions & 0 deletions pkg/client/fake_policybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand Down Expand Up @@ -29,3 +30,8 @@ func (c *FakePolicyBindings) Delete(name string) error {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-policyBinding", Value: name})
return nil
}

func (c *FakePolicyBindings) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-policyBinding"})
return nil, nil
}
7 changes: 7 additions & 0 deletions pkg/client/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand All @@ -16,6 +17,7 @@ type PolicyInterface interface {
List(label, field labels.Selector) (*authorizationapi.PolicyList, error)
Get(name string) (*authorizationapi.Policy, error)
Delete(name string) error
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
}

// policies implements PoliciesNamespacer interface
Expand Down Expand Up @@ -51,3 +53,8 @@ func (c *policies) Delete(name string) (err error) {
err = c.r.Delete().Namespace(c.ns).Resource("policies").Name(name).Do().Error()
return
}

// Watch returns a watch.Interface that watches the requested policies
func (c *policies) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().Prefix("watch").Namespace(c.ns).Resource("policies").Param("resourceVersion", resourceVersion).SelectorParam("labels", label).SelectorParam("fields", field).Watch()
}
7 changes: 7 additions & 0 deletions pkg/client/policybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
Expand All @@ -17,6 +18,7 @@ type PolicyBindingInterface interface {
Get(name string) (*authorizationapi.PolicyBinding, error)
Create(policyBinding *authorizationapi.PolicyBinding) (*authorizationapi.PolicyBinding, error)
Delete(name string) error
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
}

// policyBindings implements PolicyBindingsNamespacer interface
Expand Down Expand Up @@ -59,3 +61,8 @@ func (c *policyBindings) Delete(name string) (err error) {
err = c.r.Delete().Namespace(c.ns).Resource("policyBindings").Name(name).Do().Error()
return
}

// Watch returns a watch.Interface that watches the requested policyBindings
func (c *policyBindings) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().Prefix("watch").Namespace(c.ns).Resource("policyBindings").Param("resourceVersion", resourceVersion).SelectorParam("labels", label).SelectorParam("fields", field).Watch()
}