From 631b53d2a3bcbe9e817404fd07c44344a360512c Mon Sep 17 00:00:00 2001 From: Mohammed Ahmed Date: Wed, 13 Mar 2019 11:20:34 +0530 Subject: [PATCH] Adding scripts to handle initialization of cluster for openshift CI. (#1441) * Adding scripts to handle initialization of cluster for openshift CI. This also fixes couple of usernames on the side Signed-off-by: Mohammed Zeeshan Ahmed * Adding http-tools to build root so we can use htpasswd * Adding login as developer and creation of first project * Moving script to ./scripts and renaming makefile command * Renaming scripts to incude tests in configure cluster script * Making script more configurable * Adding namespace to secret commands. * Fixing missing username * Simplifying script by removing unnessasary variables * Adding TODO and slightly reduction wait time for auth config * Making assets dir overwritable * Making configure script executable. * Fixing message for not existing kubeconfig * Redirecting out and err of commands where we are not interested in msg * Updating to 18 secs default sleep which can be overridden * Adding workaround for missing wildfly in OpenShift 4.0 * Adding basic ci docs for prow Signed-off-by: Mohammed Zeeshan Ahmed --- Makefile | 4 + docs/ci-reference.md | 12 +++ openshift-ci/build-root/Dockerfile | 2 +- scripts/configure-installer-tests-cluster.sh | 84 ++++++++++++++++++++ tests/e2e/e2e_test.go | 6 +- 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100755 scripts/configure-installer-tests-cluster.sh diff --git a/Makefile b/Makefile index 7dc808dac..c0f25eedf 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,10 @@ generate-cli-reference: prepare-release: cross ./scripts/prepare-release.sh +.PHONY: configure-installer-tests-cluster +configure-installer-tests-cluster: + . ./scripts/configure-installer-tests-cluster.sh + .PHONY: test test: go test -race $(PKGS) diff --git a/docs/ci-reference.md b/docs/ci-reference.md index 2d2ddf798..95470641a 100644 --- a/docs/ci-reference.md +++ b/docs/ci-reference.md @@ -29,3 +29,15 @@ If the need presents itself to run odo integration tests against a specific vers - oc login -u developer - make test-main-e2e ``` + +# How to run integtration tests on Prow + +Prow is the Kubernetes / OpenShift way of managing workflow including tests. To get tests on there, you need to raise PR to openshift/release repository setting up appropriate ci operator config and job files. Reference for same is available there itself. + +However note that prow gives you a bare bones cluster, so we need to preconfigure the same so that the cluster is in state expected such as auth being configured and so on. + +You can do this by running `$ make configure-installer-tests-cluster` before running actual tests. +This script is configurable with environment variables as + + - SLEEP_AFTER_SECRET_CREATION: The time to sleep after auth is configured. Default is 18 seconds + - DEFAULT_INSTALLER_ASSETS_DIR: The location where OpenShift installer creates assets such as kube admin password and the kubeconfig file. \ No newline at end of file diff --git a/openshift-ci/build-root/Dockerfile b/openshift-ci/build-root/Dockerfile index 757836faf..1f0239193 100644 --- a/openshift-ci/build-root/Dockerfile +++ b/openshift-ci/build-root/Dockerfile @@ -2,4 +2,4 @@ FROM registry.svc.ci.openshift.org/openshift/release:golang-1.11 -RUN yum -y install make wget gcc git +RUN yum -y install make wget gcc git httpd-tools diff --git a/scripts/configure-installer-tests-cluster.sh b/scripts/configure-installer-tests-cluster.sh new file mode 100755 index 000000000..6e5f26a6f --- /dev/null +++ b/scripts/configure-installer-tests-cluster.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# Setup to find nessasary data from cluster setup +## Constants +HTPASSWD_FILE="./htpass" +USERPASS="developer" +HTPASSWD_SECRET="htpasswd-secret" +# Overrideable information +DEFAULT_INSTALLER_ASSETS_DIR=${DEFAULT_INSTALLER_ASSETS_DIR:-$(pwd)} +KUBEADMIN_USER=${KUBEADMIN_USER:-"kubeadmin"} +KUBEADMIN_PASSWORD_FILE=${KUBEADMIN_PASSWORD_FILE:-"${DEFAULT_INSTALLER_ASSETS_DIR}/auth/kubeadmin-password"} +SLEEP_AFTER_SECRET_CREATION=${SLEEP_AFTER_SECRET_CREATION:-18} +# Exported to current env +export KUBECONFIG=${KUBECONFIG:-"${DEFAULT_INSTALLER_ASSETS_DIR}/auth/kubeconfig"} + +# List of users to create +USERS="developer odonoprojectattemptscreateproject odosingleprojectattemptscreate odologinnoproject odologinsingleproject1" + +# Check if nessasary files exist +if [ ! -f $KUBEADMIN_PASSWORD_FILE ]; then + echo "Could not find kubeadmin password file" + exit 1 +fi + +if [ ! -f $KUBECONFIG ]; then + echo "Could not find kubeconfig file" + exit 1 +fi + +# Get kubeadmin password from file +KUBEADMIN_PASSWORD=`cat $KUBEADMIN_PASSWORD_FILE` + +# Remove existing htpasswd file, if any +if [ -f $HTPASSWD_FILE ]; then + rm -rf $HTPASSWD_FILE +fi + +# Set so first time -c parameter gets applied to htpasswd +HTPASSWD_CREATED=" -c " + +# Create htpasswd entries for all listed users +for i in `echo $USERS`; do + htpasswd -b $HTPASSWD_CREATED $HTPASSWD_FILE $i $USERPASS + HTPASSWD_CREATED="" +done + +# Login as admin user +oc login -u $KUBEADMIN_USER -p $KUBEADMIN_PASSWORD + +# Workarounds - Note we should find better soulutions asap +## Missing wildfly in OpenShift Adding it manually to cluster Please remove once wildfly is again visible +oc apply -n openshift -f https://raw.githubusercontent.com/openshift/library/master/arch/x86_64/community/wildfly/imagestreams/wildfly-centos7.json + +# Create secret in cluster, removing if it already exists +oc get secret $HTPASSWD_SECRET -n openshift-config &> /dev/null +if [ $? -eq 0 ]; then + oc delete secret $HTPASSWD_SECRET -n openshift-config &> /dev/null +fi +oc create secret generic ${HTPASSWD_SECRET} --from-file=htpasswd=${HTPASSWD_FILE} -n openshift-config + +# Upload htpasswd as new login config +oc apply -f - <