Update to latest cadvisor - cleanup mesos/rkt
Change-Id: Ib5ae0cb13b93f8c87bb74e3ba33040df5f3d6a6f
This commit is contained in:
11
vendor/github.com/google/cadvisor/utils/cloudinfo/BUILD
generated
vendored
11
vendor/github.com/google/cadvisor/utils/cloudinfo/BUILD
generated
vendored
@@ -2,20 +2,11 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"aws.go",
|
||||
"azure.go",
|
||||
"cloudinfo.go",
|
||||
"gce.go",
|
||||
],
|
||||
srcs = ["cloudinfo.go"],
|
||||
importmap = "k8s.io/kubernetes/vendor/github.com/google/cadvisor/utils/cloudinfo",
|
||||
importpath = "github.com/google/cadvisor/utils/cloudinfo",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/cloud.google.com/go/compute/metadata:go_default_library",
|
||||
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
|
||||
"//vendor/github.com/aws/aws-sdk-go/aws/ec2metadata:go_default_library",
|
||||
"//vendor/github.com/aws/aws-sdk-go/aws/session:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
],
|
||||
|
||||
69
vendor/github.com/google/cadvisor/utils/cloudinfo/aws.go
generated
vendored
69
vendor/github.com/google/cadvisor/utils/cloudinfo/aws.go
generated
vendored
@@ -1,69 +0,0 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// 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 cloudinfo
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/ec2metadata"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
info "github.com/google/cadvisor/info/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
ProductVerFileName = "/sys/class/dmi/id/product_version"
|
||||
BiosVerFileName = "/sys/class/dmi/id/bios_vendor"
|
||||
Amazon = "amazon"
|
||||
)
|
||||
|
||||
func onAWS() bool {
|
||||
var dataProduct []byte
|
||||
var dataBios []byte
|
||||
if _, err := os.Stat(ProductVerFileName); err == nil {
|
||||
dataProduct, err = ioutil.ReadFile(ProductVerFileName)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(BiosVerFileName); err == nil {
|
||||
dataBios, err = ioutil.ReadFile(BiosVerFileName)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Contains(string(dataProduct), Amazon) || strings.Contains(strings.ToLower(string(dataBios)), Amazon)
|
||||
}
|
||||
|
||||
func getAwsMetadata(name string) string {
|
||||
client := ec2metadata.New(session.New(&aws.Config{}))
|
||||
data, err := client.GetMetadata(name)
|
||||
if err != nil {
|
||||
return info.UnknownInstance
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func getAwsInstanceType() info.InstanceType {
|
||||
return info.InstanceType(getAwsMetadata("instance-type"))
|
||||
}
|
||||
|
||||
func getAwsInstanceID() info.InstanceID {
|
||||
return info.InstanceID(getAwsMetadata("instance-id"))
|
||||
}
|
||||
48
vendor/github.com/google/cadvisor/utils/cloudinfo/azure.go
generated
vendored
48
vendor/github.com/google/cadvisor/utils/cloudinfo/azure.go
generated
vendored
@@ -1,48 +0,0 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// 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 cloudinfo
|
||||
|
||||
import (
|
||||
info "github.com/google/cadvisor/info/v1"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
SysVendorFileName = "/sys/class/dmi/id/sys_vendor"
|
||||
BiosUUIDFileName = "/sys/class/dmi/id/product_uuid"
|
||||
MicrosoftCorporation = "Microsoft Corporation"
|
||||
)
|
||||
|
||||
func onAzure() bool {
|
||||
data, err := ioutil.ReadFile(SysVendorFileName)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(string(data), MicrosoftCorporation)
|
||||
}
|
||||
|
||||
// TODO: Implement method.
|
||||
func getAzureInstanceType() info.InstanceType {
|
||||
return info.UnknownInstance
|
||||
}
|
||||
|
||||
func getAzureInstanceID() info.InstanceID {
|
||||
data, err := ioutil.ReadFile(BiosUUIDFileName)
|
||||
if err != nil {
|
||||
return info.UnNamedInstance
|
||||
}
|
||||
return info.InstanceID(strings.TrimSuffix(string(data), "\n"))
|
||||
}
|
||||
91
vendor/github.com/google/cadvisor/utils/cloudinfo/cloudinfo.go
generated
vendored
91
vendor/github.com/google/cadvisor/utils/cloudinfo/cloudinfo.go
generated
vendored
@@ -18,6 +18,7 @@ package cloudinfo
|
||||
|
||||
import (
|
||||
info "github.com/google/cadvisor/info/v1"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
type CloudInfo interface {
|
||||
@@ -26,6 +27,29 @@ type CloudInfo interface {
|
||||
GetInstanceID() info.InstanceID
|
||||
}
|
||||
|
||||
// CloudProvider is an abstraction for providing cloud-specific information.
|
||||
type CloudProvider interface {
|
||||
// IsActiveProvider determines whether this is the cloud provider operating
|
||||
// this instance.
|
||||
IsActiveProvider() bool
|
||||
// GetInstanceType gets the type of instance this process is running on.
|
||||
// The behavior is undefined if this is not the active provider.
|
||||
GetInstanceType() info.InstanceType
|
||||
// GetInstanceType gets the ID of the instance this process is running on.
|
||||
// The behavior is undefined if this is not the active provider.
|
||||
GetInstanceID() info.InstanceID
|
||||
}
|
||||
|
||||
var providers = map[info.CloudProvider]CloudProvider{}
|
||||
|
||||
// RegisterCloudProvider registers the given cloud provider
|
||||
func RegisterCloudProvider(name info.CloudProvider, provider CloudProvider) {
|
||||
if _, alreadyRegistered := providers[name]; alreadyRegistered {
|
||||
klog.Warningf("Duplicate registration of CloudProvider %s", name)
|
||||
}
|
||||
providers[name] = provider
|
||||
}
|
||||
|
||||
type realCloudInfo struct {
|
||||
cloudProvider info.CloudProvider
|
||||
instanceType info.InstanceType
|
||||
@@ -33,13 +57,21 @@ type realCloudInfo struct {
|
||||
}
|
||||
|
||||
func NewRealCloudInfo() CloudInfo {
|
||||
cloudProvider := detectCloudProvider()
|
||||
instanceType := detectInstanceType(cloudProvider)
|
||||
instanceID := detectInstanceID(cloudProvider)
|
||||
for name, provider := range providers {
|
||||
if provider.IsActiveProvider() {
|
||||
return &realCloudInfo{
|
||||
cloudProvider: name,
|
||||
instanceType: provider.GetInstanceType(),
|
||||
instanceID: provider.GetInstanceID(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No registered active provider.
|
||||
return &realCloudInfo{
|
||||
cloudProvider: cloudProvider,
|
||||
instanceType: instanceType,
|
||||
instanceID: instanceID,
|
||||
cloudProvider: info.UnknownProvider,
|
||||
instanceType: info.UnknownInstance,
|
||||
instanceID: info.UnNamedInstance,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,50 +86,3 @@ func (self *realCloudInfo) GetInstanceType() info.InstanceType {
|
||||
func (self *realCloudInfo) GetInstanceID() info.InstanceID {
|
||||
return self.instanceID
|
||||
}
|
||||
|
||||
func detectCloudProvider() info.CloudProvider {
|
||||
switch {
|
||||
case onGCE():
|
||||
return info.GCE
|
||||
case onAWS():
|
||||
return info.AWS
|
||||
case onAzure():
|
||||
return info.Azure
|
||||
case onBaremetal():
|
||||
return info.Baremetal
|
||||
}
|
||||
return info.UnknownProvider
|
||||
}
|
||||
|
||||
func detectInstanceType(cloudProvider info.CloudProvider) info.InstanceType {
|
||||
switch cloudProvider {
|
||||
case info.GCE:
|
||||
return getGceInstanceType()
|
||||
case info.AWS:
|
||||
return getAwsInstanceType()
|
||||
case info.Azure:
|
||||
return getAzureInstanceType()
|
||||
case info.Baremetal:
|
||||
return info.NoInstance
|
||||
}
|
||||
return info.UnknownInstance
|
||||
}
|
||||
|
||||
func detectInstanceID(cloudProvider info.CloudProvider) info.InstanceID {
|
||||
switch cloudProvider {
|
||||
case info.GCE:
|
||||
return getGceInstanceID()
|
||||
case info.AWS:
|
||||
return getAwsInstanceID()
|
||||
case info.Azure:
|
||||
return getAzureInstanceID()
|
||||
case info.Baremetal:
|
||||
return info.UnNamedInstance
|
||||
}
|
||||
return info.UnNamedInstance
|
||||
}
|
||||
|
||||
// TODO: Implement method.
|
||||
func onBaremetal() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
57
vendor/github.com/google/cadvisor/utils/cloudinfo/gce.go
generated
vendored
57
vendor/github.com/google/cadvisor/utils/cloudinfo/gce.go
generated
vendored
@@ -1,57 +0,0 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// 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 cloudinfo
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
info "github.com/google/cadvisor/info/v1"
|
||||
|
||||
"cloud.google.com/go/compute/metadata"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
const (
|
||||
gceProductName = "/sys/class/dmi/id/product_name"
|
||||
google = "Google"
|
||||
)
|
||||
|
||||
func onGCE() bool {
|
||||
data, err := ioutil.ReadFile(gceProductName)
|
||||
if err != nil {
|
||||
klog.V(2).Infof("Error while reading product_name: %v", err)
|
||||
return false
|
||||
}
|
||||
return strings.Contains(string(data), google)
|
||||
}
|
||||
|
||||
func getGceInstanceType() info.InstanceType {
|
||||
machineType, err := metadata.Get("instance/machine-type")
|
||||
if err != nil {
|
||||
return info.UnknownInstance
|
||||
}
|
||||
|
||||
responseParts := strings.Split(machineType, "/") // Extract the instance name from the machine type.
|
||||
return info.InstanceType(responseParts[len(responseParts)-1])
|
||||
}
|
||||
|
||||
func getGceInstanceID() info.InstanceID {
|
||||
instanceID, err := metadata.Get("instance/id")
|
||||
if err != nil {
|
||||
return info.UnknownInstance
|
||||
}
|
||||
return info.InstanceID(info.InstanceType(instanceID))
|
||||
}
|
||||
Reference in New Issue
Block a user