mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-22 13:17:07 +00:00
Merge pull request #78176 from yastij/event-expansion-client
add event_expansion for v1beta1 Events Kubernetes-commit: 3978efc2167d9b3bcf266b7c2f3e7fb579f04e20
This commit is contained in:
commit
5ecd7315c7
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -188,11 +188,11 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "67ef80593b24"
|
||||
"Rev": "cf720200d547"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "e59c2fb0a8e5"
|
||||
"Rev": "bff0c42413f8"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/klog",
|
||||
|
8
go.mod
8
go.mod
@ -26,8 +26,8 @@ require (
|
||||
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a
|
||||
golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
|
||||
google.golang.org/appengine v1.5.0 // indirect
|
||||
k8s.io/api v0.0.0-20190528154508-67ef80593b24
|
||||
k8s.io/apimachinery v0.0.0-20190528154326-e59c2fb0a8e5
|
||||
k8s.io/api v0.0.0-20190531132107-cf720200d547
|
||||
k8s.io/apimachinery v0.0.0-20190529005236-bff0c42413f8
|
||||
k8s.io/klog v0.3.1
|
||||
k8s.io/utils v0.0.0-20190221042446-c2654d5206da
|
||||
sigs.k8s.io/yaml v1.1.0
|
||||
@ -37,6 +37,6 @@ replace (
|
||||
golang.org/x/sync => golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
|
||||
golang.org/x/sys => golang.org/x/sys v0.0.0-20190209173611-3b5209105503
|
||||
golang.org/x/tools => golang.org/x/tools v0.0.0-20190313210603-aa82965741a9
|
||||
k8s.io/api => k8s.io/api v0.0.0-20190528154508-67ef80593b24
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190528154326-e59c2fb0a8e5
|
||||
k8s.io/api => k8s.io/api v0.0.0-20190531132107-cf720200d547
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190529005236-bff0c42413f8
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -91,8 +91,8 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
k8s.io/api v0.0.0-20190528154508-67ef80593b24/go.mod h1:aCWu6byTIKt+TeO2ZJ48xnOrYgDq0jqxbxmzfjXbNqw=
|
||||
k8s.io/apimachinery v0.0.0-20190528154326-e59c2fb0a8e5/go.mod h1:I4A+glKBHiTgiEjQiCCQfCAIcIMFGt291SmsvcrFzJA=
|
||||
k8s.io/api v0.0.0-20190531132107-cf720200d547/go.mod h1:QMoKrFuqE2O+M+xCzcomo1EH5b0DgFDaKvisrkBaMfk=
|
||||
k8s.io/apimachinery v0.0.0-20190529005236-bff0c42413f8/go.mod h1:I4A+glKBHiTgiEjQiCCQfCAIcIMFGt291SmsvcrFzJA=
|
||||
k8s.io/klog v0.3.1 h1:RVgyDHY/kFKtLqh67NvEWIgkMneNoIrdkN0CxDSQc68=
|
||||
k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30 h1:TRb4wNWoBVrH9plmkp2q86FIDppkbrEXdXlxU3a3BMI=
|
||||
|
95
kubernetes/typed/events/v1beta1/event_expansion.go
Normal file
95
kubernetes/typed/events/v1beta1/event_expansion.go
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
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 v1beta1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/api/events/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
// The EventExpansion interface allows manually adding extra methods to the EventInterface.
|
||||
// TODO: Add querying functions to the event expansion
|
||||
type EventExpansion interface {
|
||||
// CreateWithEventNamespace is the same as a Create
|
||||
// except that it sends the request to the event.Namespace.
|
||||
CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error)
|
||||
// UpdateWithEventNamespace is the same as a Update
|
||||
// except that it sends the request to the event.Namespace.
|
||||
UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error)
|
||||
// PatchWithEventNamespace is the same as a Update
|
||||
// except that it sends the request to the event.Namespace.
|
||||
PatchWithEventNamespace(event *v1beta1.Event, data []byte) (*v1beta1.Event, error)
|
||||
}
|
||||
|
||||
// CreateWithEventNamespace makes a new event.
|
||||
// Returns the copy of the event the server returns, or an error.
|
||||
// The namespace to create the event within is deduced from the event.
|
||||
// it must either match this event client's namespace, or this event client must
|
||||
// have been created with the "" namespace.
|
||||
func (e *events) CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
if e.ns != "" && event.Namespace != e.ns {
|
||||
return nil, fmt.Errorf("can't create an event with namespace '%v' in namespace '%v'", event.Namespace, e.ns)
|
||||
}
|
||||
result := &v1beta1.Event{}
|
||||
err := e.client.Post().
|
||||
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
|
||||
Resource("events").
|
||||
Body(event).
|
||||
Do().
|
||||
Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// UpdateWithEventNamespace modifies an existing event.
|
||||
// It returns the copy of the event that the server returns, or an error.
|
||||
// The namespace and key to update the event within is deduced from the event.
|
||||
// The namespace must either match this event client's namespace, or this event client must have been
|
||||
// created with the "" namespace.
|
||||
// Update also requires the ResourceVersion to be set in the event object.
|
||||
func (e *events) UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
result := &v1beta1.Event{}
|
||||
err := e.client.Put().
|
||||
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
|
||||
Resource("events").
|
||||
Name(event.Name).
|
||||
Body(event).
|
||||
Do().
|
||||
Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// PatchWithEventNamespace modifies an existing event.
|
||||
// It returns the copy of the event that the server returns, or an error.
|
||||
// The namespace and name of the target event is deduced from the event.
|
||||
// The namespace must either match this event client's namespace, or this event client must
|
||||
// have been created with the "" namespace.
|
||||
func (e *events) PatchWithEventNamespace(event *v1beta1.Event, data []byte) (*v1beta1.Event, error) {
|
||||
if e.ns != "" && event.Namespace != e.ns {
|
||||
return nil, fmt.Errorf("can't patch an event with namespace '%v' in namespace '%v'", event.Namespace, e.ns)
|
||||
}
|
||||
result := &v1beta1.Event{}
|
||||
err := e.client.Patch(types.StrategicMergePatchType).
|
||||
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
|
||||
Resource("events").
|
||||
Name(event.Name).
|
||||
Body(data).
|
||||
Do().
|
||||
Into(result)
|
||||
return result, err
|
||||
}
|
66
kubernetes/typed/events/v1beta1/fake/fake_event_expansion.go
Normal file
66
kubernetes/typed/events/v1beta1/fake/fake_event_expansion.go
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
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 fake
|
||||
|
||||
import (
|
||||
v1beta1 "k8s.io/api/events/v1beta1"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
// CreateWithEventNamespace creats a new event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
action := core.NewRootCreateAction(eventsResource, event)
|
||||
if c.ns != "" {
|
||||
action = core.NewCreateAction(eventsResource, c.ns, event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.(*v1beta1.Event), err
|
||||
}
|
||||
|
||||
// UpdateWithEventNamespace replaces an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
action := core.NewRootUpdateAction(eventsResource, event)
|
||||
if c.ns != "" {
|
||||
action = core.NewUpdateAction(eventsResource, c.ns, event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.(*v1beta1.Event), err
|
||||
}
|
||||
|
||||
// PatchWithEventNamespace patches an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) PatchWithEventNamespace(event *v1beta1.Event, data []byte) (*v1beta1.Event, error) {
|
||||
pt := types.StrategicMergePatchType
|
||||
action := core.NewRootPatchAction(eventsResource, event.Name, pt, data)
|
||||
if c.ns != "" {
|
||||
action = core.NewPatchAction(eventsResource, c.ns, event.Name, pt, data)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.(*v1beta1.Event), err
|
||||
}
|
@ -17,5 +17,3 @@ limitations under the License.
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v1beta1
|
||||
|
||||
type EventExpansion interface{}
|
||||
|
@ -34,6 +34,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
typedv1beta1 "k8s.io/client-go/kubernetes/typed/events/v1beta1"
|
||||
"k8s.io/client-go/tools/record/util"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
@ -65,6 +66,28 @@ type eventBroadcasterImpl struct {
|
||||
sink EventSink
|
||||
}
|
||||
|
||||
// EventSinkImpl wraps EventInterface to implement EventSink.
|
||||
// TODO: this makes it easier for testing purpose and masks the logic of performing API calls.
|
||||
// Note that rollbacking to raw clientset should also be transparent.
|
||||
type EventSinkImpl struct {
|
||||
Interface typedv1beta1.EventInterface
|
||||
}
|
||||
|
||||
// Create is the same as CreateWithEventNamespace of the EventExpansion
|
||||
func (e *EventSinkImpl) Create(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
return e.Interface.CreateWithEventNamespace(event)
|
||||
}
|
||||
|
||||
// Update is the same as UpdateithEventNamespace of the EventExpansion
|
||||
func (e *EventSinkImpl) Update(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
return e.Interface.UpdateWithEventNamespace(event)
|
||||
}
|
||||
|
||||
// Patch is the same as PatchWithEventNamespace of the EventExpansion
|
||||
func (e *EventSinkImpl) Patch(event *v1beta1.Event, data []byte) (*v1beta1.Event, error) {
|
||||
return e.Interface.PatchWithEventNamespace(event, data)
|
||||
}
|
||||
|
||||
// NewBroadcaster Creates a new event broadcaster.
|
||||
func NewBroadcaster(sink EventSink) EventBroadcaster {
|
||||
return newBroadcaster(sink, defaultSleepDuration)
|
||||
|
Loading…
Reference in New Issue
Block a user