mirror of
https://github.com/rancher/types.git
synced 2025-06-29 06:56:50 +00:00
cluster events
This commit is contained in:
parent
e77815f156
commit
0715c3311e
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
*.swp
|
||||
/.trash-cache
|
||||
/.idea
|
||||
types
|
||||
|
@ -39,6 +39,40 @@ func (in *ComponentStatusList) DeepCopyObject() runtime.Object {
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *EventList) DeepCopyInto(out *EventList) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
out.ListMeta = in.ListMeta
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]core_v1.Event, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EventList.
|
||||
func (in *EventList) DeepCopy() *EventList {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(EventList)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *EventList) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *NamespaceList) DeepCopyInto(out *NamespaceList) {
|
||||
*out = *in
|
||||
|
188
apis/core/v1/zz_generated_event_controller.go
Normal file
188
apis/core/v1/zz_generated_event_controller.go
Normal file
@ -0,0 +1,188 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/rancher/norman/clientbase"
|
||||
"github.com/rancher/norman/controller"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
var (
|
||||
EventGroupVersionKind = schema.GroupVersionKind{
|
||||
Version: "v1",
|
||||
Group: "",
|
||||
Kind: "Event",
|
||||
}
|
||||
EventResource = metav1.APIResource{
|
||||
Name: "events",
|
||||
SingularName: "event",
|
||||
Namespaced: false,
|
||||
Kind: EventGroupVersionKind.Kind,
|
||||
}
|
||||
)
|
||||
|
||||
type EventList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitempty"`
|
||||
Items []v1.Event
|
||||
}
|
||||
|
||||
type EventHandlerFunc func(key string, obj *v1.Event) error
|
||||
|
||||
type EventLister interface {
|
||||
List(namespace string, selector labels.Selector) (ret []*v1.Event, err error)
|
||||
Get(namespace, name string) (*v1.Event, error)
|
||||
}
|
||||
|
||||
type EventController interface {
|
||||
Informer() cache.SharedIndexInformer
|
||||
Lister() EventLister
|
||||
AddHandler(handler EventHandlerFunc)
|
||||
Enqueue(namespace, name string)
|
||||
Sync(ctx context.Context) error
|
||||
Start(ctx context.Context, threadiness int) error
|
||||
}
|
||||
|
||||
type EventInterface interface {
|
||||
ObjectClient() *clientbase.ObjectClient
|
||||
Create(*v1.Event) (*v1.Event, error)
|
||||
Get(name string, opts metav1.GetOptions) (*v1.Event, error)
|
||||
Update(*v1.Event) (*v1.Event, error)
|
||||
Delete(name string, options *metav1.DeleteOptions) error
|
||||
List(opts metav1.ListOptions) (*EventList, error)
|
||||
Watch(opts metav1.ListOptions) (watch.Interface, error)
|
||||
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
|
||||
Controller() EventController
|
||||
}
|
||||
|
||||
type eventLister struct {
|
||||
controller *eventController
|
||||
}
|
||||
|
||||
func (l *eventLister) List(namespace string, selector labels.Selector) (ret []*v1.Event, err error) {
|
||||
err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) {
|
||||
ret = append(ret, obj.(*v1.Event))
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (l *eventLister) Get(namespace, name string) (*v1.Event, error) {
|
||||
obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(namespace + "/" + name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.NewNotFound(schema.GroupResource{
|
||||
Group: EventGroupVersionKind.Group,
|
||||
Resource: "event",
|
||||
}, name)
|
||||
}
|
||||
return obj.(*v1.Event), nil
|
||||
}
|
||||
|
||||
type eventController struct {
|
||||
controller.GenericController
|
||||
}
|
||||
|
||||
func (c *eventController) Lister() EventLister {
|
||||
return &eventLister{
|
||||
controller: c,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *eventController) AddHandler(handler EventHandlerFunc) {
|
||||
c.GenericController.AddHandler(func(key string) error {
|
||||
obj, exists, err := c.Informer().GetStore().GetByKey(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
return handler(key, nil)
|
||||
}
|
||||
return handler(key, obj.(*v1.Event))
|
||||
})
|
||||
}
|
||||
|
||||
type eventFactory struct {
|
||||
}
|
||||
|
||||
func (c eventFactory) Object() runtime.Object {
|
||||
return &v1.Event{}
|
||||
}
|
||||
|
||||
func (c eventFactory) List() runtime.Object {
|
||||
return &EventList{}
|
||||
}
|
||||
|
||||
func (s *eventClient) Controller() EventController {
|
||||
s.client.Lock()
|
||||
defer s.client.Unlock()
|
||||
|
||||
c, ok := s.client.eventControllers[s.ns]
|
||||
if ok {
|
||||
return c
|
||||
}
|
||||
|
||||
genericController := controller.NewGenericController(EventGroupVersionKind.Kind+"Controller",
|
||||
s.objectClient)
|
||||
|
||||
c = &eventController{
|
||||
GenericController: genericController,
|
||||
}
|
||||
|
||||
s.client.eventControllers[s.ns] = c
|
||||
s.client.starters = append(s.client.starters, c)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type eventClient struct {
|
||||
client *Client
|
||||
ns string
|
||||
objectClient *clientbase.ObjectClient
|
||||
controller EventController
|
||||
}
|
||||
|
||||
func (s *eventClient) ObjectClient() *clientbase.ObjectClient {
|
||||
return s.objectClient
|
||||
}
|
||||
|
||||
func (s *eventClient) Create(o *v1.Event) (*v1.Event, error) {
|
||||
obj, err := s.objectClient.Create(o)
|
||||
return obj.(*v1.Event), err
|
||||
}
|
||||
|
||||
func (s *eventClient) Get(name string, opts metav1.GetOptions) (*v1.Event, error) {
|
||||
obj, err := s.objectClient.Get(name, opts)
|
||||
return obj.(*v1.Event), err
|
||||
}
|
||||
|
||||
func (s *eventClient) Update(o *v1.Event) (*v1.Event, error) {
|
||||
obj, err := s.objectClient.Update(o.Name, o)
|
||||
return obj.(*v1.Event), err
|
||||
}
|
||||
|
||||
func (s *eventClient) Delete(name string, options *metav1.DeleteOptions) error {
|
||||
return s.objectClient.Delete(name, options)
|
||||
}
|
||||
|
||||
func (s *eventClient) List(opts metav1.ListOptions) (*EventList, error) {
|
||||
obj, err := s.objectClient.List(opts)
|
||||
return obj.(*EventList), err
|
||||
}
|
||||
|
||||
func (s *eventClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
return s.objectClient.Watch(opts)
|
||||
}
|
||||
|
||||
func (s *eventClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
|
||||
}
|
40
apis/core/v1/zz_generated_event_lifecycle_adapter.go
Normal file
40
apis/core/v1/zz_generated_event_lifecycle_adapter.go
Normal file
@ -0,0 +1,40 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/rancher/norman/lifecycle"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
type EventLifecycle interface {
|
||||
Create(obj *v1.Event) error
|
||||
Remove(obj *v1.Event) error
|
||||
Updated(obj *v1.Event) error
|
||||
}
|
||||
|
||||
type eventLifecycleAdapter struct {
|
||||
lifecycle EventLifecycle
|
||||
}
|
||||
|
||||
func (w *eventLifecycleAdapter) Create(obj runtime.Object) error {
|
||||
return w.lifecycle.Create(obj.(*v1.Event))
|
||||
}
|
||||
|
||||
func (w *eventLifecycleAdapter) Finalize(obj runtime.Object) error {
|
||||
return w.lifecycle.Remove(obj.(*v1.Event))
|
||||
}
|
||||
|
||||
func (w *eventLifecycleAdapter) Updated(obj runtime.Object) error {
|
||||
return w.lifecycle.Updated(obj.(*v1.Event))
|
||||
}
|
||||
|
||||
func NewEventLifecycleAdapter(name string, client EventInterface, l EventLifecycle) EventHandlerFunc {
|
||||
adapter := &eventLifecycleAdapter{lifecycle: l}
|
||||
syncFn := lifecycle.NewObjectLifecycleAdapter(name, adapter, client.ObjectClient())
|
||||
return func(key string, obj *v1.Event) error {
|
||||
if obj == nil {
|
||||
return syncFn(key, nil)
|
||||
}
|
||||
return syncFn(key, obj)
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ type Interface interface {
|
||||
NodesGetter
|
||||
ComponentStatusesGetter
|
||||
NamespacesGetter
|
||||
EventsGetter
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
@ -29,6 +30,7 @@ type Client struct {
|
||||
nodeControllers map[string]NodeController
|
||||
componentStatusControllers map[string]ComponentStatusController
|
||||
namespaceControllers map[string]NamespaceController
|
||||
eventControllers map[string]EventController
|
||||
}
|
||||
|
||||
func NewForConfig(config rest.Config) (Interface, error) {
|
||||
@ -49,6 +51,7 @@ func NewForConfig(config rest.Config) (Interface, error) {
|
||||
nodeControllers: map[string]NodeController{},
|
||||
componentStatusControllers: map[string]ComponentStatusController{},
|
||||
namespaceControllers: map[string]NamespaceController{},
|
||||
eventControllers: map[string]EventController{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -115,3 +118,16 @@ func (c *Client) Namespaces(namespace string) NamespaceInterface {
|
||||
objectClient: objectClient,
|
||||
}
|
||||
}
|
||||
|
||||
type EventsGetter interface {
|
||||
Events(namespace string) EventInterface
|
||||
}
|
||||
|
||||
func (c *Client) Events(namespace string) EventInterface {
|
||||
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &EventResource, EventGroupVersionKind, eventFactory{})
|
||||
return &eventClient{
|
||||
ns: namespace,
|
||||
client: c,
|
||||
objectClient: objectClient,
|
||||
}
|
||||
}
|
||||
|
@ -126,3 +126,8 @@ type GoogleKubernetesEngineConfig struct {
|
||||
type AzureKubernetesServiceConfig struct {
|
||||
//TBD
|
||||
}
|
||||
|
||||
type ClusterEvent struct {
|
||||
v1.Event
|
||||
ClusterName string
|
||||
}
|
||||
|
@ -261,6 +261,32 @@ func (in *ClusterCondition) DeepCopy() *ClusterCondition {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClusterEvent) DeepCopyInto(out *ClusterEvent) {
|
||||
*out = *in
|
||||
in.Event.DeepCopyInto(&out.Event)
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterEvent.
|
||||
func (in *ClusterEvent) DeepCopy() *ClusterEvent {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ClusterEvent)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *ClusterEvent) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClusterList) DeepCopyInto(out *ClusterList) {
|
||||
*out = *in
|
||||
|
2
main.go
2
main.go
@ -19,7 +19,7 @@ func main() {
|
||||
generator.Generate(clusterSchema.Schemas)
|
||||
generator.Generate(projectSchema.Schemas)
|
||||
// Group by API group
|
||||
generator.GenerateNativeTypes(v1.Pod{}, v1.Node{}, v1.ComponentStatus{}, v1.Namespace{})
|
||||
generator.GenerateNativeTypes(v1.Pod{}, v1.Node{}, v1.ComponentStatus{}, v1.Namespace{}, v1.Event{})
|
||||
generator.GenerateNativeTypes(v1beta2.Deployment{})
|
||||
generator.GenerateNativeTypes(rbacv1.RoleBinding{}, rbacv1.ClusterRoleBinding{}, rbacv1.ClusterRole{})
|
||||
generator.GenerateNativeTypes(extv1beta1.PodSecurityPolicy{})
|
||||
|
Loading…
Reference in New Issue
Block a user