Skip to content

Commit

Permalink
Test for and fix crash with nil client in kubelet.
Browse files Browse the repository at this point in the history
Added test that fails before fix.
Fixed use of nil pointer.
  • Loading branch information
erictune committed Jan 16, 2015
1 parent ee0ba6c commit 98bdd3f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -96,6 +97,7 @@ func setupRunOnce() {
func main() {
util.InitFlags()
util.InitLogs()
util.ReallyCrash = *reallyCrashForTesting
defer util.FlushLogs()
rand.Seed(time.Now().UTC().UnixNano())

Expand Down
14 changes: 12 additions & 2 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/cache/listwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 98bdd3f

Please sign in to comment.