mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Test for and fix crash with nil client in kubelet.
Added test that fails before fix. Fixed use of nil pointer.
This commit is contained in:
parent
ee0ba6c922
commit
98bdd3f7c4
@ -68,6 +68,7 @@ var (
|
||||
clusterDomain = flag.String("cluster_domain", "", "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains")
|
||||
masterServiceNamespace = flag.String("master_service_namespace", api.NamespaceDefault, "The namespace from which the kubernetes master services should be injected into pods")
|
||||
clusterDNS = util.IP(nil)
|
||||
reallyCrashForTesting = flag.Bool("really_crash_for_testing", false, "If true, crash with panics more often.")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -96,6 +97,7 @@ func setupRunOnce() {
|
||||
func main() {
|
||||
util.InitFlags()
|
||||
util.InitLogs()
|
||||
util.ReallyCrash = *reallyCrashForTesting
|
||||
defer util.FlushLogs()
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
|
@ -51,9 +51,19 @@ CTLRMGR_PORT=${CTLRMGR_PORT:-10252}
|
||||
kube::log::status "Running kubectl with no options"
|
||||
"${KUBE_OUTPUT_HOSTBIN}/kubectl"
|
||||
|
||||
# Start kubelet
|
||||
kube::log::status "Starting kubelet"
|
||||
kube::log::status "Starting kubelet in masterless mode"
|
||||
"${KUBE_OUTPUT_HOSTBIN}/kubelet" \
|
||||
--really_crash_for_testing=true \
|
||||
--root_dir=/tmp/kubelet.$$ \
|
||||
--address="127.0.0.1" \
|
||||
--port="$KUBELET_PORT" 1>&2 &
|
||||
KUBELET_PID=$!
|
||||
kube::util::wait_for_url "http://127.0.0.1:${KUBELET_PORT}/healthz" "kubelet: "
|
||||
kill ${KUBELET_PID} 1>&2 2>/dev/null
|
||||
|
||||
kube::log::status "Starting kubelet in masterful mode"
|
||||
"${KUBE_OUTPUT_HOSTBIN}/kubelet" \
|
||||
--really_crash_for_testing=true \
|
||||
--root_dir=/tmp/kubelet.$$ \
|
||||
--etcd_servers="http://${ETCD_HOST}:${ETCD_PORT}" \
|
||||
--hostname_override="127.0.0.1" \
|
||||
|
2
pkg/client/cache/listwatch.go
vendored
2
pkg/client/cache/listwatch.go
vendored
@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
// ListWatch knows how to list and watch a set of apiserver resources. It satisfies the ListerWatcher interface.
|
||||
// It is a convenience function for users of NewReflector, etc.
|
||||
// It is a convenience function for users of NewReflector, etc. Client must not be nil.
|
||||
type ListWatch struct {
|
||||
Client *client.Client
|
||||
FieldSelector labels.Selector
|
||||
|
@ -93,7 +93,9 @@ func NewMainKubelet(
|
||||
}
|
||||
|
||||
serviceStore := cache.NewStore()
|
||||
cache.NewReflector(&cache.ListWatch{kubeClient, labels.Everything(), "services", api.NamespaceAll}, &api.Service{}, serviceStore).Run()
|
||||
if kubeClient != nil {
|
||||
cache.NewReflector(&cache.ListWatch{kubeClient, labels.Everything(), "services", api.NamespaceAll}, &api.Service{}, serviceStore).Run()
|
||||
}
|
||||
serviceLister := &cache.StoreToServiceLister{serviceStore}
|
||||
|
||||
klet := &Kubelet{
|
||||
|
Loading…
Reference in New Issue
Block a user