mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-08 12:41:58 +00:00
Fix comparison of EtcdClient to nil so that it does not run into the pointer vs. interface issue
This is a partial rollback of commit 6e6f465a36
("Fix a crash for
kubelet when without EtcdClient") in which we used the `reflect` module
to inspect that the pointer stored inside the interface was `nil`, but
as pointed out by @lavalamp, the correct solution is to make the
function return the interface type, in which case a `return nil` will
return the interface nil and not a nil pointer that turns into a non-nil
value when coerced into an interface.
For more details, see http://golang.org/doc/faq#nil_error and the
discussion in PR #3356.
Tested by installing a kubelet built from head with this patch into a
containervm instance and confirming it did not crash on standalone.go.
Confirmed that by only removing the `reflect.IsNil()` comparison but not
changing the return type of `EtcdClientOrDie()` did indeed cause that
same crash, so changing the return type does indeed fix the issue.
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/golang/glog"
|
||||
@@ -55,7 +56,7 @@ func InitHealthChecking(k *Kubelet) {
|
||||
}
|
||||
|
||||
// TODO: move this into a pkg/tools/etcd_tools
|
||||
func EtcdClientOrDie(etcdServerList util.StringList, etcdConfigFile string) *etcd.Client {
|
||||
func EtcdClientOrDie(etcdServerList util.StringList, etcdConfigFile string) tools.EtcdClient {
|
||||
if len(etcdServerList) > 0 {
|
||||
return etcd.NewClient(etcdServerList)
|
||||
} else if etcdConfigFile != "" {
|
||||
|
Reference in New Issue
Block a user