Switch to github.com/golang/dep for vendoring
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
d6ab91be27
commit
8e5b17cf13
15431 changed files with 3971413 additions and 8881 deletions
40
vendor/k8s.io/kubernetes/pkg/kubectl/metricsutil/BUILD
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/pkg/kubectl/metricsutil/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"metrics_client.go",
|
||||
"metrics_printer.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/resource:go_default_library",
|
||||
"//pkg/api/validation:go_default_library",
|
||||
"//pkg/client/clientset_generated/internalclientset/typed/core/internalversion:go_default_library",
|
||||
"//pkg/kubectl:go_default_library",
|
||||
"//vendor:k8s.io/apimachinery/pkg/labels",
|
||||
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
||||
"//vendor:k8s.io/heapster/metrics/apis/metrics/v1alpha1",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
167
vendor/k8s.io/kubernetes/pkg/kubectl/metricsutil/metrics_client.go
generated
vendored
Normal file
167
vendor/k8s.io/kubernetes/pkg/kubectl/metricsutil/metrics_client.go
generated
vendored
Normal file
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
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 metricsutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
metricsapi "k8s.io/heapster/metrics/apis/metrics/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultHeapsterNamespace = "kube-system"
|
||||
DefaultHeapsterScheme = "http"
|
||||
DefaultHeapsterService = "heapster"
|
||||
DefaultHeapsterPort = "" // use the first exposed port on the service
|
||||
)
|
||||
|
||||
var (
|
||||
prefix = "/apis"
|
||||
groupVersion = fmt.Sprintf("%s/%s", metricsGv.Group, metricsGv.Version)
|
||||
metricsRoot = fmt.Sprintf("%s/%s", prefix, groupVersion)
|
||||
|
||||
// TODO: get this from metrics api once it's finished
|
||||
metricsGv = schema.GroupVersion{Group: "metrics", Version: "v1alpha1"}
|
||||
)
|
||||
|
||||
type HeapsterMetricsClient struct {
|
||||
SVCClient coreclient.ServicesGetter
|
||||
HeapsterNamespace string
|
||||
HeapsterScheme string
|
||||
HeapsterService string
|
||||
HeapsterPort string
|
||||
}
|
||||
|
||||
func NewHeapsterMetricsClient(svcClient coreclient.ServicesGetter, namespace, scheme, service, port string) *HeapsterMetricsClient {
|
||||
return &HeapsterMetricsClient{
|
||||
SVCClient: svcClient,
|
||||
HeapsterNamespace: namespace,
|
||||
HeapsterScheme: scheme,
|
||||
HeapsterService: service,
|
||||
HeapsterPort: port,
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultHeapsterMetricsClient(svcClient coreclient.ServicesGetter) *HeapsterMetricsClient {
|
||||
return NewHeapsterMetricsClient(svcClient, DefaultHeapsterNamespace, DefaultHeapsterScheme, DefaultHeapsterService, DefaultHeapsterPort)
|
||||
}
|
||||
|
||||
func podMetricsUrl(namespace string, name string) (string, error) {
|
||||
if namespace == api.NamespaceAll {
|
||||
return fmt.Sprintf("%s/pods", metricsRoot), nil
|
||||
}
|
||||
errs := validation.ValidateNamespaceName(namespace, false)
|
||||
if len(errs) > 0 {
|
||||
message := fmt.Sprintf("invalid namespace: %s - %v", namespace, errs)
|
||||
return "", errors.New(message)
|
||||
}
|
||||
if len(name) > 0 {
|
||||
errs = validation.ValidatePodName(name, false)
|
||||
if len(errs) > 0 {
|
||||
message := fmt.Sprintf("invalid pod name: %s - %v", name, errs)
|
||||
return "", errors.New(message)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s/namespaces/%s/pods/%s", metricsRoot, namespace, name), nil
|
||||
}
|
||||
|
||||
func nodeMetricsUrl(name string) (string, error) {
|
||||
if len(name) > 0 {
|
||||
errs := validation.ValidateNodeName(name, false)
|
||||
if len(errs) > 0 {
|
||||
message := fmt.Sprintf("invalid node name: %s - %v", name, errs)
|
||||
return "", errors.New(message)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s/nodes/%s", metricsRoot, name), nil
|
||||
}
|
||||
|
||||
func (cli *HeapsterMetricsClient) GetNodeMetrics(nodeName string, selector labels.Selector) ([]metricsapi.NodeMetrics, error) {
|
||||
params := map[string]string{"labelSelector": selector.String()}
|
||||
path, err := nodeMetricsUrl(nodeName)
|
||||
if err != nil {
|
||||
return []metricsapi.NodeMetrics{}, err
|
||||
}
|
||||
resultRaw, err := GetHeapsterMetrics(cli, path, params)
|
||||
if err != nil {
|
||||
return []metricsapi.NodeMetrics{}, err
|
||||
}
|
||||
metrics := make([]metricsapi.NodeMetrics, 0)
|
||||
if len(nodeName) == 0 {
|
||||
metricsList := metricsapi.NodeMetricsList{}
|
||||
err = json.Unmarshal(resultRaw, &metricsList)
|
||||
if err != nil {
|
||||
return []metricsapi.NodeMetrics{}, fmt.Errorf("failed to unmarshall heapster response: %v", err)
|
||||
}
|
||||
metrics = append(metrics, metricsList.Items...)
|
||||
} else {
|
||||
var singleMetric metricsapi.NodeMetrics
|
||||
err = json.Unmarshal(resultRaw, &singleMetric)
|
||||
if err != nil {
|
||||
return []metricsapi.NodeMetrics{}, fmt.Errorf("failed to unmarshall heapster response: %v", err)
|
||||
}
|
||||
metrics = append(metrics, singleMetric)
|
||||
}
|
||||
return metrics, nil
|
||||
}
|
||||
|
||||
func (cli *HeapsterMetricsClient) GetPodMetrics(namespace string, podName string, allNamespaces bool, selector labels.Selector) ([]metricsapi.PodMetrics, error) {
|
||||
if allNamespaces {
|
||||
namespace = api.NamespaceAll
|
||||
}
|
||||
path, err := podMetricsUrl(namespace, podName)
|
||||
if err != nil {
|
||||
return []metricsapi.PodMetrics{}, err
|
||||
}
|
||||
|
||||
params := map[string]string{"labelSelector": selector.String()}
|
||||
allMetrics := make([]metricsapi.PodMetrics, 0)
|
||||
|
||||
resultRaw, err := GetHeapsterMetrics(cli, path, params)
|
||||
if err != nil {
|
||||
return []metricsapi.PodMetrics{}, err
|
||||
}
|
||||
if len(podName) == 0 {
|
||||
metrics := metricsapi.PodMetricsList{}
|
||||
err = json.Unmarshal(resultRaw, &metrics)
|
||||
if err != nil {
|
||||
return []metricsapi.PodMetrics{}, fmt.Errorf("failed to unmarshall heapster response: %v", err)
|
||||
}
|
||||
allMetrics = append(allMetrics, metrics.Items...)
|
||||
} else {
|
||||
var singleMetric metricsapi.PodMetrics
|
||||
err = json.Unmarshal(resultRaw, &singleMetric)
|
||||
if err != nil {
|
||||
return []metricsapi.PodMetrics{}, fmt.Errorf("failed to unmarshall heapster response: %v", err)
|
||||
}
|
||||
allMetrics = append(allMetrics, singleMetric)
|
||||
}
|
||||
return allMetrics, nil
|
||||
}
|
||||
|
||||
func GetHeapsterMetrics(cli *HeapsterMetricsClient, path string, params map[string]string) ([]byte, error) {
|
||||
return cli.SVCClient.Services(cli.HeapsterNamespace).
|
||||
ProxyGet(cli.HeapsterScheme, cli.HeapsterService, cli.HeapsterPort, path, params).
|
||||
DoRaw()
|
||||
}
|
185
vendor/k8s.io/kubernetes/pkg/kubectl/metricsutil/metrics_printer.go
generated
vendored
Normal file
185
vendor/k8s.io/kubernetes/pkg/kubectl/metricsutil/metrics_printer.go
generated
vendored
Normal file
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
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 metricsutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
metricsapi "k8s.io/heapster/metrics/apis/metrics/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
)
|
||||
|
||||
var (
|
||||
MeasuredResources = []api.ResourceName{
|
||||
api.ResourceCPU,
|
||||
api.ResourceMemory,
|
||||
}
|
||||
NodeColumns = []string{"NAME", "CPU(cores)", "CPU%", "MEMORY(bytes)", "MEMORY%"}
|
||||
PodColumns = []string{"NAME", "CPU(cores)", "MEMORY(bytes)"}
|
||||
NamespaceColumn = "NAMESPACE"
|
||||
PodColumn = "POD"
|
||||
)
|
||||
|
||||
type ResourceMetricsInfo struct {
|
||||
Name string
|
||||
Metrics api.ResourceList
|
||||
Available api.ResourceList
|
||||
}
|
||||
|
||||
type TopCmdPrinter struct {
|
||||
out io.Writer
|
||||
}
|
||||
|
||||
func NewTopCmdPrinter(out io.Writer) *TopCmdPrinter {
|
||||
return &TopCmdPrinter{out: out}
|
||||
}
|
||||
|
||||
func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics, availableResources map[string]api.ResourceList) error {
|
||||
if len(metrics) == 0 {
|
||||
return nil
|
||||
}
|
||||
w := kubectl.GetNewTabWriter(printer.out)
|
||||
defer w.Flush()
|
||||
|
||||
printColumnNames(w, NodeColumns)
|
||||
var usage api.ResourceList
|
||||
for _, m := range metrics {
|
||||
err := api.Scheme.Convert(&m.Usage, &usage, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printMetricsLine(w, &ResourceMetricsInfo{
|
||||
Name: m.Name,
|
||||
Metrics: usage,
|
||||
Available: availableResources[m.Name],
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (printer *TopCmdPrinter) PrintPodMetrics(metrics []metricsapi.PodMetrics, printContainers bool, withNamespace bool) error {
|
||||
if len(metrics) == 0 {
|
||||
return nil
|
||||
}
|
||||
w := kubectl.GetNewTabWriter(printer.out)
|
||||
defer w.Flush()
|
||||
|
||||
if withNamespace {
|
||||
printValue(w, NamespaceColumn)
|
||||
}
|
||||
if printContainers {
|
||||
printValue(w, PodColumn)
|
||||
}
|
||||
printColumnNames(w, PodColumns)
|
||||
for _, m := range metrics {
|
||||
err := printSinglePodMetrics(w, &m, printContainers, withNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printColumnNames(out io.Writer, names []string) {
|
||||
for _, name := range names {
|
||||
printValue(out, name)
|
||||
}
|
||||
fmt.Fprint(out, "\n")
|
||||
}
|
||||
|
||||
func printSinglePodMetrics(out io.Writer, m *metricsapi.PodMetrics, printContainersOnly bool, withNamespace bool) error {
|
||||
containers := make(map[string]api.ResourceList)
|
||||
podMetrics := make(api.ResourceList)
|
||||
for _, res := range MeasuredResources {
|
||||
podMetrics[res], _ = resource.ParseQuantity("0")
|
||||
}
|
||||
|
||||
for _, c := range m.Containers {
|
||||
var usage api.ResourceList
|
||||
err := api.Scheme.Convert(&c.Usage, &usage, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
containers[c.Name] = usage
|
||||
if !printContainersOnly {
|
||||
for _, res := range MeasuredResources {
|
||||
quantity := podMetrics[res]
|
||||
quantity.Add(usage[res])
|
||||
podMetrics[res] = quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
if printContainersOnly {
|
||||
for contName := range containers {
|
||||
if withNamespace {
|
||||
printValue(out, m.Namespace)
|
||||
}
|
||||
printValue(out, m.Name)
|
||||
printMetricsLine(out, &ResourceMetricsInfo{
|
||||
Name: contName,
|
||||
Metrics: containers[contName],
|
||||
Available: api.ResourceList{},
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if withNamespace {
|
||||
printValue(out, m.Namespace)
|
||||
}
|
||||
printMetricsLine(out, &ResourceMetricsInfo{
|
||||
Name: m.Name,
|
||||
Metrics: podMetrics,
|
||||
Available: api.ResourceList{},
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printMetricsLine(out io.Writer, metrics *ResourceMetricsInfo) {
|
||||
printValue(out, metrics.Name)
|
||||
printAllResourceUsages(out, metrics)
|
||||
fmt.Fprint(out, "\n")
|
||||
}
|
||||
|
||||
func printValue(out io.Writer, value interface{}) {
|
||||
fmt.Fprintf(out, "%v\t", value)
|
||||
}
|
||||
|
||||
func printAllResourceUsages(out io.Writer, metrics *ResourceMetricsInfo) {
|
||||
for _, res := range MeasuredResources {
|
||||
quantity := metrics.Metrics[res]
|
||||
printSingleResourceUsage(out, res, quantity)
|
||||
fmt.Fprint(out, "\t")
|
||||
if available, found := metrics.Available[res]; found {
|
||||
fraction := float64(quantity.MilliValue()) / float64(available.MilliValue()) * 100
|
||||
fmt.Fprintf(out, "%d%%\t", int64(fraction))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printSingleResourceUsage(out io.Writer, resourceType api.ResourceName, quantity resource.Quantity) {
|
||||
switch resourceType {
|
||||
case api.ResourceCPU:
|
||||
fmt.Fprintf(out, "%vm", quantity.MilliValue())
|
||||
case api.ResourceMemory:
|
||||
fmt.Fprintf(out, "%vMi", quantity.Value()/(1024*1024))
|
||||
default:
|
||||
fmt.Fprintf(out, "%v", quantity.Value())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue