Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hack/make-p12-cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/bash

CERT=${1:-}
KEY=${2:-}
P12=${3:-}
PASSWORD=${4:-}

if [ "${CERT}" == "" ] || [ "${KEY}" == "" ] || [ "${P12}" == "" ] || [ "${PASSWORD}" == "" ]; then
echo "Usage: make-p12-cert.sh cert.crt key.key out.p12 password"
exit 1
fi

openssl pkcs12 -export -inkey "${KEY}" -in "${CERT}" -out "${P12}" -password "pass:${PASSWORD}"
36 changes: 30 additions & 6 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ API_PORT=${API_PORT:-8443}
API_HOST=${API_HOST:-127.0.0.1}
MASTER_ADDR="${API_SCHEME}://${API_HOST}:${API_PORT}"
PUBLIC_MASTER_HOST="${PUBLIC_MASTER_HOST:-${API_HOST}}"
KUBELET_SCHEME=${KUBELET_SCHEME:-http}
KUBELET_SCHEME=${KUBELET_SCHEME:-https}
KUBELET_HOST=${KUBELET_HOST:-127.0.0.1}
KUBELET_PORT=${KUBELET_PORT:-10250}

TEMP_DIR=${USE_TEMP:-$(mktemp -d /tmp/openshift-cmd.XXXX)}
Expand Down Expand Up @@ -86,11 +87,34 @@ do
SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}"
done <<< "${ALL_IP_ADDRESSES}"

openshift admin create-master-certs --overwrite=false --cert-dir="${CERT_DIR}" --hostnames="${SERVER_HOSTNAME_LIST}" --master="${MASTER_ADDR}" --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}"
openshift admin create-node-config --listen="https://0.0.0.0:10250" --node-dir="${CERT_DIR}/node-${API_HOST}" --node="${API_HOST}" --hostnames="${SERVER_HOSTNAME_LIST}" --master="${MASTER_ADDR}" --certificate-authority="${CERT_DIR}/ca/cert.crt" --signer-cert="${CERT_DIR}/ca/cert.crt" --signer-key="${CERT_DIR}/ca/key.key" --signer-serial="${CERT_DIR}/ca/serial.txt"
openshift admin create-master-certs \
--overwrite=false \
--cert-dir="${CERT_DIR}" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="${MASTER_ADDR}" \
--public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}"

openshift admin create-node-config \
--listen="${KUBELET_SCHEME}://0.0.0.0:${KUBELET_PORT}" \
--node-dir="${CERT_DIR}/node-${KUBELET_HOST}" \
--node="${KUBELET_HOST}" \
--hostnames="${KUBELET_HOST}" \
--master="${MASTER_ADDR}" \
--node-client-certificate-authority="${CERT_DIR}/ca/cert.crt" \
--certificate-authority="${CERT_DIR}/ca/cert.crt" \
--signer-cert="${CERT_DIR}/ca/cert.crt" \
--signer-key="${CERT_DIR}/ca/key.key" \
--signer-serial="${CERT_DIR}/ca/serial.txt"

# Start openshift
OPENSHIFT_ON_PANIC=crash openshift start --master="${API_SCHEME}://${API_HOST}:${API_PORT}" --listen="${API_SCHEME}://${API_HOST}:${API_PORT}" --hostname="${API_HOST}" --volume-dir="${VOLUME_DIR}" --cert-dir="${CERT_DIR}" --etcd-dir="${ETCD_DATA_DIR}" --create-certs=false 1>&2 &
OPENSHIFT_ON_PANIC=crash openshift start \
--master="${API_SCHEME}://${API_HOST}:${API_PORT}" \
--listen="${API_SCHEME}://${API_HOST}:${API_PORT}" \
--hostname="${KUBELET_HOST}" \
--volume-dir="${VOLUME_DIR}" \
--cert-dir="${CERT_DIR}" \
--etcd-dir="${ETCD_DATA_DIR}" \
--create-certs=false 1>&2 &
OS_PID=$!

if [[ "${API_SCHEME}" == "https" ]]; then
Expand All @@ -102,9 +126,9 @@ fi
# set the home directory so we don't pick up the users .config
export HOME="${CERT_DIR}/admin"

