From 22e96a0120685588d7d15a7f3917c92656541d61 Mon Sep 17 00:00:00 2001 From: Jose Carvajal Date: Wed, 1 Apr 2020 16:53:13 +0200 Subject: [PATCH] KOGITO-1606: Add install option in makefile (#249) --- hack/crds-utils.sh | 48 +++++++++++++++++++++++++++++++++ hack/deploy-operator-on-ocp.sh | 49 ++++++++++++++++++++++++++++++++++ hack/run-tests.sh | 35 +----------------------- 3 files changed, 98 insertions(+), 34 deletions(-) create mode 100755 hack/crds-utils.sh create mode 100755 hack/deploy-operator-on-ocp.sh diff --git a/hack/crds-utils.sh b/hack/crds-utils.sh new file mode 100755 index 000000000..309222fd1 --- /dev/null +++ b/hack/crds-utils.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Copyright 2020 Red Hat, Inc. and/or its affiliates +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Script with utils for CRDs resources. + +# Apply CRDs by replacing existing resources or applying if they didn't exist previously. +# Example: apply_crds my_path +function apply_crds(){ + deploy_folder=${1} + files=($deploy_folder/crds/*_crd.yaml) + for file in ${files[@]} + do + echo "Replace crds file ${file}" + oc replace -f ${file} + if [ "$?" != 0 ]; then + echo "crd from file '${file}' may not exist yet in cluster, try to simply apply it" + oc apply -f ${file} + fi + done +} + +# Download CRDs from a URL into a folder. +# Example: download_remote_crds my_path https://path/to/crds. +function download_remote_crds(){ + deploy_folder=${1} + url=${2} + echo "Download crd files into '${deploy_folder}' from ${url}" + + mkdir -p "${deploy_folder}/crds" + files=(deploy/crds/*_crd.yaml) + for file in ${files[@]} + do + filename=${file##*/} + curl -k -o "${deploy_folder}/crds/${filename}" "${url}/crds/${filename}" + done +} \ No newline at end of file diff --git a/hack/deploy-operator-on-ocp.sh b/hack/deploy-operator-on-ocp.sh new file mode 100755 index 000000000..ddbbf1386 --- /dev/null +++ b/hack/deploy-operator-on-ocp.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Copyright 2020 Red Hat, Inc. and/or its affiliates +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# build and deploy the operator into Openshift using our quay account +# 0. Deploy CRDs +# 1. Deploy Roles and Service Account +# 2. Deploy the operator on Openshift + +SCRIPT_DIR=`dirname $0` +IMAGE=$1 +OPERATOR_NAME=kogito-operator +TMP_FOLDER=tmp + +mkdir -p $TMP_FOLDER +rm -rf $TMP_FOLDER/* + +echo "Deploying Operator $OPERATOR_NAME" + +# CRDs +source $SCRIPT_DIR/crds-utils.sh +apply_crds "deploy" + +# Service Account +oc create -f deploy/service_account.yaml + +# Roles +oc create -f deploy/role.yaml +oc create -f deploy/role_binding.yaml + +# Operator +sed "s/name: kogito-operator/name: $OPERATOR_NAME/g" deploy/operator.yaml > $TMP_FOLDER/operator.yaml +sed "s|image: quay.io/kiegroup/.*|image: $IMAGE|g" $TMP_FOLDER/operator.yaml > $TMP_FOLDER/operator-tmp.yaml +oc create -f $TMP_FOLDER/operator-tmp.yaml + +# Clean Up +rm -rf $TMP_FOLDER/* \ No newline at end of file diff --git a/hack/run-tests.sh b/hack/run-tests.sh index 68877cb87..007c14048 100755 --- a/hack/run-tests.sh +++ b/hack/run-tests.sh @@ -13,19 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. - # runs all BDD tests for the operator SCRIPT_NAME=`basename $0` SCRIPT_DIR=`dirname $0` MASTER_RAW_URL=https://raw.githubusercontent.com/kiegroup/kogito-cloud-operator/master/deploy -CRD_FILES_TO_IMPORT=( - "app.kiegroup.org_kogitoapps_crd.yaml" - "app.kiegroup.org_kogitodataindices_crd.yaml" - "app.kiegroup.org_kogitoinfras_crd.yaml" - "app.kiegroup.org_kogitojobsservices_crd.yaml" - "app.kiegroup.org_kogitomgmtconsoles_crd.yaml" - ) function usage(){ printf "Run BDD tests." @@ -88,32 +80,6 @@ function usage(){ printf "\n" } -function download_remote_crds(){ - deploy_folder=${1} - url=${2} - echo "Download crd files into '${deploy_folder}' from ${url}" - - mkdir -p "${deploy_folder}/crds" - for file in ${CRD_FILES_TO_IMPORT[*]} - do - curl -k -o "${deploy_folder}/crds/${file}" "${url}/crds/${file}" - done -} - -function apply_crds(){ - deploy_folder=${1} - for file in ${CRD_FILES_TO_IMPORT[*]} - do - crd_file="${deploy_folder}/crds/${file}" - echo "Replace crds file ${crd_file}" - oc replace -f ${crd_file} - if [ "$?" != 0 ]; then - echo "crd from file '${file}' may not exist yet in cluster, try to simply apply it" - oc apply -f ${crd_file} - fi - done -} - function addParam(){ PARAMS="${PARAMS} ${1}" } @@ -317,6 +283,7 @@ done if ${CRDS_UPDATE}; then echo "-------- Apply CRD files" + source $SCRIPT_DIR/crds-utils.sh deploy_folder="${SCRIPT_DIR}/../deploy" if [[ ! -z "${OPERATOR_DEPLOY_FOLDER}" ]]; then