Skip to content

Commit

Permalink
Fix hack/test-cmd.sh test.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed Feb 5, 2015
1 parent ead6710 commit 524cdba
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
3 changes: 2 additions & 1 deletion cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
kubeletServer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/server"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
Expand Down Expand Up @@ -139,7 +140,7 @@ func startComponents(etcdClient tools.EtcdClient, cl *client.Client, addr net.IP
runScheduler(cl)
runControllerManager(machineList, cl, *nodeMilliCPU, *nodeMemory)

dockerClient := util.ConnectToDockerOrDie(*dockerEndpoint)
dockerClient := dockertools.ConnectToDockerOrDie(*dockerEndpoint)
kubeletServer.SimpleRunKubelet(cl, nil, dockerClient, machineList[0], "/tmp/kubernetes", "", "127.0.0.1", 10250, *masterServiceNamespace, kubeletServer.ProbeVolumePlugins())
}

Expand Down
2 changes: 2 additions & 0 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ kube::log::status "Starting kubelet in masterless mode"
"${KUBE_OUTPUT_HOSTBIN}/kubelet" \
--really_crash_for_testing=true \
--root_dir=/tmp/kubelet.$$ \
--docker_endpoint="fake://" \
--address="127.0.0.1" \
--port="$KUBELET_PORT" 1>&2 &
KUBELET_PID=$!
Expand All @@ -65,6 +66,7 @@ kube::log::status "Starting kubelet in masterful mode"
"${KUBE_OUTPUT_HOSTBIN}/kubelet" \
--really_crash_for_testing=true \
--root_dir=/tmp/kubelet.$$ \
--docker_endpoint="fake://" \
--etcd_servers="http://${ETCD_HOST}:${ETCD_PORT}" \
--hostname_override="127.0.0.1" \
--address="127.0.0.1" \
Expand Down
29 changes: 29 additions & 0 deletions pkg/kubelet/dockertools/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -624,6 +625,34 @@ func parseImageName(image string) (string, string) {
return image, tag
}

// Get a docker endpoint, either from the string passed in, or $DOCKER_HOST environment variables
func getDockerEndpoint(dockerEndpoint string) string {
var endpoint string
if len(dockerEndpoint) > 0 {
endpoint = dockerEndpoint
} else if len(os.Getenv("DOCKER_HOST")) > 0 {
endpoint = os.Getenv("DOCKER_HOST")
} else {
endpoint = "unix:///var/run/docker.sock"
}
glog.Infof("Connecting to docker on %s", endpoint)

return endpoint
}

func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface {
if dockerEndpoint == "fake://" {
return &FakeDockerClient{
VersionInfo: []string{"apiVersion=1.16"},
}
}
client, err := docker.NewClient(getDockerEndpoint(dockerEndpoint))
if err != nil {
glog.Fatal("Couldn't connect to docker.")
}
return client
}

type ContainerCommandRunner interface {
RunInContainer(containerID string, cmd []string) ([]byte, error)
GetDockerServerVersion() ([]uint, error)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func isValidDockerVersion(ver []uint) (bool, string) {
if ver[i] != minAllowedVersion[i] {
if ver[i] < minAllowedVersion[i] {
versions := make([]string, len(ver))
for i, v := range(ver) {
for i, v := range ver {
versions[i] = fmt.Sprint(v)
}
return false, strings.Join(versions, ".")
Expand All @@ -139,7 +139,7 @@ func (s *Server) handleHealthz(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
msg := "Docker version is too old (" + version + ")"
w.Write([]byte(msg))
return;
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *KubeletServer) Run(_ []string) error {
CAdvisorPort: s.CAdvisorPort,
EnableServer: s.EnableServer,
EnableDebuggingHandlers: s.EnableDebuggingHandlers,
DockerClient: util.ConnectToDockerOrDie(s.DockerEndpoint),
DockerClient: dockertools.ConnectToDockerOrDie(s.DockerEndpoint),
KubeClient: client,
EtcdClient: kubelet.EtcdClientOrDie(s.EtcdServerList, s.EtcdConfigFile),
MasterServiceNamespace: s.MasterServiceNamespace,
Expand Down
25 changes: 0 additions & 25 deletions pkg/util/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ limitations under the License.
package util

import (
"os"
"os/exec"
"strings"

"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
)

Expand All @@ -38,26 +36,3 @@ func GetHostname(hostnameOverride string) string {
}
return strings.TrimSpace(string(hostname))
}

// Get a docker endpoint, either from the string passed in, or $DOCKER_HOST environment variables
func GetDockerEndpoint(dockerEndpoint string) string {
var endpoint string
if len(dockerEndpoint) > 0 {
endpoint = dockerEndpoint
} else if len(os.Getenv("DOCKER_HOST")) > 0 {
endpoint = os.Getenv("DOCKER_HOST")
} else {
endpoint = "unix:///var/run/docker.sock"
}
glog.Infof("Connecting to docker on %s", endpoint)

return endpoint
}

func ConnectToDockerOrDie(dockerEndpoint string) *docker.Client {
client, err := docker.NewClient(GetDockerEndpoint(dockerEndpoint))
if err != nil {
glog.Fatal("Couldn't connect to docker.")
}
return client
}

0 comments on commit 524cdba

Please sign in to comment.