Skip to content

Commit

Permalink
Merge pull request #14054 from stevekuznetsov/skuznets/start-dry
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored May 6, 2017
2 parents ae1ccf5 + 8673f7c commit 34cda05
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 132 deletions.
57 changes: 30 additions & 27 deletions hack/lib/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ readonly -f os::start::internal::create_bootstrap_policy
# - API_BIND_HOST
# - API_PORT
# - PUBLIC_MASTER_HOST
# - NETWORK_PLUGIN
# Arguments
# 1 - alternate version for the config
# - MASTER_CONFIG_DIR
Expand All @@ -158,6 +159,7 @@ function os::start::internal::configure_master() {
--hostname="${KUBELET_HOST}" \
--volume-dir="${VOLUME_DIR}" \
--etcd-dir="${ETCD_DATA_DIR}" \
--network-plugin="${NETWORK_PLUGIN:-}" \
--write-config="${SERVER_CONFIG_DIR}" \
--listen="${API_SCHEME}://${API_BIND_HOST}:${API_PORT}" \
--public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}"
Expand Down Expand Up @@ -282,19 +284,20 @@ function os::start::master() {
os::log::debug "$( ps -ef | grep openshift )"

os::log::debug "Starting OpenShift server"
local openshift_env=( "OPENSHIFT_PROFILE=web" "OPENSHIFT_ON_PANIC=crash" )
$(os::start::internal::openshift_executable) start master \
--config="${MASTER_CONFIG_DIR}/master-config.yaml" \
--loglevel=4 --logspec='*importer=5' \
&>"${LOG_DIR}/openshift.log" &
local openshift_env=( "OPENSHIFT_PROFILE=${OPENSHIFT_PROFILE:-web}" "OPENSHIFT_ON_PANIC=crash" )
$(os::start::internal::openshift_executable) start master \
--loglevel=4 \
--logspec='*importer=5' \
--config="${MASTER_CONFIG_DIR}/master-config.yaml" \
&>"${LOG_DIR}/openshift.log" &
export OS_PID=$!

os::log::debug "OpenShift server start at: $( date )"

os::test::junit::declare_suite_start "setup/start-master"
os::cmd::try_until_text "oc get --raw /healthz --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 160 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 160 * second )) 0.25
os::cmd::try_until_success "oc get service kubernetes --namespace default --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" $(( 160 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 160 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 160 * second )) 0.25
os::cmd::try_until_success "oc get service kubernetes --namespace default --config='${ADMIN_KUBECONFIG}'" $(( 160 * second )) 0.25
os::test::junit::declare_suite_end

os::log::debug "OpenShift server health checks done at: $( date )"
Expand Down Expand Up @@ -331,26 +334,26 @@ function os::start::all_in_one() {
fi

os::log::debug "Starting OpenShift server"
local openshift_env=( "OPENSHIFT_PROFILE=web" "OPENSHIFT_ON_PANIC=crash" )
local openshift_env=( "OPENSHIFT_PROFILE=${OPENSHIFT_PROFILE:-web}" "OPENSHIFT_ON_PANIC=crash" )
local openshift_executable
openshift_executable="$(os::start::internal::openshift_executable)"
${openshift_executable} start \
--loglevel=4 \
--logspec='*importer=5' \
--latest-images="${use_latest_images}" \
--node-config="${NODE_CONFIG_DIR}/node-config.yaml" \
--master-config="${MASTER_CONFIG_DIR}/master-config.yaml" \
&>"${LOG_DIR}/openshift.log" &
${openshift_executable} start \
--loglevel=4 \
--logspec='*importer=5' \
--latest-images="${use_latest_images}" \
--node-config="${NODE_CONFIG_DIR}/node-config.yaml" \
--master-config="${MASTER_CONFIG_DIR}/master-config.yaml" \
&>"${LOG_DIR}/openshift.log" &
export OS_PID=$!

os::log::debug "OpenShift server start at: $( date )"

os::test::junit::declare_suite_start "setup/start-all_in_one"
os::cmd::try_until_text "oc get --raw /healthz --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_text "oc get --raw ${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 2 * minute )) 0.5
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_success "oc get service kubernetes --namespace default --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" $(( 160 * second )) 0.25
os::cmd::try_until_success "oc get --raw /api/v1/nodes/${KUBELET_HOST} --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" $(( 80 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_text "oc get --raw ${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 2 * minute )) 0.5
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_success "oc get service kubernetes --namespace default --config='${ADMIN_KUBECONFIG}'" $(( 160 * second )) 0.25
os::cmd::try_until_success "oc get --raw /api/v1/nodes/${KUBELET_HOST} --config='${ADMIN_KUBECONFIG}'" $(( 80 * second )) 0.25
os::test::junit::declare_suite_end

os::log::debug "OpenShift server health checks done at: $( date )"
Expand Down Expand Up @@ -407,7 +410,7 @@ readonly -f os::start::etcd
function os::start::api_server() {
local api_server_version=${1:-}
local openshift_volumes=( "${MASTER_CONFIG_DIR}" )
local openshift_env=( "OPENSHIFT_PROFILE=web" "OPENSHIFT_ON_PANIC=crash" )
local openshift_env=( "OPENSHIFT_PROFILE=${OPENSHIFT_PROFILE:-web}" "OPENSHIFT_ON_PANIC=crash" )
local openshift_executable
openshift_executable="$(os::start::internal::openshift_executable "${api_server_version}")"

Expand All @@ -420,8 +423,8 @@ function os::start::api_server() {
os::log::debug "OpenShift API server start at: $( date )"

os::test::junit::declare_suite_start "setup/start-api_server"
os::cmd::try_until_text "oc get --raw /healthz --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 160 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 160 * second )) 0.25
os::test::junit::declare_suite_end

os::log::debug "OpenShift API server health checks done at: $( date )"
Expand Down Expand Up @@ -490,7 +493,7 @@ function os::start::internal::start_node() {
os::log::debug "OpenShift node start at: $( date )"

os::test::junit::declare_suite_start "setup/start-node"
os::cmd::try_until_text "oc get --raw ${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" 'ok' $(( 80 * second )) 0.25
os::cmd::try_until_text "oc get --raw ${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz --config='${ADMIN_KUBECONFIG}'" 'ok' $(( 80 * second )) 0.25
os::test::junit::declare_suite_end

os::log::debug "OpenShift node health checks done at: $( date )"
Expand Down Expand Up @@ -646,7 +649,7 @@ function os::start::registry() {
# For testing purposes, ensure the quota objects are always up to date in the registry by
# disabling project cache.
openshift admin registry --config="${ADMIN_KUBECONFIG}" --images="${USE_IMAGES}" --enforce-quota -o json | \
oc env -f - --output json "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_PROJECTCACHETTL=0" | \
oc create -f -
oc env --config="${ADMIN_KUBECONFIG}" -f - --output json "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_PROJECTCACHETTL=0" | \
oc create --config="${ADMIN_KUBECONFIG}" -f -
}
readonly -f os::start::registry
2 changes: 0 additions & 2 deletions hack/lib/util/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ readonly -f os::util::environment::setup_time_vars
# - export VOLUME_DIR
# - export ARTIFACT_DIR
# - export FAKE_HOME_DIR
# - export HOME
# - export KUBELET_SCHEME
# - export KUBELET_BIND_HOST
# - export KUBELET_HOST
Expand Down Expand Up @@ -129,7 +128,6 @@ readonly -f os::util::environment::update_path_var
# - export VOLUME_DIR
# - export ARTIFACT_DIR
# - export FAKE_HOME_DIR
# - export HOME
# - export OS_TMP_ENV_SET
function os::util::environment::setup_tmpdir_vars() {
local sub_dir=$1
Expand Down
119 changes: 16 additions & 103 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function cleanup()
trap "exit" INT TERM
trap "cleanup" EXIT

set -e

function find_tests() {
local test_regex="${1}"
local full_test_list=()
Expand All @@ -62,19 +60,16 @@ function find_tests() {
}
tests=( $(find_tests ${1:-.*}) )

# Setup environment

# test-cmd specific defaults
API_HOST=${API_HOST:-127.0.0.1}
# deconflict ports so we can run in parallel with other test suites
export API_PORT=${API_PORT:-28443}

export ETCD_HOST=${ETCD_HOST:-127.0.0.1}
export ETCD_PORT=${ETCD_PORT:-24001}
export ETCD_PEER_PORT=${ETCD_PEER_PORT:-27001}

# use a network plugin for network tests
export NETWORK_PLUGIN='redhat/openshift-ovs-multitenant'

os::cleanup::tmpdir
os::util::environment::setup_all_server_vars
export HOME="${FAKE_HOME_DIR}"

# Allow setting $JUNIT_REPORT to toggle output behavior
if [[ -n "${JUNIT_REPORT:-}" ]]; then
Expand All @@ -101,114 +96,32 @@ else
export WEB_PROFILE=cpu
fi

# Check openshift version
echo "openshift version:"
openshift version

# Check oc version
echo "oc version:"
oc version

# profile the web
export OPENSHIFT_PROFILE="${WEB_PROFILE-}"

# 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.
os::log::info "Create certificates for the OpenShift server to ${MASTER_CONFIG_DIR}"
# find the same IP that openshift start will bind to. This allows access from pods that have to talk back to master
SERVER_HOSTNAME_LIST="${PUBLIC_MASTER_HOST},$(openshift start --print-ip),localhost"

openshift admin ca create-master-certs \
--overwrite=false \
--cert-dir="${MASTER_CONFIG_DIR}" \
--hostnames="${SERVER_HOSTNAME_LIST}" \
--master="${MASTER_ADDR}" \
--public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}"

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

oadm create-bootstrap-policy-file --filename="${MASTER_CONFIG_DIR}/policy.json"

# create openshift config
openshift start \
--write-config=${SERVER_CONFIG_DIR} \
--create-certs=false \
--master="${API_SCHEME}://${API_HOST}:${API_PORT}" \
--listen="${API_SCHEME}://${API_HOST}:${API_PORT}" \
--hostname="${KUBELET_HOST}" \
--volume-dir="${VOLUME_DIR}" \
--etcd-dir="${ETCD_DATA_DIR}" \
--images="${USE_IMAGES}" \
--network-plugin=redhat/openshift-ovs-multitenant

# Set deconflicted etcd ports in the config
cp ${SERVER_CONFIG_DIR}/master/master-config.yaml ${SERVER_CONFIG_DIR}/master/master-config.orig.yaml
openshift ex config patch ${SERVER_CONFIG_DIR}/master/master-config.orig.yaml --patch="{\"etcdConfig\": {\"address\": \"${API_HOST}:${ETCD_PORT}\"}}" | \
openshift ex config patch - --patch="{\"etcdConfig\": {\"servingInfo\": {\"bindAddress\": \"${API_HOST}:${ETCD_PORT}\"}}}" | \
openshift ex config patch - --type json --patch="[{\"op\": \"replace\", \"path\": \"/etcdClientInfo/urls\", \"value\": [\"${API_SCHEME}://${API_HOST}:${ETCD_PORT}\"]}]" | \
openshift ex config patch - --patch="{\"etcdConfig\": {\"peerAddress\": \"${API_HOST}:${ETCD_PEER_PORT}\"}}" | \
openshift ex config patch - --patch="{\"etcdConfig\": {\"peerServingInfo\": {\"bindAddress\": \"${API_HOST}:${ETCD_PEER_PORT}\"}}}" > ${SERVER_CONFIG_DIR}/master/master-config.yaml

# check oc version with no server running but config files present
os::start::configure_server

os::test::junit::declare_suite_start "cmd/version"
os::cmd::expect_success_and_not_text "KUBECONFIG='${MASTER_CONFIG_DIR}/admin.kubeconfig' oc version" "did you specify the right host or port"
os::cmd::expect_success_and_not_text "KUBECONFIG='' oc version" "Missing or incomplete configuration info"
os::test::junit::declare_suite_end

# Start openshift
OPENSHIFT_ON_PANIC=crash openshift start master \
--config=${MASTER_CONFIG_DIR}/master-config.yaml \
--loglevel=5 \
&>"${LOG_DIR}/openshift.log" &
OS_PID=$!

if [[ "${API_SCHEME}" == "https" ]]; then
export CURL_CA_BUNDLE="${MASTER_CONFIG_DIR}/ca.crt"
export CURL_CERT="${MASTER_CONFIG_DIR}/admin.crt"
export CURL_KEY="${MASTER_CONFIG_DIR}/admin.key"
fi

os::test::junit::declare_suite_start "cmd/startup"
os::cmd::try_until_text "oc get --raw /healthz --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" "ok"
os::cmd::try_until_text "oc get --raw /healthz/ready --config='${MASTER_CONFIG_DIR}/admin.kubeconfig'" "ok"
os::test::junit::declare_suite_start "cmd/config"
os::cmd::expect_success_and_text "cat ${MASTER_CONFIG_DIR}/master-config.yaml" 'disabledFeatures: null'
os::test::junit::declare_suite_end

os::start::master

# profile the cli commands
export OPENSHIFT_PROFILE="${CLI_PROFILE-}"

# start up a registry for images tests
ADMIN_KUBECONFIG="${MASTER_CONFIG_DIR}/admin.kubeconfig" KUBECONFIG="${MASTER_CONFIG_DIR}/admin.kubeconfig" os::start::registry

#
# Begin tests
#

# check oc version with no config file
os::test::junit::declare_suite_start "cmd/version"
os::cmd::expect_success_and_not_text "oc version" "Missing or incomplete configuration info"
echo "oc version (with no config file set): ok"
os::test::junit::declare_suite_end

# ensure that DisabledFeatures aren't written to config files
os::test::junit::declare_suite_start "cmd/config"
os::cmd::expect_success_and_text "cat ${MASTER_CONFIG_DIR}/master-config.yaml" 'disabledFeatures: null'
os::test::junit::declare_suite_end
os::start::registry

# from this point every command will use config from the KUBECONFIG env var
export KUBERNETES_MASTER="${API_SCHEME}://${API_HOST}:${API_PORT}"
export NODECONFIG="${NODE_CONFIG_DIR}/node-config.yaml"
mkdir -p ${HOME}/.kube
cp ${MASTER_CONFIG_DIR}/admin.kubeconfig ${HOME}/.kube/non-default-config
export HOME="${FAKE_HOME_DIR}"
mkdir -p "${HOME}/.kube"
cp "${MASTER_CONFIG_DIR}/admin.kubeconfig" "${HOME}/.kube/non-default-config"
export KUBECONFIG="${HOME}/.kube/non-default-config"
export CLUSTER_ADMIN_CONTEXT=$(oc config view --flatten -o template --template='{{index . "current-context"}}')
export KUBERNETES_MASTER="${API_SCHEME}://${API_HOST}:${API_PORT}"

# NOTE: Do not add tests here, add them to test/cmd/*.
# Tests should assume they run in an empty project, and should be reentrant if possible
Expand Down
2 changes: 2 additions & 0 deletions test/cmd/admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ project="$( oc project -q )"
defaultimage="openshift/origin-\${component}:latest"
USE_IMAGES=${USE_IMAGES:-$defaultimage}

export NODECONFIG="${NODE_CONFIG_DIR}/node-config.yaml"

os::test::junit::declare_suite_start "cmd/admin"
# This test validates admin level commands including system policy

Expand Down

0 comments on commit 34cda05

Please sign in to comment.