mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 08:40:42 +00:00
commit
8ddc33998c
@ -27,6 +27,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/go-etcd/etcd"
|
||||||
|
@ -247,6 +247,7 @@ func ValidateManifest(manifest *ContainerManifest) []error {
|
|||||||
return []error(allErrs)
|
return []error(allErrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateService tests if required fields in the service are set.
|
||||||
func ValidateService(service *Service) []error {
|
func ValidateService(service *Service) []error {
|
||||||
allErrs := errorList{}
|
allErrs := errorList{}
|
||||||
if service.ID == "" {
|
if service.ID == "" {
|
||||||
|
@ -237,10 +237,12 @@ func (h *HumanReadablePrinter) PrintObj(obj interface{}, output io.Writer) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template.
|
||||||
type TemplatePrinter struct {
|
type TemplatePrinter struct {
|
||||||
Template *template.Template
|
Template *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print parses the data as JSON, and re-formats it with the Go Template.
|
||||||
func (t *TemplatePrinter) Print(data []byte, w io.Writer) error {
|
func (t *TemplatePrinter) Print(data []byte, w io.Writer) error {
|
||||||
obj, err := api.Decode(data)
|
obj, err := api.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -249,6 +251,7 @@ func (t *TemplatePrinter) Print(data []byte, w io.Writer) error {
|
|||||||
return t.PrintObj(obj, w)
|
return t.PrintObj(obj, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintObj formats the obj with the Go Template.
|
||||||
func (t *TemplatePrinter) PrintObj(obj interface{}, w io.Writer) error {
|
func (t *TemplatePrinter) PrintObj(obj interface{}, w io.Writer) error {
|
||||||
return t.Template.Execute(w, obj)
|
return t.Template.Execute(w, obj)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
||||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/go-etcd/etcd"
|
||||||
@ -49,8 +48,8 @@ const defaultChanSize = 1024
|
|||||||
|
|
||||||
// taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc
|
// taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc
|
||||||
const minShares = 2
|
const minShares = 2
|
||||||
const sharesPerCpu = 1024
|
const sharesPerCPU = 1024
|
||||||
const milliCpuToCpu = 1000
|
const milliCPUToCPU = 1000
|
||||||
|
|
||||||
// CadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client.
|
// CadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client.
|
||||||
type CadvisorInterface interface {
|
type CadvisorInterface interface {
|
||||||
@ -125,7 +124,7 @@ func (kl *Kubelet) RunKubelet(dockerEndpoint, configPath, manifestURL, etcdServe
|
|||||||
}
|
}
|
||||||
if address != "" {
|
if address != "" {
|
||||||
glog.Infof("Starting to listen on %s:%d", address, port)
|
glog.Infof("Starting to listen on %s:%d", address, port)
|
||||||
handler := KubeletServer{
|
handler := Server{
|
||||||
Kubelet: kl,
|
Kubelet: kl,
|
||||||
UpdateChannel: updateChannel,
|
UpdateChannel: updateChannel,
|
||||||
DelegateHandler: http.DefaultServeMux,
|
DelegateHandler: http.DefaultServeMux,
|
||||||
@ -275,9 +274,9 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m
|
|||||||
return exposedPorts, portBindings
|
return exposedPorts, portBindings
|
||||||
}
|
}
|
||||||
|
|
||||||
func milliCpuToShares(milliCpu int) int {
|
func milliCPUToShares(milliCPU int) int {
|
||||||
// Conceptually (milliCpu / milliCpuToCpu) * sharesPerCpu, but factored to improve rounding.
|
// Conceptually (milliCPU / milliCPUToCPU) * sharesPerCPU, but factored to improve rounding.
|
||||||
shares := (milliCpu * sharesPerCpu) / milliCpuToCpu
|
shares := (milliCPU * sharesPerCPU) / milliCPUToCPU
|
||||||
if shares < minShares {
|
if shares < minShares {
|
||||||
return minShares
|
return minShares
|
||||||
}
|
}
|
||||||
@ -299,7 +298,7 @@ func (kl *Kubelet) runContainer(manifest *api.ContainerManifest, container *api.
|
|||||||
Hostname: container.Name,
|
Hostname: container.Name,
|
||||||
Image: container.Image,
|
Image: container.Image,
|
||||||
Memory: int64(container.Memory),
|
Memory: int64(container.Memory),
|
||||||
CpuShares: int64(milliCpuToShares(container.CPU)),
|
CpuShares: int64(milliCPUToShares(container.CPU)),
|
||||||
Volumes: volumes,
|
Volumes: volumes,
|
||||||
WorkingDir: container.WorkingDir,
|
WorkingDir: container.WorkingDir,
|
||||||
},
|
},
|
||||||
@ -865,7 +864,7 @@ func (kl *Kubelet) statsFromContainerPath(containerPath string, req *info.Contai
|
|||||||
return cinfo, nil
|
return cinfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerStats returns stats (from Cadvisor) for a container.
|
// GetContainerInfo returns stats (from Cadvisor) for a container.
|
||||||
func (kl *Kubelet) GetContainerInfo(podID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (kl *Kubelet) GetContainerInfo(podID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||||
if kl.CadvisorClient == nil {
|
if kl.CadvisorClient == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -28,13 +28,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/google/cadvisor/info"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
|
||||||
|
"github.com/google/cadvisor/info"
|
||||||
"gopkg.in/v1/yaml"
|
"gopkg.in/v1/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KubeletServer is a http.Handler which exposes kubelet functionality over HTTP.
|
// Server is a http.Handler which exposes kubelet functionality over HTTP.
|
||||||
type KubeletServer struct {
|
type Server struct {
|
||||||
Kubelet kubeletInterface
|
Kubelet kubeletInterface
|
||||||
UpdateChannel chan<- manifestUpdate
|
UpdateChannel chan<- manifestUpdate
|
||||||
DelegateHandler http.Handler
|
DelegateHandler http.Handler
|
||||||
@ -48,11 +48,11 @@ type kubeletInterface interface {
|
|||||||
GetPodInfo(name string) (api.PodInfo, error)
|
GetPodInfo(name string) (api.PodInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KubeletServer) error(w http.ResponseWriter, err error) {
|
func (s *Server) error(w http.ResponseWriter, err error) {
|
||||||
http.Error(w, fmt.Sprintf("Internal Error: %v", err), http.StatusInternalServerError)
|
http.Error(w, fmt.Sprintf("Internal Error: %v", err), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
defer httplog.MakeLogged(req, &w).Log()
|
defer httplog.MakeLogged(req, &w).Log()
|
||||||
|
|
||||||
u, err := url.ParseRequestURI(req.RequestURI)
|
u, err := url.ParseRequestURI(req.RequestURI)
|
||||||
@ -113,7 +113,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KubeletServer) serveStats(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
||||||
// /stats/<podid>/<containerName>
|
// /stats/<podid>/<containerName>
|
||||||
components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/")
|
components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/")
|
||||||
var stats *info.ContainerInfo
|
var stats *info.ContainerInfo
|
||||||
|
@ -53,7 +53,7 @@ func (fk *fakeKubelet) GetMachineStats(req *info.ContainerInfoRequest) (*info.Co
|
|||||||
type serverTestFramework struct {
|
type serverTestFramework struct {
|
||||||
updateChan chan manifestUpdate
|
updateChan chan manifestUpdate
|
||||||
updateReader *channelReader
|
updateReader *channelReader
|
||||||
serverUnderTest *KubeletServer
|
serverUnderTest *Server
|
||||||
fakeKubelet *fakeKubelet
|
fakeKubelet *fakeKubelet
|
||||||
testHTTPServer *httptest.Server
|
testHTTPServer *httptest.Server
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func makeServerTest() *serverTestFramework {
|
|||||||
}
|
}
|
||||||
fw.updateReader = startReading(fw.updateChan)
|
fw.updateReader = startReading(fw.updateChan)
|
||||||
fw.fakeKubelet = &fakeKubelet{}
|
fw.fakeKubelet = &fakeKubelet{}
|
||||||
fw.serverUnderTest = &KubeletServer{
|
fw.serverUnderTest = &Server{
|
||||||
Kubelet: fw.fakeKubelet,
|
Kubelet: fw.fakeKubelet,
|
||||||
UpdateChannel: fw.updateChan,
|
UpdateChannel: fw.updateChan,
|
||||||
}
|
}
|
||||||
|
@ -1064,7 +1064,7 @@ func TestGetContainerStatsWithoutCadvisor(t *testing.T) {
|
|||||||
t.Errorf("MaxMemoryUsage is %v even if there's no cadvisor", stats.StatsPercentiles.MaxMemoryUsage)
|
t.Errorf("MaxMemoryUsage is %v even if there's no cadvisor", stats.StatsPercentiles.MaxMemoryUsage)
|
||||||
}
|
}
|
||||||
if len(stats.StatsPercentiles.CpuUsagePercentiles) > 0 {
|
if len(stats.StatsPercentiles.CpuUsagePercentiles) > 0 {
|
||||||
t.Errorf("Cpu usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.CpuUsagePercentiles)
|
t.Errorf("CPU usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.CpuUsagePercentiles)
|
||||||
}
|
}
|
||||||
if len(stats.StatsPercentiles.MemoryUsagePercentiles) > 0 {
|
if len(stats.StatsPercentiles.MemoryUsagePercentiles) > 0 {
|
||||||
t.Errorf("Memory usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.MemoryUsagePercentiles)
|
t.Errorf("Memory usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.MemoryUsagePercentiles)
|
||||||
|
Loading…
Reference in New Issue
Block a user