wait_for_url "http://${API_HOST}:${KUBELET_PORT}/healthz" "kubelet: " 0.25 80
wait_for_url "${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz" "kubelet: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/127.0.0.1" "apiserver(minions): " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/${KUBELET_HOST}" "apiserver(minions): " 0.25 80

# profile the cli commands
export OPENSHIFT_PROFILE="${CLI_PROFILE-}"
Expand Down
47 changes: 36 additions & 11 deletions hack/test-end-to-end.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ API_PORT="${API_PORT:-8443}"
API_SCHEME="${API_SCHEME:-https}"
MASTER_ADDR="${API_SCHEME}://${API_HOST}:${API_PORT}"
PUBLIC_MASTER_HOST="${PUBLIC_MASTER_HOST:-${API_HOST}}"
KUBELET_SCHEME="${KUBELET_SCHEME:-http}"
KUBELET_SCHEME="${KUBELET_SCHEME:-https}"
KUBELET_HOST="${KUBELET_HOST:-127.0.0.1}"
KUBELET_PORT="${KUBELET_PORT:-10250}"

# use the docker bridge ip address until there is a good way to get the auto-selected address from master
Expand Down Expand Up @@ -96,7 +97,10 @@ function cleanup()
osc get -n test builds -o template -t '{{ range .items }}{{.metadata.name}}{{ "\n" }}{{end}}' | xargs -r -l osc build-logs -n test >"${LOG_DIR}/stibuild.log"
osc get -n docker builds -o template -t '{{ range .items }}{{.metadata.name}}{{ "\n" }}{{end}}' | xargs -r -l osc build-logs -n docker >"${LOG_DIR}/dockerbuild.log"
osc get -n custom builds -o template -t '{{ range .items }}{{.metadata.name}}{{ "\n" }}{{end}}' | xargs -r -l osc build-logs -n custom >"${LOG_DIR}/custombuild.log"
curl -L http://localhost:4001/v2/keys/?recursive=true > "${ARTIFACT_DIR}/etcd_dump.json"

echo "[INFO] Dumping etcd contents to ${ARTIFACT_DIR}/etcd_dump.json"
set_curl_args 0 1
curl ${clientcert_args} -L "${API_SCHEME}://${API_HOST}:4001/v2/keys/?recursive=true" > "${ARTIFACT_DIR}/etcd_dump.json"
echo

if [[ -z "${SKIP_TEARDOWN-}" ]]; then
Expand Down Expand Up @@ -174,7 +178,6 @@ echo "[INFO] Certs dir is: ${CERT_DIR}"
echo "[INFO] Using images: ${USE_IMAGES}"

# Start All-in-one server and wait for health
# Specify the scheme and port for the listen address, but let the IP auto-discover. Set --public-master to localhost, for a stable link to the console.
echo "[INFO] Create certificates for the OpenShift server"
# find the same IP that openshift start will bind to. This allows access from pods that have to talk back to master
ALL_IP_ADDRESSES=`ifconfig | grep "inet " | awk '{print $2}'`
Expand All @@ -184,15 +187,37 @@ do
SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}"
done <<< "${ALL_IP_ADDRESSES}"

openshift admin create-master-certs --overwrite=false --cert-dir="${CERT_DIR}" --hostnames="${SERVER_HOSTNAME_LIST}" --master="${MASTER_ADDR}" --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}"
openshift admin create-node-config --listen="https://0.0.0.0:10250" --node-dir="${CERT_DIR}/node-127.0.0.1" --node="127.0.0.1" --hostnames="${SERVER_HOSTNAME_LIST}" --master="${MASTER_ADDR}" --certificate-authority="${CERT_DIR}/ca/cert.crt" --signer-cert="${CERT_DIR}/ca/cert.crt" --signer-key="${CERT_DIR}/ca/key.key" --signer-serial="${CERT_DIR}/ca/serial.txt"
openshift admin create-master-certs \
--overwrite=false \
--cert-dir="${CERT_DIR}" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="${MASTER_ADDR}" \
--public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}"

