Skip to content

Commit

Permalink
enable API aggregation and Service Catalog RBAC on Jenkins (openshift…
Browse files Browse the repository at this point in the history
…#1333)

* enable API aggregation and Service Catalog RBAC on Jenkins

* temporarily disable e2e.test run in Jenkins
  • Loading branch information
kibbles-n-bytes authored and pmorie committed Oct 15, 2017
1 parent 5a93315 commit eba8ba4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 82 deletions.
7 changes: 6 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ def test_zone = params.TEST_ZONE ?: 'us-west1-b'
def namespace = 'catalog'
def root_path = 'src/github.com/kubernetes-incubator/service-catalog'
def timeoutMin = 30
def certFolder = '/tmp/sc-certs'

node {
echo "Service Catalog end-to-end test"

sh "sudo rm -rf ${env.WORKSPACE}/*"
sh "rm -rf ${certFolder} && mkdir ${certFolder}"

updatePullRequest('run')

Expand Down Expand Up @@ -120,6 +122,7 @@ node {
--create-artifacts
"""

/*
ansiColor('xterm-darker-gray') {
// Run the e2e test framework
sh """${env.ROOT}/contrib/jenkins/run_e2e.sh \
Expand All @@ -129,6 +132,7 @@ node {
--create-artifacts
"""
}
*/

echo 'Run succeeded.'
}
Expand All @@ -137,8 +141,9 @@ node {
currentBuild.result = 'FAILURE'
} finally {
archiveArtifacts artifacts: 'walkthrough*.txt', fingerprint: true
archiveArtifacts artifacts: 'e2e*.txt', fingerprint: true
// archiveArtifacts artifacts: 'e2e*.txt', fingerprint: true
try {
sh "rm -rf ${certFolder}"
sh """${env.ROOT}/contrib/jenkins/cleanup_cluster.sh --kubeconfig ${KUBECONFIG}"""
} catch (Exception e) {
echo 'Exception caught during cleanup.'
Expand Down
17 changes: 8 additions & 9 deletions contrib/jenkins/init_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,33 @@ gcloud auth activate-service-account \

echo "Creating cluster ${CLUSTERNAME}"

# Use the latest 1.6.X version that GKE offers.
# Use the latest 1.7.X version that GKE offers.
CLUSTER_VERSION="$(gcloud container get-server-config --zone "${ZONE}" \
| awk '
BEGIN {p=0};
/validMasterVersions:/ {p=1; next};
/validNodeVersions:/ {exit};
p && /1.6/ {print $2; exit}
p && /1.7/ {print $2; exit}
')"

[[ -n "${CLUSTER_VERSION}" ]] \
|| { echo 'Could not find valid 1.6.X cluster version on Google Container Engine.'; exit 1; }
|| { echo 'Could not find valid 1.7.X cluster version on Google Container Engine.'; exit 1; }

echo "Using cluster version ${CLUSTER_VERSION}"

gcloud container clusters create "${CLUSTERNAME}" --project="${PROJECT}" --zone="${ZONE}" \
--cluster-version "${CLUSTER_VERSION}" \
--cluster-version "${CLUSTER_VERSION}" --no-enable-legacy-authorization \
|| { echo 'Cannot create cluster.'; exit 1; }

echo "Using cluster ${CLUSTERNAME}."

gcloud container clusters get-credentials "${CLUSTERNAME}" --project="${PROJECT}" --zone="${ZONE}" \
|| { echo 'Cannot get credentials for cluster.'; exit 1; }

# On GKE you need to give your user proper permissions in order to create new
# cluster roles. Needed for RBAC setup.
ACCOUNT_NAME="$(gcloud info | grep Account | sed 's/.*\[\(.*\)\]/\1/')"
kubectl create clusterrolebinding jenkins-cluster-admin-binding \
--clusterrole=cluster-admin --user="${ACCOUNT_NAME}" \
# Need to give tiller proper permissions in order to create RBAC roles.
kubectl create clusterrolebinding tiller-cluster-admin \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:default \
|| { echo 'Cannot not create cluster-admin role for service account.'; exit 1; }

helm init \
Expand Down
70 changes: 34 additions & 36 deletions contrib/jenkins/install_catalog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ done

REGISTRY="${REGISTRY:-}"
VERSION="${VERSION:-"canary"}"
CERT_FOLDER="${CERT_FOLDER:-"/tmp/sc-certs/"}"
FIX_CONFIGMAP="${FIX_CONFIGMAP:-false}"

CONTROLLER_MANAGER_IMAGE="${REGISTRY}controller-manager:${VERSION}"
Expand All @@ -43,6 +44,15 @@ echo "Using controller-manager image: ${CONTROLLER_MANAGER_IMAGE}"
echo "Using apiserver image: ${APISERVER_IMAGE}"
echo '-------------------'

# Create certificates for API server
echo 'Creating API server CA and certificate...'

# The SC_SERVING_CA, SC_SERVING_CERT, and SC_SERVING_KEY environment variables
# are sourced from this script.
CERT_FOLDER="${CERT_FOLDER}" source ${ROOT}/contrib/svc-cat-apiserver-aggregation-tls-setup.sh \
|| error_exit 'Error creating certificates for API server.'


# Deploying to cluster

echo 'Deploying service catalog...'
Expand All @@ -59,56 +69,44 @@ if [[ "${FIX_CONFIGMAP}" == true ]] && [[ -z "$(kubectl --namespace kube-system
[[ -n "$(kubectl --namespace kube-system get configmap extension-apiserver-authentication -o jsonpath="{ $.data['requestheader-client-ca-file'] }")" ]] || { echo "Could not add requestheader auth CA to extension-apiserver-authentication configmap."; exit 1; }
fi

VALUES=()
VALUES+="controllerManager.image=${CONTROLLER_MANAGER_IMAGE}"
VALUES+=",apiserver.image=${APISERVER_IMAGE}"
VALUES+=",apiserver.service.type=NodePort"
VALUES+=",apiserver.service.nodePort.securePort=30443"
PARAMETERS="$(cat <<-EOF
--set apiserver.auth.enabled=true \
--set useAggregator=true \
--set apiserver.tls.ca=$(base64 --wrap 0 ${SC_SERVING_CA}) \
--set apiserver.tls.cert=$(base64 --wrap 0 ${SC_SERVING_CERT}) \
--set apiserver.tls.key=$(base64 --wrap 0 ${SC_SERVING_KEY}) \
--set controllerManager.image=${CONTROLLER_MANAGER_IMAGE} \
--set apiserver.image=${APISERVER_IMAGE}
EOF
)"

retry \
helm install "${ROOT}/charts/catalog" \
--name "catalog" \
--namespace "catalog" \
--set "${VALUES}" \
${PARAMETERS} \
|| error_exit 'Error deploying service catalog to cluster.'

# Waiting for everything to come up

echo 'Waiting on pods to come up...'

wait_for_expected_output -e 'catalog-catalog-controller-manager' \
kubectl get pods --namespace catalog \
&& wait_for_expected_output -e 'catalog-catalog-apiserver' \
kubectl get pods --namespace catalog \
&& wait_for_expected_output -x -e 'Pending' \
kubectl get pods --namespace catalog \
&& wait_for_expected_output -x -e 'ContainerCreating' \
kubectl get pods --namespace catalog \
|| error_exit 'Timed out waiting for service catalog pods to come up.'
echo 'Waiting for Service Catalog API Server to be up...'

[[ "$(kubectl get pods --namespace catalog | grep catalog-catalog-apiserver | awk '{print $3}')" == 'Running' ]] \
retry &> /dev/null \
kubectl get clusterservicebrokers,clusterserviceclasses,serviceinstances,servicebindings \
|| {
POD_NAME="$(kubectl get pods --namespace catalog | grep catalog-catalog-apiserver | awk '{print $1}')"
kubectl get pod "${POD_NAME}" --namespace catalog
kubectl describe pod "${POD_NAME}" --namespace catalog
error_exit 'API server pod did not come up successfully.'
API_SERVER_POD_NAME="$(kubectl get pods --namespace catalog | grep catalog-catalog-apiserver | awk '{print $1}')"
kubectl describe pod "${API_SERVER_POD_NAME}" --namespace catalog
error_exit 'Timed out waiting for expected response from service catalog API server.'
}

[[ "$(kubectl get pods --namespace catalog | grep catalog-catalog-controller | awk '{print $3}')" == 'Running' ]] \
echo 'Waiting for Service Catalog Controller to be up...'

CONTROLLER_POD_NAME="$(kubectl get pods --namespace catalog | grep catalog-catalog-controller | awk '{print $1}')"
wait_for_expected_output -e 'Running' \
kubectl get pods "${CONTROLLER_POD_NAME}" --namespace catalog \
|| {
POD_NAME="$(kubectl get pods --namespace catalog | grep catalog-catalog-controller | awk '{print $1}')"
kubectl get pod "${POD_NAME}" --namespace catalog
kubectl describe pod "${POD_NAME}" --namespace catalog
error_exit 'Controller manager pod did not come up successfully.'
kubectl describe pod "${CONTROLLER_POD_NAME}" --namespace catalog
error_exit 'Timed out waiting for service catalog controller-manager pod to come up.'
}

echo 'Waiting for Service Catalog API Server to be up...'

${ROOT}/contrib/jenkins/setup-sc-context.sh \
|| error_exit 'Error when setting up context for service catalog.'

retry &> /dev/null \
kubectl --context=service-catalog get clusterservicebrokers,clusterserviceclasses,serviceinstances,servicebindings \
|| error_exit 'Timed out waiting for expected response from service catalog API server.'

echo 'Service Catalog installed successfully.'
8 changes: 2 additions & 6 deletions contrib/jenkins/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ done
CATALOG_RELEASE="catalog"

K8S_KUBECONFIG="${KUBECONFIG:-"~/.kube/config"}"
SC_KUBECONFIG="/tmp/sc-kubeconfig"

function cleanup() {
export KUBECONFIG="${K8S_KUBECONFIG}"
Expand All @@ -53,7 +52,6 @@ function cleanup() {
echo 'Cleaning up resources...'
{
helm delete --purge "${CATALOG_RELEASE}" || true
rm -f "${SC_KUBECONFIG}"
} &> /dev/null
}

Expand All @@ -74,10 +72,8 @@ ${ROOT}/contrib/jenkins/install_catalog.sh ${ARGUMENTS} \
make bin/e2e.test \
|| error_exit "Error when making e2e test binary."

KUBECONFIG="${KUBECONFIG}" ${ROOT}/bin/e2e.test \
-service-catalog-config="${KUBECONFIG}" \
-service-catalog-context="service-catalog" \
-broker-image="${REGISTRY}user-broker:${VERSION}" \
export SERVICECATALOGCONFIG="${KUBECONFIG}"
${ROOT}/bin/e2e.test -broker-image="${REGISTRY}user-broker:${VERSION}" \
|| error_exit "Error while running e2e tests."

echo "'e2e.test' completed successfully."
42 changes: 21 additions & 21 deletions contrib/jenkins/test_walkthrough.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,62 +128,62 @@ echo 'Creating broker...'
# Defined in ../pkg/broker/user_provided/controller/controller.go
USER_PROVIDED_SERVICE_ID="4f6e6cf6-ffdd-425f-a2c7-3c9258ad2468"

kubectl --context=service-catalog create -f "${ROOT}/contrib/examples/walkthrough/ups-broker.yaml" \
kubectl create -f "${ROOT}/contrib/examples/walkthrough/ups-broker.yaml" \
|| error_exit 'Error when creating ups-broker.'

wait_for_expected_output -e 'FetchedCatalog' \
kubectl --context=service-catalog get clusterservicebrokers ups-broker -o yaml \
kubectl get clusterservicebrokers ups-broker -o yaml \
|| {
kubectl --context=service-catalog get clusterservicebrokers ups-broker -o yaml
kubectl get clusterservicebrokers ups-broker -o yaml
error_exit 'Did not receive expected condition when creating ups-broker.'
}

[[ "$(kubectl --context=service-catalog get clusterservicebrokers ups-broker -o yaml)" == *"status: \"True\""* ]] \
[[ "$(kubectl get clusterservicebrokers ups-broker -o yaml)" == *"status: \"True\""* ]] \
|| {
kubectl --context=service-catalog get clusterservicebrokers ups-broker -o yaml
kubectl get clusterservicebrokers ups-broker -o yaml
error_exit 'Failure status reported when attempting to fetch catalog from ups-broker.'
}

[[ "$(kubectl --context=service-catalog get clusterserviceclasses)" == *${USER_PROVIDED_SERVICE_ID}* ]] \
[[ "$(kubectl get clusterserviceclasses)" == *${USER_PROVIDED_SERVICE_ID}* ]] \
|| error_exit 'user-provided-service ID not listed when fetching service classes.'

# Provision an instance

echo 'Provisioning instance...'

kubectl --context=service-catalog create -f "${ROOT}/contrib/examples/walkthrough/ups-instance.yaml" \
kubectl create -f "${ROOT}/contrib/examples/walkthrough/ups-instance.yaml" \
|| error_exit 'Error when creating ups-instance.'

wait_for_expected_output -e 'ProvisionedSuccessfully' \
kubectl --context=service-catalog get serviceinstances -n test-ns ups-instance -o yaml \
kubectl get serviceinstances -n test-ns ups-instance -o yaml \
|| {
kubectl --context=service-catalog get serviceinstances -n test-ns ups-instance -o yaml
kubectl get serviceinstances -n test-ns ups-instance -o yaml
error_exit 'Did not receive expected condition when provisioning ups-instance.'
}

[[ "$(kubectl --context=service-catalog get serviceinstances -n test-ns ups-instance -o yaml)" == *"status: \"True\""* ]] \
[[ "$(kubectl get serviceinstances -n test-ns ups-instance -o yaml)" == *"status: \"True\""* ]] \
|| {
kubectl --context=service-catalog get serviceinstances -n test-ns ups-instance -o yaml
kubectl get serviceinstances -n test-ns ups-instance -o yaml
error_exit 'Failure status reported when attempting to provision ups-instance.'
}

# Bind to the instance

echo 'Binding to instance...'

kubectl --context=service-catalog create -f "${ROOT}/contrib/examples/walkthrough/ups-binding.yaml" \
kubectl create -f "${ROOT}/contrib/examples/walkthrough/ups-binding.yaml" \
|| error_exit 'Error when creating ups-binding.'

wait_for_expected_output -e 'InjectedBindResult' \
kubectl --context=service-catalog get servicebindings -n test-ns ups-binding -o yaml \
kubectl get servicebindings -n test-ns ups-binding -o yaml \
|| {
kubectl --context=service-catalog get servicebindings -n test-ns ups-binding -o yaml
kubectl get servicebindings -n test-ns ups-binding -o yaml
error_exit 'Did not receive expected condition when injecting ups-binding.'
}

[[ "$(kubectl --context=service-catalog get servicebindings -n test-ns ups-binding -o yaml)" == *"status: \"True\""* ]] \
[[ "$(kubectl get servicebindings -n test-ns ups-binding -o yaml)" == *"status: \"True\""* ]] \
|| {
kubectl --context=service-catalog get servicebindings -n test-ns ups-binding -o yaml
kubectl get servicebindings -n test-ns ups-binding -o yaml
error_exit 'Failure status reported when attempting to inject ups-binding.'
}

Expand All @@ -194,7 +194,7 @@ wait_for_expected_output -e 'InjectedBindResult' \

echo 'Unbinding from instance...'

kubectl --context=service-catalog delete -n test-ns servicebindings ups-binding \
kubectl delete -n test-ns servicebindings ups-binding \
|| error_exit 'Error when deleting ups-binding.'

wait_for_expected_output -x -e "ups-binding" \
Expand All @@ -205,20 +205,20 @@ wait_for_expected_output -x -e "ups-binding" \

echo 'Deprovisioning instance...'

kubectl --context=service-catalog delete -n test-ns serviceinstances ups-instance \
kubectl delete -n test-ns serviceinstances ups-instance \
|| error_exit 'Error when deleting ups-instance.'

# Delete the broker

echo 'Deleting broker...'

kubectl --context=service-catalog delete clusterservicebrokers ups-broker \
kubectl delete clusterservicebrokers ups-broker \
|| error_exit 'Error when deleting ups-broker.'

wait_for_expected_output -x -e ${USER_PROVIDED_SERVICE_ID} \
kubectl --context=service-catalog get clusterserviceclasses \
kubectl get clusterserviceclasses \
|| {
kubectl --context=service-catalog get clusterserviceclasses
kubectl get clusterserviceclasses
error_exit 'Service classes not successfully removed upon deleting ups-broker.'
}

Expand Down
26 changes: 17 additions & 9 deletions contrib/svc-cat-apiserver-aggregation-tls-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ export HELM_RELEASE_NAME=${HELM_RELEASE_NAME:-catalog}
export SVCCAT_NAMESPACE=${SVCCAT_NAMESPACE:-catalog}
SVCCAT_SERVICE_NAME=${HELM_RELEASE_NAME}-catalog-apiserver

# The location to create the output files may be customized by setting your
# CERT_FOLDER environment variable to the desired output folder. Leaving this
# blank will create them in the current directory.
#
# NOTE: Must contain a trailing slash. (e.g., CERT_FOLDER="/tmp/certs/")
CERT_FOLDER=${CERT_FOLDER:-}

CA_NAME=ca

ALT_NAMES="\"${SVCCAT_SERVICE_NAME}.${SVCCAT_NAMESPACE}\",\"${SVCCAT_SERVICE_NAME}.${SVCCAT_NAMESPACE}.svc"\"

SVCCAT_CA_SETUP=svc-cat-ca.json
SVCCAT_CA_SETUP=${CERT_FOLDER}svc-cat-ca.json
cat > ${SVCCAT_CA_SETUP} << EOF
{
"hosts": [ ${ALT_NAMES} ],
Expand All @@ -44,19 +51,20 @@ cat > ${SVCCAT_CA_SETUP} << EOF
EOF


cfssl genkey --initca ${SVCCAT_CA_SETUP} | cfssljson -bare ${CA_NAME}
cfssl genkey --initca ${SVCCAT_CA_SETUP} | cfssljson -bare "${CERT_FOLDER}${CA_NAME}"
# now the files 'ca.csr ca-key.pem ca.pem' exist

SVCCAT_CA_CERT=${CA_NAME}.pem
SVCCAT_CA_KEY=${CA_NAME}-key.pem
SVCCAT_CA_CERT="${CERT_FOLDER}${CA_NAME}.pem"
SVCCAT_CA_KEY="${CERT_FOLDER}${CA_NAME}-key.pem"

PURPOSE=server
echo '{"signing":{"default":{"expiry":"43800h","usages":["signing","key encipherment","'${PURPOSE}'"]}}}' > "${PURPOSE}-ca-config.json"
SVCCAT_SERVER_CA_CONFIG="${CERT_FOLDER}${PURPOSE}-ca-config.json"
echo '{"signing":{"default":{"expiry":"43800h","usages":["signing","key encipherment","'${PURPOSE}'"]}}}' > "${SVCCAT_SERVER_CA_CONFIG}"

echo '{"CN":"'${SVCCAT_SERVICE_NAME}'","hosts":['${ALT_NAMES}'],"key":{"algo":"rsa","size":2048}}' \
| cfssl gencert -ca=${SVCCAT_CA_CERT} -ca-key=${SVCCAT_CA_KEY} -config=server-ca-config.json - \
| cfssljson -bare apiserver
| cfssl gencert -ca=${SVCCAT_CA_CERT} -ca-key=${SVCCAT_CA_KEY} -config=${SVCCAT_SERVER_CA_CONFIG} - \
| cfssljson -bare "${CERT_FOLDER}apiserver"

export SC_SERVING_CA=${SVCCAT_CA_CERT}
export SC_SERVING_CERT=apiserver.pem
export SC_SERVING_KEY=apiserver-key.pem
export SC_SERVING_CERT=${CERT_FOLDER}apiserver.pem
export SC_SERVING_KEY=${CERT_FOLDER}apiserver-key.pem

0 comments on commit eba8ba4

Please sign in to comment.