Skip to content

Commit

Permalink
Provide an error message in case GCP ZONE is not set and exit, also f…
Browse files Browse the repository at this point in the history
…ix styles for kfctl.sh (kubeflow#1888)

* Provide an error message in case GCP ZONE is not set and exit, also fix styles for kfctl.sh

* Provide an error message in case GCP ZONE is not set and exit, also fix styles for kfctl.sh

* provide zone info for kfctl_test.jsonnet as well

* Add parameter option for --zone

* Move the GCP specific flags up under GCP env creation, mandate gcloud specific flags per review if they are not found under gcloud config

* source env.sh prior to calling gcpInitProject

* move check for SKIP_INIT_PROJECT back to main

* Minor style fix

* Fix the missing ENVs during deploy and adding env.sh to .gitignore

* Attempt to make kfct.sh executable

* Fix a typo in .gitignore per review feedback
  • Loading branch information
ashahba authored and k8s-ci-robot committed Nov 5, 2018
1 parent 8315ad3 commit 3ae451b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ examples/.ipynb_checkpoints/

**/.ipynb_checkpoints

# env.sh generated by kfctl.sh
**/env.sh

!testing/test-infra/vendor

Expand Down
147 changes: 89 additions & 58 deletions scripts/kfctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ WHAT=$2

ENV_FILE="env.sh"
SKIP_INIT_PROJECT=false
CLUSTER_VERSION="1.10"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source "${DIR}/util.sh"
Expand Down Expand Up @@ -48,13 +49,64 @@ createEnv() {
echo KUBEFLOW_DOCKER_REGISTRY=registry.aliyuncs.com >> ${ENV_FILE}
;;
gcp)
PROJECT=${PROJECT:-$(gcloud config get-value project 2>/dev/null)}
while [[ $# -gt 0 ]]; do
case $1 in
--project)
shift
PROJECT=$1
;;
--zone)
shift
ZONE=$1
;;
--email)
shift
EMAIL=$1
;;
--skipInitProject)
SKIP_INIT_PROJECT=true
;;
esac
shift
done

echo KUBEFLOW_PLATFORM=gke >> ${ENV_FILE}
echo PROJECT="${PROJECT}" >> ${ENV_FILE}
# GCP Project
if [ -z "${PROJECT}" ]; then
echo PROJECT must be set either using environment variable PROJECT
echo or by setting the default project in gcloud
exit 1
PROJECT=$(gcloud config get-value project 2>/dev/null)
if [ -z "${PROJECT}" ]; then
echo "GCP project must be set either using --project <PROJECT>"
echo "or by setting a default project in gcloud config"
exit 1
fi
fi
echo PROJECT="${PROJECT}" >> ${ENV_FILE}

# GCP Zone
if [ -z "$ZONE" ]; then
ZONE=$(gcloud config get-value compute/zone 2>/dev/null)
if [ -z "$ZONE" ]; then
echo "GCP zone must be set either using --zone <ZONE>"
echo "or by setting a default zone in gcloud config"
exit 1
fi
fi
echo ZONE=${ZONE} >> ${ENV_FILE}

# GCP Email for cert manager
if [ -z "$EMAIL" ]; then
EMAIL=$(gcloud config get-value account 2>/dev/null)
if [ -z "$EMAIL" ]; then
echo "GCP account must be set either using --email <EMAIL>"
echo "or by setting a default account in gcloud config"
exit 1
fi
fi
echo EMAIL=${EMAIL} >> ${ENV_FILE}

# TODO: Do we need to make PROJECT_NUMBER also a flag like --project-number
if [ -z "${PROJECT_NUMBER}" ]; then
PROJECT_NUMBER=$(gcloud projects describe ${PROJECT} --format='value(project_number)')
fi

