From dd9ec46cc0a671dbe50907a59b9aa95a3ea8624b Mon Sep 17 00:00:00 2001 From: Robert Bailey Date: Tue, 31 Mar 2015 15:51:58 -0700 Subject: [PATCH] Fix test-cmd to work with the kubelet listening on HTTPS. --- cmd/kubelet/app/server.go | 10 +++++++--- hack/test-cmd.sh | 13 +++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index e66b86e41cb..53fff33b04a 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -23,6 +23,7 @@ import ( "math/rand" "net" "net/http" + "path" "strconv" "strings" "time" @@ -91,6 +92,7 @@ type KubeletServer struct { CloudConfigFile string TLSCertFile string TLSPrivateKeyFile string + CertDirectory string } // NewKubeletServer will create a new KubeletServer with default values. @@ -118,6 +120,7 @@ func NewKubeletServer() *KubeletServer { ImageGCLowThresholdPercent: 80, NetworkPluginName: "", HostNetworkSources: kubelet.FileSource, + CertDirectory: "/var/run/kubernetes", } } @@ -134,8 +137,9 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.TLSCertFile, "tls_cert_file", s.TLSCertFile, ""+ "File containing x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). "+ "If --tls_cert_file and --tls_private_key_file are not provided, a self-signed certificate and key "+ - "are generated for the public address and saved to /var/run/kubernetes.") + "are generated for the public address and saved to the directory passed to --cert_dir.") fs.StringVar(&s.TLSPrivateKeyFile, "tls_private_key_file", s.TLSPrivateKeyFile, "File containing x509 private key matching --tls_cert_file.") + fs.StringVar(&s.CertDirectory, "cert_dir", s.CertDirectory, "The directory where the TLS certs are located (by default /var/run/kubernetes)") fs.StringVar(&s.HostnameOverride, "hostname_override", s.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.") fs.StringVar(&s.PodInfraContainerImage, "pod_infra_container_image", s.PodInfraContainerImage, "The image whose network/ipc namespaces containers in each pod will use.") fs.StringVar(&s.DockerEndpoint, "docker_endpoint", s.DockerEndpoint, "If non-empty, use this for the docker endpoint to communicate with") @@ -204,8 +208,8 @@ func (s *KubeletServer) Run(_ []string) error { } if s.TLSCertFile == "" && s.TLSPrivateKeyFile == "" { - s.TLSCertFile = "/var/run/kubernetes/kubelet.crt" - s.TLSPrivateKeyFile = "/var/run/kubernetes/kubelet.key" + s.TLSCertFile = path.Join(s.CertDirectory, "kubelet.crt") + s.TLSPrivateKeyFile = path.Join(s.CertDirectory, "kubelet.key") if err := util.GenerateSelfSignedCert(util.GetHostname(s.HostnameOverride), s.TLSCertFile, s.TLSPrivateKeyFile); err != nil { glog.Fatalf("Unable to generate self signed cert: %v", err) } diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index 75088618f29..a91d9f544ea 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -48,6 +48,7 @@ ETCD_PORT=${ETCD_PORT:-4001} API_PORT=${API_PORT:-8080} API_HOST=${API_HOST:-127.0.0.1} KUBELET_PORT=${KUBELET_PORT:-10250} +KUBELET_HEALTHZ_PORT=${KUBELET_HEALTHZ_PORT:-10248} CTLRMGR_PORT=${CTLRMGR_PORT:-10252} # Check kubectl @@ -58,27 +59,31 @@ kube::log::status "Starting kubelet in masterless mode" "${KUBE_OUTPUT_HOSTBIN}/kubelet" \ --really_crash_for_testing=true \ --root_dir=/tmp/kubelet.$$ \ + --cert_dir="${TMPDIR:-/tmp/}" \ --docker_endpoint="fake://" \ --hostname_override="127.0.0.1" \ --address="127.0.0.1" \ - --port="$KUBELET_PORT" 1>&2 & + --port="$KUBELET_PORT" \ + --healthz_port="${KUBELET_HEALTHZ_PORT}" 1>&2 & KUBELET_PID=$! -kube::util::wait_for_url "http://127.0.0.1:${KUBELET_PORT}/healthz" "kubelet: " +kube::util::wait_for_url "http://127.0.0.1:${KUBELET_HEALTHZ_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.$$ \ + --cert_dir="${TMPDIR:-/tmp/}" \ --docker_endpoint="fake://" \ --hostname_override="127.0.0.1" \ --address="127.0.0.1" \ --api_servers="${API_HOST}:${API_PORT}" \ --auth_path="${KUBE_ROOT}/hack/.test-cmd-auth" \ - --port="$KUBELET_PORT" 1>&2 & + --port="$KUBELET_PORT" \ + --healthz_port="${KUBELET_HEALTHZ_PORT}" 1>&2 & KUBELET_PID=$! -kube::util::wait_for_url "http://127.0.0.1:${KUBELET_PORT}/healthz" "kubelet: " +kube::util::wait_for_url "http://127.0.0.1:${KUBELET_HEALTHZ_PORT}/healthz" "kubelet: " # Start kube-apiserver kube::log::status "Starting kube-apiserver"