mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #2142 from erictune/fix_crash
Require a KubeletClient in master.New()
This commit is contained in:
commit
6c2212b37a
@ -126,13 +126,16 @@ func (c *HTTPKubeletClient) HealthCheck(host string) (health.Status, error) {
|
|||||||
return health.DoHTTPCheck(fmt.Sprintf("%s/healthz", c.url(host)), c.Client)
|
return health.DoHTTPCheck(fmt.Sprintf("%s/healthz", c.url(host)), c.Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FakeKubeletClient is a fake implementation of PodInfoGetter. It is useful for testing.
|
// FakeKubeletClient is a fake implementation of KubeletClient which returns an error
|
||||||
type FakePodInfoGetter struct {
|
// when called. It is useful to pass to the master in a test configuration with
|
||||||
data api.PodInfo
|
// no kubelets.
|
||||||
err error
|
type FakeKubeletClient struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// GetPodInfo is a fake implementation of PodInfoGetter.GetPodInfo.
|
// GetPodInfo is a fake implementation of PodInfoGetter.GetPodInfo.
|
||||||
func (c *FakePodInfoGetter) GetPodInfo(host, podNamespace string, podID string) (api.PodInfo, error) {
|
func (c FakeKubeletClient) GetPodInfo(host, podNamespace string, podID string) (api.PodInfo, error) {
|
||||||
return c.data, c.err
|
return api.PodInfo{}, errors.New("Not Implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c FakeKubeletClient) HealthCheck(host string) (health.Status, error) {
|
||||||
|
return health.Unknown, errors.New("Not Implemented")
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,9 @@ func New(c *Config) *Master {
|
|||||||
boundPodFactory := &pod.BasicBoundPodFactory{
|
boundPodFactory := &pod.BasicBoundPodFactory{
|
||||||
ServiceRegistry: serviceRegistry,
|
ServiceRegistry: serviceRegistry,
|
||||||
}
|
}
|
||||||
|
if c.KubeletClient == nil {
|
||||||
|
glog.Fatalf("master.New() called with config.KubeletClient == nil")
|
||||||
|
}
|
||||||
m := &Master{
|
m := &Master{
|
||||||
podRegistry: etcd.NewRegistry(c.EtcdHelper, boundPodFactory),
|
podRegistry: etcd.NewRegistry(c.EtcdHelper, boundPodFactory),
|
||||||
controllerRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
controllerRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@ -80,6 +81,7 @@ func TestWhoAmI(t *testing.T) {
|
|||||||
defer os.Remove(tokenFilename)
|
defer os.Remove(tokenFilename)
|
||||||
m := master.New(&master.Config{
|
m := master.New(&master.Config{
|
||||||
EtcdHelper: helper,
|
EtcdHelper: helper,
|
||||||
|
KubeletClient: client.FakeKubeletClient{},
|
||||||
EnableLogsSupport: false,
|
EnableLogsSupport: false,
|
||||||
EnableUISupport: false,
|
EnableUISupport: false,
|
||||||
APIPrefix: "/api",
|
APIPrefix: "/api",
|
||||||
@ -364,6 +366,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
|
|||||||
|
|
||||||
m := master.New(&master.Config{
|
m := master.New(&master.Config{
|
||||||
EtcdHelper: helper,
|
EtcdHelper: helper,
|
||||||
|
KubeletClient: client.FakeKubeletClient{},
|
||||||
EnableLogsSupport: false,
|
EnableLogsSupport: false,
|
||||||
EnableUISupport: false,
|
EnableUISupport: false,
|
||||||
APIPrefix: "/api",
|
APIPrefix: "/api",
|
||||||
@ -408,6 +411,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
|
|||||||
|
|
||||||
m := master.New(&master.Config{
|
m := master.New(&master.Config{
|
||||||
EtcdHelper: helper,
|
EtcdHelper: helper,
|
||||||
|
KubeletClient: client.FakeKubeletClient{},
|
||||||
EnableLogsSupport: false,
|
EnableLogsSupport: false,
|
||||||
EnableUISupport: false,
|
EnableUISupport: false,
|
||||||
APIPrefix: "/api",
|
APIPrefix: "/api",
|
||||||
|
@ -41,6 +41,7 @@ func TestClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
m := master.New(&master.Config{
|
m := master.New(&master.Config{
|
||||||
EtcdHelper: helper,
|
EtcdHelper: helper,
|
||||||
|
KubeletClient: client.FakeKubeletClient{},
|
||||||
EnableLogsSupport: false,
|
EnableLogsSupport: false,
|
||||||
EnableUISupport: false,
|
EnableUISupport: false,
|
||||||
APIPrefix: "/api",
|
APIPrefix: "/api",
|
||||||
|
Loading…
Reference in New Issue
Block a user