# Name of the deployment
Expand All @@ -69,16 +121,6 @@ createEnv() {
# Name of the K8s context to create.
echo KUBEFLOW_K8S_CONTEXT=${DEPLOYMENT_NAME} >> ${ENV_FILE}

# GCP Zone
# The default should be a zone that supports Haswell.
ZONE=${ZONE:-$(gcloud config get-value compute/zone 2>/dev/null)}
ZONE=${ZONE:-"us-east1-d"}
echo ZONE=${ZONE} >> ${ENV_FILE}

# Email for cert manager
EMAIL=${EMAIL:-$(gcloud config get-value account 2>/dev/null)}
echo EMAIL=${EMAIL} >> ${ENV_FILE}

# GCP Static IP Name
echo KUBEFLOW_IP_NAME=${KUBEFLOW_IP_NAME:-"${DEPLOYMENT_NAME}-ip"} >> ${ENV_FILE}
# Name of the endpoint
Expand All @@ -89,11 +131,12 @@ createEnv() {

echo CONFIG_FILE=${CONFIG_FILE:-"cluster-kubeflow.yaml"} >> ${ENV_FILE}

if [ -z "${PROJECT_NUMBER}" ]; then
PROJECT_NUMBER=$(gcloud projects describe ${PROJECT} --format='value(project_number)')
fi

echo PROJECT_NUMBER=${PROJECT_NUMBER} >> ${ENV_FILE}

# "1.X": picks the highest valid patch+gke.N patch in the 1.X version
# https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.zones.clusters
echo "Setting cluster version to ${CLUSTER_VERSION}"
echo CLUSTER_VERSION=${CLUSTER_VERSION} >> ${ENV_FILE}
;;
*)
echo KUBEFLOW_PLATFORM=null >> ${ENV_FILE}
Expand All @@ -117,79 +160,67 @@ createNamespace() {
if [ "${COMMAND}" == "init" ]; then
DEPLOYMENT_NAME=${WHAT}

while [[ $# -gt 0 ]]; do
while [[ $# -gt 0 ]]; do
case $1 in
-h | --help)
usage
exit
;;
--platform)
shift
PLATFORM=$1
;;
--project)
shift
PROJECT=$1
;;
--skipInitProject)
SKIP_INIT_PROJECT=true
;;
--email)
shift
EMAIL=$1
;;
esac
shift
-h | --help)
usage
exit
;;
--platform)
shift
PLATFORM=$1
mkdir -p ${DEPLOYMENT_NAME}
# Most commands expect to be executed from the app directory
cd ${DEPLOYMENT_NAME}
createEnv $*
;;
esac
shift
done

mkdir -p ${DEPLOYMENT_NAME}
# Most commands expect to be executed from the app directory
cd ${DEPLOYMENT_NAME}
createEnv
source ${ENV_FILE}
# TODO(jlewi): Should we default to directory name?
# TODO(jlewi): This doesn't work if user doesn't provide name we will end up
# interpreting parameters as the name. To fix this we need to check name doesn't start with --
if [ -z "${DEPLOYMENT_NAME}" ]; then
echo "name must be provided"
echo "usage: kfctl init <name>"
exit 1
echo "name must be provided"
echo "usage: kfctl init <name>"
exit 1
fi
if [ -d ${DEPLOYMENT_NAME} ]; then
echo Directory ${DEPLOYMENT_NAME} already exists
if [ -d ${DEPLOYMENT_NAME} ]; then
echo "Directory ${DEPLOYMENT_NAME} already exists"
exit 1
fi

if [ -z "${PLATFORM}" ]; then
echo "--platform must be provided"
echo "usage: kfctl init <PLATFORM>"
exit 1
echo "--platform must be provided"
echo "usage: kfctl init <PLATFORM>"
exit 1
fi
source "${ENV_FILE}"

# TODO(jlewi): How can we skip GCP project setup? Add a command line argument
# to skip it?
if [ "${PLATFORM}" == "gcp" ]; then
if ${SKIP_INIT_PROJECT}; then
echo skipping project initialization
echo "skipping project initialization"
else
echo initializing project
gcpInitProject
fi
fi

fi

source ${ENV_FILE}

if [ -z "${COMMAND}" ]; then
echo COMMAND must be provided
echo "COMMAND must be provided"
usage
exit 1
fi

if [ -z "${WHAT}" ]; then
echo WHAT must be provided
echo "WHAT must be provided"
usage
exit 1
fi
Expand Down Expand Up @@ -217,7 +248,7 @@ ksApply () {
set -e

if [ "${RESULT}" -eq 0 ]; then
echo environment default already exists
echo "environment default already exists"
else
ks env add default --namespace "${K8S_NAMESPACE}"
fi
Expand Down
2 changes: 2 additions & 0 deletions testing/workflows/components/kfctl_test.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ local dagTemplates = [
"gcp",
"--project",
project,
"--zone",
"us-east1-d",
// Temporary fix for https://github.com/kubeflow/kubeflow/issues/1562
"--skipInitProject",
],
Expand Down

0 comments on commit 3ae451b

Please sign in to comment.