From 3f32a21fbbd681ceb24e246debaeea45ebcc3350 Mon Sep 17 00:00:00 2001 From: Anand Kumar Singh Date: Wed, 1 Dec 2021 17:30:27 +0530 Subject: [PATCH] setup minikube before env setup (#5265) * setup minikube before env setup Signed-off-by: anandrkskd * install operator only if cluster is recreated Signed-off-by: anandrkskd * update OLM version, and comments Signed-off-by: anandrkskd --- scripts/minikube-minishift-setup-env.sh | 170 ++++++++++++------------ 1 file changed, 86 insertions(+), 84 deletions(-) diff --git a/scripts/minikube-minishift-setup-env.sh b/scripts/minikube-minishift-setup-env.sh index 838469664..5bf6e56d7 100755 --- a/scripts/minikube-minishift-setup-env.sh +++ b/scripts/minikube-minishift-setup-env.sh @@ -6,51 +6,50 @@ shout() { set -x } -# Create a bin directory whereever script runs. This will be where all binaries that need to be in PATH will reside. -export HOME=`pwd`/home -export GOPATH="`pwd`/home/go" -export GOBIN="$GOPATH/bin" -mkdir -p $GOBIN # This si one of the variables injected by ci-firewall. Its purpose is to allow scripts to handle uniqueness as needed SCRIPT_IDENTITY=${SCRIPT_IDENTITY:-"def-id"} -# Add GOBIN which is the bin dir we created earlier to PATH so any binaries there are automatically available in PATH -export PATH=$PATH:$GOBIN +setup_operator() { + SETUP_OPERATORS="./scripts/configure-cluster/common/setup-operators.sh" -# Prep for integration/e2e -shout "Building odo binaries" -make bin + # The OLM Version + LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/operator-framework/operator-lifecycle-manager/releases/latest) + OLM_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') + export OLM_VERSION=${OLM_VERSION:-"v0.17.0"} + # Enable OLM for running operator tests + curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/$OLM_VERSION/install.sh | bash -s $OLM_VERSION -# copy built odo to GOBIN -cp -avrf ./odo $GOBIN/ + # Install Operators for Operator tests + sh $SETUP_OPERATORS +} setup_kubeconfig() { - export KUBECONFIG=$HOME/.kube/config - if [[ ! -f $KUBECONFIG ]]; then - echo "Could not find kubeconfig file" - exit 1 - fi - if [[ ! -z $KUBECONFIG ]]; then - # Copy kubeconfig to current directory, to avoid clashes with other test runs - # Read and Write permission to current kubeconfig file - cp $KUBECONFIG "`pwd`/config" - chmod 640 "`pwd`/config" - export KUBECONFIG="`pwd`/config" - fi + export KUBECONFIG=$HOME/.kube/config + if [[ ! -f $KUBECONFIG ]]; then + echo "Could not find kubeconfig file" + exit 1 + fi + if [[ ! -z $KUBECONFIG ]]; then + # Copy kubeconfig to current directory, to avoid clashes with other test runs + # Read and Write permission to current kubeconfig file + cp $KUBECONFIG "$(pwd)/config" + chmod 640 "$(pwd)/config" + export KUBECONFIG="$(pwd)/config" + fi } setup_minikube_developer() { - pwd=`pwd` - certdir=`mktemp -d` - cd $certdir - shout "Creating a minikube developer user" - openssl genrsa -out developer.key 2048 - openssl req -new -key developer.key -out developer.csr -subj "/CN=developer/O=minikube" - openssl x509 -req -in developer.csr -CA ~/.minikube/ca.crt -CAkey ~/.minikube/ca.key -CAcreateserial -out developer.crt -days 500 - kubectl config set-credentials developer --client-certificate=developer.crt --client-key=developer.key - kubectl config set-context developer-minikube --cluster=minikube --user=developer - # Create role and rolebinding to allow the user necessary access to the cluster; this does not include access to CRD - kubectl create -f - <>>" - exit 1 - ;; + # Create a developer user if it is not created already and change the context to use it after the setup is done + kubectl config get-contexts developer-minikube || setup_minikube_developer + kubectl config use-context developer-minikube + ;; +*) + echo "<<< Need parameter set to minikube or minishift >>>" + exit 1 + ;; esac + +# Create a bin directory whereever script runs. This will be where all binaries that need to be in PATH will reside. +export HOME=$(pwd)/home +export GOPATH="$(pwd)/home/go" +export GOBIN="$GOPATH/bin" +mkdir -p $GOBIN + +# Add GOBIN which is the bin dir we created earlier to PATH so any binaries there are automatically available in PATH +export PATH=$PATH:$GOBIN + +# Prep for integration/e2e +shout "Building odo binaries" +make bin + +# copy built odo to GOBIN +cp -avrf ./odo $GOBIN/ \ No newline at end of file