From 5acfb16023869fc6fb9ea33382bf41d5366cd948 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 20 Jul 2017 14:35:05 +0200 Subject: [PATCH] Use Eventfd() from x/sys/unix Use unix.Eventfd() instead of C.eventfd and also use the correct corresponding unix.EFD_CLOEXEC flag. This allows to get rid of cgo. --- pkg/kubelet/eviction/BUILD | 15 +-------------- pkg/kubelet/eviction/threshold_notifier_linux.go | 10 +--------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/pkg/kubelet/eviction/BUILD b/pkg/kubelet/eviction/BUILD index ec9cb61fd77..27639e09415 100644 --- a/pkg/kubelet/eviction/BUILD +++ b/pkg/kubelet/eviction/BUILD @@ -4,23 +4,10 @@ licenses(["notice"]) load( "@io_bazel_rules_go//go:def.bzl", - "cgo_genrule", "go_library", "go_test", ) -cgo_genrule( - name = "cgo_codegen", - srcs = ["threshold_notifier_linux.go"], - clinkopts = [ - "-lz", - "-lm", - "-lpthread", - "-ldl", - ], - tags = ["automanaged"], -) - go_test( name = "go_default_test", srcs = [ @@ -53,9 +40,9 @@ go_library( "doc.go", "eviction_manager.go", "helpers.go", + "threshold_notifier_linux.go", "types.go", ], - library = ":cgo_codegen", tags = ["automanaged"], deps = [ "//pkg/api:go_default_library", diff --git a/pkg/kubelet/eviction/threshold_notifier_linux.go b/pkg/kubelet/eviction/threshold_notifier_linux.go index ef6fb3d2f4d..1709cac8b79 100644 --- a/pkg/kubelet/eviction/threshold_notifier_linux.go +++ b/pkg/kubelet/eviction/threshold_notifier_linux.go @@ -1,5 +1,3 @@ -// +build cgo - /* Copyright 2016 The Kubernetes Authors. @@ -18,11 +16,6 @@ limitations under the License. package eviction -/* -#include -*/ -import "C" - import ( "fmt" @@ -61,11 +54,10 @@ func NewMemCGThresholdNotifier(path, attribute, threshold, description string, h unix.Close(controlfd) } }() - efd, err := C.eventfd(0, C.EFD_CLOEXEC) + eventfd, err := unix.Eventfd(0, unix.EFD_CLOEXEC) if err != nil { return nil, err } - eventfd := int(efd) if eventfd < 0 { err = fmt.Errorf("eventfd call failed") return nil, err