openshift admin create-node-config \
--listen="${KUBELET_SCHEME}://0.0.0.0:${KUBELET_PORT}" \
--node-dir="${CERT_DIR}/node-${KUBELET_HOST}" \
--node="${KUBELET_HOST}" \
--hostnames="${KUBELET_HOST}" \
--master="${MASTER_ADDR}" \
--node-client-certificate-authority="${CERT_DIR}/ca/cert.crt" \
--certificate-authority="${CERT_DIR}/ca/cert.crt" \
--signer-cert="${CERT_DIR}/ca/cert.crt" \
--signer-key="${CERT_DIR}/ca/key.key" \
--signer-serial="${CERT_DIR}/ca/serial.txt"

echo "[INFO] Starting OpenShift server"
sudo env "PATH=${PATH}" OPENSHIFT_PROFILE=web OPENSHIFT_ON_PANIC=crash openshift start \
--listen="${API_SCHEME}://0.0.0.0:${API_PORT}" --master="${MASTER_ADDR}" --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}" \
--hostname="127.0.0.1" --volume-dir="${VOLUME_DIR}" \
--etcd-dir="${ETCD_DATA_DIR}" --cert-dir="${CERT_DIR}" --loglevel=4 \
--images="${USE_IMAGES}" --create-certs=false\
--listen="${API_SCHEME}://0.0.0.0:${API_PORT}" \
--master="${MASTER_ADDR}" \
--public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}" \
--hostname="${KUBELET_HOST}" \
--volume-dir="${VOLUME_DIR}" \
--etcd-dir="${ETCD_DATA_DIR}" \
--cert-dir="${CERT_DIR}" \
--loglevel=4 \
--images="${USE_IMAGES}" \
--create-certs=false \
&> "${LOG_DIR}/openshift.log" &
OS_PID=$!

Expand All @@ -208,9 +233,9 @@ if [[ "${API_SCHEME}" == "https" ]]; then
echo "[INFO] To debug: export OPENSHIFTCONFIG=$OPENSHIFTCONFIG"
fi

wait_for_url "${KUBELET_SCHEME}://127.0.0.1:${KUBELET_PORT}/healthz" "kubelet: " 0.5 60
wait_for_url "${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz" "[INFO] kubelet: " 0.5 60
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/127.0.0.1" "apiserver(minions): " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/${KUBELET_HOST}" "apiserver(minions): " 0.25 80

