Switch to github.com/golang/dep for vendoring

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2017-01-31 16:45:59 -08:00
parent d6ab91be27
commit 8e5b17cf13
15431 changed files with 3971413 additions and 8881 deletions

50
vendor/k8s.io/kubernetes/pkg/util/procfs/BUILD generated vendored Normal file
View file

@ -0,0 +1,50 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"procfs.go",
"procfs_fake.go",
"procfs_linux.go",
],
tags = ["automanaged"],
deps = [
"//vendor:github.com/golang/glog",
"//vendor:k8s.io/apimachinery/pkg/util/errors",
],
)
go_test(
name = "go_default_test",
srcs = ["procfs_linux_test.go"],
data = [
"example_proc_cgroup",
],
library = ":go_default_library",
tags = [
"automanaged",
],
deps = ["//vendor:github.com/stretchr/testify/assert"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

18
vendor/k8s.io/kubernetes/pkg/util/procfs/doc.go generated vendored Normal file
View file

@ -0,0 +1,18 @@
/*
Copyright 2015 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 procfs implements utility functions relating to the /proc mount.
package procfs // import "k8s.io/kubernetes/pkg/util/procfs"

View file

@ -0,0 +1,10 @@
11:name=systemd:/user/1000.user/c1.session
10:hugetlb:/user/1000.user/c1.session
9:perf_event:/user/1000.user/c1.session
8:blkio:/user/1000.user/c1.session
7:freezer:/user/1000.user/c1.session
6:devices:/user/1000.user/c1.session
5:memory:/user/1000.user/c1.session
4:cpuacct:/user/1000.user/c1.session
3:cpu:/user/1000.user/c1.session
2:cpuset:/

22
vendor/k8s.io/kubernetes/pkg/util/procfs/procfs.go generated vendored Normal file
View file

@ -0,0 +1,22 @@
/*
Copyright 2015 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 procfs
type ProcFSInterface interface {
// GetFullContainerName gets the container name given the root process id of the container.
GetFullContainerName(pid int) (string, error)
}

View file

@ -0,0 +1,30 @@
/*
Copyright 2015 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 procfs
type FakeProcFS struct{}
func NewFakeProcFS() ProcFSInterface {
return &FakeProcFS{}
}
// GetFullContainerName gets the container name given the root process id of the container.
// Eg. If the devices cgroup for the container is stored in /sys/fs/cgroup/devices/docker/nginx,
// return docker/nginx. Assumes that the process is part of exactly one cgroup hierarchy.
func (fakePfs *FakeProcFS) GetFullContainerName(pid int) (string, error) {
return "", nil
}

View file

@ -0,0 +1,151 @@
// +build linux
/*
Copyright 2015 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 procfs
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
"unicode"
"github.com/golang/glog"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
type ProcFS struct{}
func NewProcFS() ProcFSInterface {
return &ProcFS{}
}
func containerNameFromProcCgroup(content string) (string, error) {
lines := strings.Split(content, "\n")
for _, line := range lines {
entries := strings.SplitN(line, ":", 3)
if len(entries) == 3 && entries[1] == "devices" {
return strings.TrimSpace(entries[2]), nil
}
}
return "", fmt.Errorf("could not find devices cgroup location")
}
// getFullContainerName gets the container name given the root process id of the container.
// Eg. If the devices cgroup for the container is stored in /sys/fs/cgroup/devices/docker/nginx,
// return docker/nginx. Assumes that the process is part of exactly one cgroup hierarchy.
func (pfs *ProcFS) GetFullContainerName(pid int) (string, error) {
filePath := path.Join("/proc", strconv.Itoa(pid), "cgroup")
content, err := ioutil.ReadFile(filePath)
if err != nil {
if os.IsNotExist(err) {
return "", os.ErrNotExist
}
return "", err
}
return containerNameFromProcCgroup(string(content))
}
// Find process(es) using a regular expression and send a specified
// signal to each process
func PKill(name string, sig syscall.Signal) error {
if len(name) == 0 {
return fmt.Errorf("name should not be empty")
}
re, err := regexp.Compile(name)
if err != nil {
return err
}
pids := getPids(re)
if len(pids) == 0 {
return fmt.Errorf("unable to fetch pids for process name : %q", name)
}
errList := []error{}
for _, pid := range pids {
if err = syscall.Kill(pid, sig); err != nil {
errList = append(errList, err)
}
}
return utilerrors.NewAggregate(errList)
}
// Find process(es) with a specified name (exact match)
// and return their pid(s)
func PidOf(name string) ([]int, error) {
if len(name) == 0 {
return []int{}, fmt.Errorf("name should not be empty")
}
re, err := regexp.Compile("(^|/)" + name + "$")
if err != nil {
return []int{}, err
}
return getPids(re), nil
}
func getPids(re *regexp.Regexp) []int {
pids := []int{}
filepath.Walk("/proc", func(path string, info os.FileInfo, err error) error {
if err != nil {
// We should continue processing other directories/files
return nil
}
base := filepath.Base(path)
// Traverse only the directories we are interested in
if info.IsDir() && path != "/proc" {
// If the directory is not a number (i.e. not a PID), skip it
if _, err := strconv.Atoi(base); err != nil {
return filepath.SkipDir
}
}
if base != "cmdline" {
return nil
}
cmdline, err := ioutil.ReadFile(path)
if err != nil {
glog.V(4).Infof("Error reading file %s: %+v", path, err)
return nil
}
// The bytes we read have '\0' as a separator for the command line
parts := bytes.SplitN(cmdline, []byte{0}, 2)
if len(parts) == 0 {
return nil
}
// Split the command line itself we are interested in just the first part
exe := strings.FieldsFunc(string(parts[0]), func(c rune) bool {
return unicode.IsSpace(c) || c == ':'
})
if len(exe) == 0 {
return nil
}
// Check if the name of the executable is what we are looking for
if re.MatchString(exe[0]) {
dirname := filepath.Base(filepath.Dir(path))
// Grab the PID from the directory path
pid, _ := strconv.Atoi(dirname)
pids = append(pids, pid)
}
return nil
})
return pids
}

View file

@ -0,0 +1,97 @@
// +build linux
/*
Copyright 2015 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 procfs
import (
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func verifyContainerName(procCgroupText, expectedName string, expectedErr bool, t *testing.T) {
name, err := containerNameFromProcCgroup(procCgroupText)
if expectedErr && err == nil {
t.Errorf("Expected error but did not get error in verifyContainerName")
return
} else if !expectedErr && err != nil {
t.Errorf("Expected no error, but got error %+v in verifyContainerName", err)
return
} else if expectedErr {
return
}
if name != expectedName {
t.Errorf("Expected container name %s but got name %s", expectedName, name)
}
}
func TestContainerNameFromProcCgroup(t *testing.T) {
procCgroupValid := "2:devices:docker/kubelet"
verifyContainerName(procCgroupValid, "docker/kubelet", false, t)
procCgroupEmpty := ""
verifyContainerName(procCgroupEmpty, "", true, t)
content, err := ioutil.ReadFile("example_proc_cgroup")
if err != nil {
t.Errorf("Could not read example /proc cgroup file")
}
verifyContainerName(string(content), "/user/1000.user/c1.session", false, t)
procCgroupNoDevice := "2:freezer:docker/kubelet\n5:cpuacct:pkg/kubectl"
verifyContainerName(procCgroupNoDevice, "", true, t)
procCgroupInvalid := "devices:docker/kubelet\ncpuacct:pkg/kubectl"
verifyContainerName(procCgroupInvalid, "", true, t)
}
func TestPidOf(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skipf("not supported on GOOS=%s", runtime.GOOS)
}
pids, err := PidOf(filepath.Base(os.Args[0]))
assert.Empty(t, err)
assert.NotZero(t, pids)
assert.Contains(t, pids, os.Getpid())
}
func TestPKill(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skipf("not supported on GOOS=%s", runtime.GOOS)
}
sig := syscall.SIGCONT
c := make(chan os.Signal, 1)
signal.Notify(c, sig)
defer signal.Stop(c)
PKill(os.Args[0], sig)
select {
case s := <-c:
if s != sig {
t.Fatalf("signal was %v, want %v", s, sig)
}
case <-time.After(1 * time.Second):
t.Fatalf("timeout waiting for %v", sig)
}
}

View file

@ -0,0 +1,47 @@
// +build !linux
/*
Copyright 2016 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 procfs
import (
"fmt"
"syscall"
)
type ProcFS struct{}
func NewProcFS() ProcFSInterface {
return &ProcFS{}
}
// GetFullContainerName gets the container name given the root process id of the container.
func (pfs *ProcFS) GetFullContainerName(pid int) (string, error) {
return "", fmt.Errorf("GetFullContainerName is unsupported in this build")
}
// Find process(es) using a regular expression and send a specified
// signal to each process
func PKill(name string, sig syscall.Signal) error {
return fmt.Errorf("PKill is unsupported in this build")
}
// Find process(es) with a specified name (exact match)
// and return their pid(s)
func PidOf(name string) ([]int, error) {
return []int{}, fmt.Errorf("PidOf is unsupported in this build")
}