mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	switch kubelet to use external (client-go) object references for events
This commit is contained in:
		| @@ -125,6 +125,7 @@ go_library( | ||||
|         "//vendor:k8s.io/apiserver/pkg/util/feature", | ||||
|         "//vendor:k8s.io/client-go/kubernetes", | ||||
|         "//vendor:k8s.io/client-go/kubernetes/typed/core/v1", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|         "//vendor:k8s.io/client-go/tools/cache", | ||||
|         "//vendor:k8s.io/client-go/tools/record", | ||||
|         "//vendor:k8s.io/client-go/util/clock", | ||||
| @@ -208,6 +209,7 @@ go_test( | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/strategicpatch", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/uuid", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/wait", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|         "//vendor:k8s.io/client-go/testing", | ||||
|         "//vendor:k8s.io/client-go/tools/record", | ||||
|         "//vendor:k8s.io/client-go/util/clock", | ||||
|   | ||||
| @@ -29,6 +29,7 @@ go_library( | ||||
|         "//pkg/api:go_default_library", | ||||
|         "//pkg/api/v1:go_default_library", | ||||
|         "//pkg/kubelet/api/v1alpha1/runtime:go_default_library", | ||||
|         "//pkg/kubelet/events:go_default_library", | ||||
|         "//pkg/kubelet/util/format:go_default_library", | ||||
|         "//pkg/kubelet/util/ioutils:go_default_library", | ||||
|         "//pkg/util/hash:go_default_library", | ||||
| @@ -42,6 +43,7 @@ go_library( | ||||
|         "//vendor:k8s.io/apimachinery/pkg/types", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/errors", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/runtime", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|         "//vendor:k8s.io/client-go/tools/record", | ||||
|         "//vendor:k8s.io/client-go/util/flowcontrol", | ||||
|     ], | ||||
|   | ||||
| @@ -29,9 +29,11 @@ import ( | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	runtimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" | ||||
| 	"k8s.io/kubernetes/pkg/kubelet/events" | ||||
| 	"k8s.io/kubernetes/pkg/kubelet/util/format" | ||||
| 	"k8s.io/kubernetes/pkg/kubelet/util/ioutils" | ||||
| 	hashutil "k8s.io/kubernetes/pkg/util/hash" | ||||
| @@ -146,15 +148,21 @@ type innerEventRecorder struct { | ||||
| 	recorder record.EventRecorder | ||||
| } | ||||
|  | ||||
| func (irecorder *innerEventRecorder) shouldRecordEvent(object runtime.Object) (*v1.ObjectReference, bool) { | ||||
| func (irecorder *innerEventRecorder) shouldRecordEvent(object runtime.Object) (*clientv1.ObjectReference, bool) { | ||||
| 	if object == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	if ref, ok := object.(*v1.ObjectReference); ok { | ||||
| 	if ref, ok := object.(*clientv1.ObjectReference); ok { | ||||
| 		if !strings.HasPrefix(ref.FieldPath, ImplicitContainerPrefix) { | ||||
| 			return ref, true | ||||
| 		} | ||||
| 	} | ||||
| 	// just in case we miss a spot, be sure that we still log something | ||||
| 	if ref, ok := object.(*v1.ObjectReference); ok { | ||||
| 		if !strings.HasPrefix(ref.FieldPath, ImplicitContainerPrefix) { | ||||
| 			return events.ToObjectReference(ref), true | ||||
| 		} | ||||
| 	} | ||||
| 	return nil, false | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -11,6 +11,10 @@ go_library( | ||||
|     name = "go_default_library", | ||||
|     srcs = ["event.go"], | ||||
|     tags = ["automanaged"], | ||||
|     deps = [ | ||||
|         "//pkg/api/v1:go_default_library", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|     ], | ||||
| ) | ||||
|  | ||||
| filegroup( | ||||
|   | ||||
| @@ -16,6 +16,11 @@ limitations under the License. | ||||
|  | ||||
| package events | ||||
|  | ||||
| import ( | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	// Container event reason list | ||||
| 	CreatedContainer        = "Created" | ||||
| @@ -76,3 +81,19 @@ const ( | ||||
| 	FailedPreStopHook     = "FailedPreStopHook" | ||||
| 	UnfinishedPreStopHook = "UnfinishedPreStopHook" | ||||
| ) | ||||
|  | ||||
| // ToObjectReference takes an old style object reference and converts it to a client-go one | ||||
| func ToObjectReference(ref *v1.ObjectReference) *clientv1.ObjectReference { | ||||
| 	if ref == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return &clientv1.ObjectReference{ | ||||
| 		Kind:            ref.Kind, | ||||
| 		Namespace:       ref.Namespace, | ||||
| 		Name:            ref.Name, | ||||
| 		UID:             ref.UID, | ||||
| 		APIVersion:      ref.APIVersion, | ||||
| 		ResourceVersion: ref.ResourceVersion, | ||||
| 		FieldPath:       ref.FieldPath, | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -36,6 +36,7 @@ go_library( | ||||
|         "//vendor:k8s.io/apimachinery/pkg/apis/meta/v1", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/sets", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/wait", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|         "//vendor:k8s.io/client-go/tools/record", | ||||
|         "//vendor:k8s.io/client-go/util/clock", | ||||
|     ], | ||||
| @@ -59,6 +60,7 @@ go_test( | ||||
|         "//vendor:k8s.io/apimachinery/pkg/api/resource", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/apis/meta/v1", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/types", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|         "//vendor:k8s.io/client-go/tools/record", | ||||
|         "//vendor:k8s.io/client-go/util/clock", | ||||
|     ], | ||||
|   | ||||
| @@ -25,6 +25,7 @@ import ( | ||||
| 	"github.com/golang/glog" | ||||
| 	"k8s.io/apimachinery/pkg/api/resource" | ||||
| 	"k8s.io/apimachinery/pkg/util/wait" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/client-go/util/clock" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| @@ -54,7 +55,7 @@ type managerImpl struct { | ||||
| 	// captures when a node condition was last observed based on a threshold being met | ||||
| 	nodeConditionsLastObservedAt nodeConditionsObservedAt | ||||
| 	// nodeRef is a reference to the node | ||||
| 	nodeRef *v1.ObjectReference | ||||
| 	nodeRef *clientv1.ObjectReference | ||||
| 	// used to record events about the node | ||||
| 	recorder record.EventRecorder | ||||
| 	// used to measure usage stats on system | ||||
| @@ -83,7 +84,7 @@ func NewManager( | ||||
| 	killPodFunc KillPodFunc, | ||||
| 	imageGC ImageGC, | ||||
| 	recorder record.EventRecorder, | ||||
| 	nodeRef *v1.ObjectReference, | ||||
| 	nodeRef *clientv1.ObjectReference, | ||||
| 	clock clock.Clock) (Manager, lifecycle.PodAdmitHandler) { | ||||
| 	manager := &managerImpl{ | ||||
| 		clock:           clock, | ||||
|   | ||||
| @@ -22,6 +22,7 @@ import ( | ||||
|  | ||||
| 	"k8s.io/apimachinery/pkg/api/resource" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/client-go/util/clock" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| @@ -172,7 +173,7 @@ func TestMemoryPressure(t *testing.T) { | ||||
| 	podKiller := &mockPodKiller{} | ||||
| 	diskInfoProvider := &mockDiskInfoProvider{dedicatedImageFs: false} | ||||
| 	imageGC := &mockImageGC{freed: int64(0), err: nil} | ||||
| 	nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
| 	nodeRef := &clientv1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
|  | ||||
| 	config := Config{ | ||||
| 		MaxPodGracePeriodSeconds: 5, | ||||
| @@ -392,7 +393,7 @@ func TestDiskPressureNodeFs(t *testing.T) { | ||||
| 	podKiller := &mockPodKiller{} | ||||
| 	diskInfoProvider := &mockDiskInfoProvider{dedicatedImageFs: false} | ||||
| 	imageGC := &mockImageGC{freed: int64(0), err: nil} | ||||
| 	nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
| 	nodeRef := &clientv1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
|  | ||||
| 	config := Config{ | ||||
| 		MaxPodGracePeriodSeconds: 5, | ||||
| @@ -589,7 +590,7 @@ func TestMinReclaim(t *testing.T) { | ||||
| 	podKiller := &mockPodKiller{} | ||||
| 	diskInfoProvider := &mockDiskInfoProvider{dedicatedImageFs: false} | ||||
| 	imageGC := &mockImageGC{freed: int64(0), err: nil} | ||||
| 	nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
| 	nodeRef := &clientv1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
|  | ||||
| 	config := Config{ | ||||
| 		MaxPodGracePeriodSeconds: 5, | ||||
| @@ -728,7 +729,7 @@ func TestNodeReclaimFuncs(t *testing.T) { | ||||
| 	diskInfoProvider := &mockDiskInfoProvider{dedicatedImageFs: false} | ||||
| 	imageGcFree := resource.MustParse("700Mi") | ||||
| 	imageGC := &mockImageGC{freed: imageGcFree.Value(), err: nil} | ||||
| 	nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
| 	nodeRef := &clientv1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
|  | ||||
| 	config := Config{ | ||||
| 		MaxPodGracePeriodSeconds: 5, | ||||
| @@ -920,7 +921,7 @@ func TestInodePressureNodeFsInodes(t *testing.T) { | ||||
| 	podKiller := &mockPodKiller{} | ||||
| 	diskInfoProvider := &mockDiskInfoProvider{dedicatedImageFs: false} | ||||
| 	imageGC := &mockImageGC{freed: int64(0), err: nil} | ||||
| 	nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
| 	nodeRef := &clientv1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""} | ||||
|  | ||||
| 	config := Config{ | ||||
| 		MaxPodGracePeriodSeconds: 5, | ||||
|   | ||||
| @@ -30,6 +30,7 @@ go_library( | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/errors", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/sets", | ||||
|         "//vendor:k8s.io/apimachinery/pkg/util/wait", | ||||
|         "//vendor:k8s.io/client-go/pkg/api/v1", | ||||
|         "//vendor:k8s.io/client-go/tools/record", | ||||
|         "//vendor:k8s.io/client-go/util/flowcontrol", | ||||
|     ], | ||||
|   | ||||
| @@ -27,6 +27,7 @@ import ( | ||||
| 	"k8s.io/apimachinery/pkg/util/errors" | ||||
| 	"k8s.io/apimachinery/pkg/util/sets" | ||||
| 	"k8s.io/apimachinery/pkg/util/wait" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	"k8s.io/kubernetes/pkg/kubelet/cadvisor" | ||||
| @@ -85,7 +86,7 @@ type realImageGCManager struct { | ||||
| 	recorder record.EventRecorder | ||||
|  | ||||
| 	// Reference to this node. | ||||
| 	nodeRef *v1.ObjectReference | ||||
| 	nodeRef *clientv1.ObjectReference | ||||
|  | ||||
| 	// Track initialization | ||||
| 	initialized bool | ||||
| @@ -128,7 +129,7 @@ type imageRecord struct { | ||||
| 	size int64 | ||||
| } | ||||
|  | ||||
| func NewImageGCManager(runtime container.Runtime, cadvisorInterface cadvisor.Interface, recorder record.EventRecorder, nodeRef *v1.ObjectReference, policy ImageGCPolicy) (ImageGCManager, error) { | ||||
| func NewImageGCManager(runtime container.Runtime, cadvisorInterface cadvisor.Interface, recorder record.EventRecorder, nodeRef *clientv1.ObjectReference, policy ImageGCPolicy) (ImageGCManager, error) { | ||||
| 	// Validate policy. | ||||
| 	if policy.HighThresholdPercent < 0 || policy.HighThresholdPercent > 100 { | ||||
| 		return nil, fmt.Errorf("invalid HighThresholdPercent %d, must be in range [0-100]", policy.HighThresholdPercent) | ||||
|   | ||||
| @@ -75,7 +75,7 @@ func shouldPullImage(container *v1.Container, imagePresent bool) bool { | ||||
| // records an event using ref, event msg.  log to glog using prefix, msg, logFn | ||||
| func (m *imageManager) logIt(ref *v1.ObjectReference, eventtype, event, prefix, msg string, logFn func(args ...interface{})) { | ||||
| 	if ref != nil { | ||||
| 		m.recorder.Event(ref, eventtype, event, msg) | ||||
| 		m.recorder.Event(events.ToObjectReference(ref), eventtype, event, msg) | ||||
| 	} else { | ||||
| 		logFn(fmt.Sprint(prefix, " ", msg)) | ||||
| 	} | ||||
|   | ||||
| @@ -44,6 +44,7 @@ import ( | ||||
| 	"k8s.io/apimachinery/pkg/util/wait" | ||||
| 	utilfeature "k8s.io/apiserver/pkg/util/feature" | ||||
| 	v1core "k8s.io/client-go/kubernetes/typed/core/v1" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/cache" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/client-go/util/clock" | ||||
| @@ -401,7 +402,7 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Kub | ||||
| 	// TODO: get the real node object of ourself, | ||||
| 	// and use the real node name and UID. | ||||
| 	// TODO: what is namespace for node? | ||||
| 	nodeRef := &v1.ObjectReference{ | ||||
| 	nodeRef := &clientv1.ObjectReference{ | ||||
| 		Kind:      "Node", | ||||
| 		Name:      string(nodeName), | ||||
| 		UID:       types.UID(nodeName), | ||||
| @@ -923,7 +924,7 @@ type Kubelet struct { | ||||
| 	autoDetectCloudProvider bool | ||||
|  | ||||
| 	// Reference to this node. | ||||
| 	nodeRef *v1.ObjectReference | ||||
| 	nodeRef *clientv1.ObjectReference | ||||
|  | ||||
| 	// Container runtime. | ||||
| 	containerRuntime kubecontainer.Runtime | ||||
|   | ||||
| @@ -34,6 +34,7 @@ import ( | ||||
| 	utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/util/sets" | ||||
| 	"k8s.io/apimachinery/pkg/util/wait" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/client-go/util/clock" | ||||
| 	"k8s.io/client-go/util/flowcontrol" | ||||
| @@ -201,7 +202,7 @@ func newTestKubeletWithImageList( | ||||
| 	kubelet.livenessManager = proberesults.NewManager() | ||||
|  | ||||
| 	kubelet.containerManager = cm.NewStubContainerManager() | ||||
| 	fakeNodeRef := &v1.ObjectReference{ | ||||
| 	fakeNodeRef := &clientv1.ObjectReference{ | ||||
| 		Kind:      "Node", | ||||
| 		Name:      testKubeletHostname, | ||||
| 		UID:       types.UID(testKubeletHostname), | ||||
| @@ -237,7 +238,7 @@ func newTestKubeletWithImageList( | ||||
| 	// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency | ||||
| 	volumeStatsAggPeriod := time.Second * 10 | ||||
| 	kubelet.resourceAnalyzer = stats.NewResourceAnalyzer(kubelet, volumeStatsAggPeriod, kubelet.containerRuntime) | ||||
| 	nodeRef := &v1.ObjectReference{ | ||||
| 	nodeRef := &clientv1.ObjectReference{ | ||||
| 		Kind:      "Node", | ||||
| 		Name:      string(kubelet.nodeName), | ||||
| 		UID:       types.UID(kubelet.nodeName), | ||||
|   | ||||
| @@ -22,8 +22,8 @@ import ( | ||||
| 	cadvisorapi "github.com/google/cadvisor/info/v1" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/util/runtime" | ||||
| 	"k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	"k8s.io/kubernetes/pkg/kubelet/cadvisor" | ||||
| ) | ||||
|  | ||||
|   | ||||
| @@ -19,8 +19,8 @@ package kubelet | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing" | ||||
| ) | ||||
|  | ||||
|   | ||||
| @@ -25,6 +25,7 @@ import ( | ||||
| 	cadvisorapiv2 "github.com/google/cadvisor/info/v2" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	clientv1 "k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/tools/record" | ||||
| 	"k8s.io/client-go/util/clock" | ||||
| 	utiltesting "k8s.io/client-go/util/testing" | ||||
| @@ -114,7 +115,7 @@ func TestRunOnce(t *testing.T) { | ||||
| 	// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency | ||||
| 	volumeStatsAggPeriod := time.Second * 10 | ||||
| 	kb.resourceAnalyzer = stats.NewResourceAnalyzer(kb, volumeStatsAggPeriod, kb.containerRuntime) | ||||
| 	nodeRef := &v1.ObjectReference{ | ||||
| 	nodeRef := &clientv1.ObjectReference{ | ||||
| 		Kind:      "Node", | ||||
| 		Name:      string(kb.nodeName), | ||||
| 		UID:       types.UID(kb.nodeName), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 deads2k
					deads2k