# add e2e-user as a viewer for the default namespace so we can see infrastructure pieces appear
openshift ex policy add-role-to-user view e2e-user --namespace=default
Expand Down
29 changes: 15 additions & 14 deletions hack/test-extended.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,24 @@ start_server() {

echo "[INFO] Create certificates for the OpenShift master"
env "PATH=${PATH}" openshift admin create-master-certs \
--overwrite=false \
--cert-dir="${CERT_DIR}" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="https://${OS_MASTER_ADDR}" \
--public-master="https://${OS_MASTER_ADDR}"
--overwrite=false \
--cert-dir="${CERT_DIR}" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="https://${OS_MASTER_ADDR}" \
--public-master="https://${OS_MASTER_ADDR}"

echo "[INFO] Create certificates for the OpenShift node"
env "PATH=${PATH}" openshift admin create-node-config \
--listen="https://0.0.0.0:10250" \
--node-dir="${CERT_DIR}/node-127.0.0.1" \
--node="127.0.0.1" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="https://${OS_MASTER_ADDR}" \
--certificate-authority="${CERT_DIR}/ca/cert.crt" \
--signer-cert="${CERT_DIR}/ca/cert.crt" \
--signer-key="${CERT_DIR}/ca/key.key" \
--signer-serial="${CERT_DIR}/ca/serial.txt"
--listen="https://0.0.0.0:10250" \
--node-dir="${CERT_DIR}/node-127.0.0.1" \
--node="127.0.0.1" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="https://${OS_MASTER_ADDR}" \
--node-client-certificate-authority="${CERT_DIR}/ca/cert.crt" \
--certificate-authority="${CERT_DIR}/ca/cert.crt" \
--signer-cert="${CERT_DIR}/ca/cert.crt" \
--signer-key="${CERT_DIR}/ca/key.key" \
--signer-serial="${CERT_DIR}/ca/serial.txt"

echo "[INFO] Starting OpenShift server"
sudo env "PATH=${PATH}" openshift start \
Expand Down
36 changes: 25 additions & 11 deletions pkg/build/registry/buildlog/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ package buildlog

import (
"fmt"
"net"
"net/http"
"net/url"
"strconv"

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"

"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/build/registry/build"
buildutil "github.com/openshift/origin/pkg/build/util"
"github.com/openshift/origin/pkg/cmd/server/kubernetes"
)

// REST is an implementation of RESTStorage for the api server.
type REST struct {
BuildRegistry build.Registry
PodControl PodControlInterface
BuildRegistry build.Registry
PodControl PodControlInterface
ConnectionInfo kclient.ConnectionInfoGetter
}

type PodControlInterface interface {
Expand All @@ -37,13 +40,16 @@ func (r RealPodControl) getPod(namespace, name string) (*kapi.Pod, error) {
// NewREST creates a new REST for BuildLog
// Takes build registry and pod client to get necessary attributes to assemble
// URL to which the request shall be redirected in order to get build logs.
func NewREST(b build.Registry, pn kclient.PodsNamespacer) *REST {
func NewREST(b build.Registry, pn kclient.PodsNamespacer, connectionInfo kclient.ConnectionInfoGetter) *REST {
return &REST{
BuildRegistry: b,
PodControl: RealPodControl{pn},
BuildRegistry: b,
PodControl: RealPodControl{pn},
ConnectionInfo: connectionInfo,
}
}

var _ = rest.Redirector(&REST{})

// Redirector implementation
func (r *REST) ResourceLocation(ctx kapi.Context, id string) (*url.URL, http.RoundTripper, error) {
build, err := r.BuildRegistry.GetBuild(ctx, id)
Expand All @@ -63,7 +69,17 @@ func (r *REST) ResourceLocation(ctx kapi.Context, id string) (*url.URL, http.Rou
buildPodNamespace := pod.Namespace
// Build will take place only in one container
buildContainerName := pod.Spec.Containers[0].Name
location := fmt.Sprintf("%s:%d/containerLogs/%s/%s/%s", buildPodHost, kubernetes.NodePort, buildPodNamespace, buildPodName, buildContainerName)

scheme, port, transport, err := r.ConnectionInfo.GetConnectionInfo(buildPodHost)
if err != nil {
return nil, nil, err
}

location := &url.URL{
Scheme: scheme,
Host: net.JoinHostPort(buildPodHost, strconv.FormatUint(uint64(port), 10)),
Path: fmt.Sprintf("/containerLogs/%s/%s/%s", buildPodNamespace, buildPodName, buildContainerName),
}

// Pod in which build take place can't be in the Pending or Unknown phase,
// cause no containers are present in the Pod in those phases.
Expand All @@ -73,16 +89,14 @@ func (r *REST) ResourceLocation(ctx kapi.Context, id string) (*url.URL, http.Rou

switch build.Status {
case api.BuildStatusRunning:
location += "?follow=1"
location.RawQuery = "follow=1"
case api.BuildStatusComplete, api.BuildStatusFailed:
// Do not follow the Complete and Failed logs as the streaming already finished.
default:
return nil, nil, fielderrors.NewFieldInvalid("build.Status", build.Status, "must be Running, Complete or Failed")
}

return &url.URL{
Host: location,
}, nil, nil
return location, transport, nil
}

func (r *REST) New() runtime.Object {
Expand Down
23 changes: 10 additions & 13 deletions pkg/build/registry/buildlog/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package buildlog

import (
"fmt"
"net/http"
"testing"

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"

"github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/build/registry/test"
"github.com/openshift/origin/pkg/cmd/server/kubernetes"
)

type podControl struct{}
Expand Down Expand Up @@ -37,12 +38,9 @@ func (p *podControl) getPod(namespace, podName string) (*kapi.Pod, error) {
// is evaluating the outcome based only on build state.
func TestRegistryResourceLocation(t *testing.T) {
expectedLocations := map[api.BuildStatus]string{
api.BuildStatusComplete: fmt.Sprintf("//foo-host:%d/containerLogs/%s/running/foo-container",
kubernetes.NodePort, kapi.NamespaceDefault),
api.BuildStatusFailed: fmt.Sprintf("//foo-host:%d/containerLogs/%s/running/foo-container",
kubernetes.NodePort, kapi.NamespaceDefault),
api.BuildStatusRunning: fmt.Sprintf("//foo-host:%d/containerLogs/%s/running/foo-container?follow=1",
kubernetes.NodePort, kapi.NamespaceDefault),
api.BuildStatusComplete: fmt.Sprintf("https://foo-host:12345/containerLogs/%s/running/foo-container", kapi.NamespaceDefault),
api.BuildStatusFailed: fmt.Sprintf("https://foo-host:12345/containerLogs/%s/running/foo-container", kapi.NamespaceDefault),
api.BuildStatusRunning: fmt.Sprintf("https://foo-host:12345/containerLogs/%s/running/foo-container?follow=1", kapi.NamespaceDefault),
api.BuildStatusNew: "",
api.BuildStatusPending: "",
api.BuildStatusError: "",
Expand Down Expand Up @@ -103,15 +101,14 @@ func TestRegistryResourceLocationPodPhases(t *testing.T) {
func resourceLocationHelper(buildStatus api.BuildStatus, podPhase string, ctx kapi.Context) (string, error) {
expectedBuild := mockBuild(buildStatus, podPhase)
buildRegistry := test.BuildRegistry{Build: expectedBuild}
storage := REST{&buildRegistry, &podControl{}}

storage := REST{&buildRegistry, &podControl{}, &kclient.HTTPKubeletClient{EnableHttps: true, Port: 12345, Client: &http.Client{}}}
redirector := rest.Redirector(&storage)
location, _, err := redirector.ResourceLocation(ctx, "foo-build")

if location != nil {
return location.String(), err
if err != nil {
return "", err
}

return "", err
return location.String(), err
}

func mockPod(podPhase kapi.PodPhase) *kapi.Pod {
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/buildlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BuildLogsNamespacer interface {

// BuildLogsInterface exposes methods on BuildLogs resources.
type BuildLogsInterface interface {
Redirect(name string) *kclient.Request
Get(name string) *kclient.Request
}

// buildLogs implements BuildLogsNamespacer interface
Expand All @@ -28,7 +28,7 @@ func newBuildLogs(c *Client, namespace string) *buildLogs {
}
}

// Redirect builds and returns a buildLog request
func (c *buildLogs) Redirect(name string) *kclient.Request {
return c.r.Get().Namespace(c.ns).Prefix("redirect").Resource("buildLogs").Name(name)
// Get builds and returns a buildLog request
func (c *buildLogs) Get(name string) *kclient.Request {
return c.r.Get().Namespace(c.ns).Prefix("proxy").Resource("buildLogs").Name(name)
}
6 changes: 3 additions & 3 deletions pkg/client/fake_buildlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type FakeBuildLogs struct {
Namespace string
}

// Redirect builds and returns a buildLog request
func (c *FakeBuildLogs) Redirect(name string) *kclient.Request {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "redirect"})
// Get builds and returns a buildLog request
func (c *FakeBuildLogs) Get(name string) *kclient.Request {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "proxy"})
return &kclient.Request{}
}
4 changes: 1 addition & 3 deletions pkg/cmd/cli/cmd/buildlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func NewCmdBuildLogs(fullName string, f *clientcmd.Factory, out io.Writer) *cobr
c, _, err := f.Clients()
checkErr(err)

request := c.BuildLogs(namespace).Redirect(args[0])

readCloser, err := request.Stream()
readCloser, err := c.BuildLogs(namespace).Get(args[0]).Stream()
checkErr(err)
defer readCloser.Close()

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/cmd/cancelbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewCmdCancelBuild(fullName string, f *clientcmd.Factory, out io.Writer) *co
glog.V(2).Infof("Build %v has not yet generated any logs.", buildName)

} else {
response, err := client.BuildLogs(namespace).Redirect(buildName).Do().Raw()
response, err := client.BuildLogs(namespace).Get(buildName).Do().Raw()
if err != nil {
glog.Errorf("Could not fetch build logs for %s: %v", buildName, err)
} else {
Expand Down
Loading