Skip to content

Commit

Permalink
Merge pull request knative#119 from navidshaikh/pr/serverless-operator
Browse files Browse the repository at this point in the history
Uses serverless operator to setup knative serving
  • Loading branch information
openshift-merge-robot authored Oct 16, 2019
2 parents 22e99a5 + a7b5d46 commit 054a704
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 707 deletions.
193 changes: 120 additions & 73 deletions openshift/e2e-tests-openshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,63 @@ set -x

readonly TEST_NAMESPACE=client-tests
readonly TEST_NAMESPACE_ALT=client-tests-alt
readonly SERVING_RELEASE_BRANCH="release-v0.7.1"
readonly SERVING_RELEASE_TAG="v0.7.1"
readonly SERVING_RELEASE="release-v0.8.1"
readonly KN_DEFAULT_TEST_IMAGE="gcr.io/knative-samples/helloworld-go"
readonly SERVING_NAMESPACE=knative-serving

# The OLM global namespace was moved to openshift-marketplace since v4.2
# ref: https://jira.coreos.com/browse/OLM-1190
if [ ${HOSTNAME} = "e2e-aws-ocp-41" ]; then
readonly OLM_NAMESPACE="openshift-operator-lifecycle-manager"
else
readonly OLM_NAMESPACE="openshift-marketplace"
fi
readonly SERVICEMESH_NAMESPACE=istio-system
readonly OLM_NAMESPACE="openshift-marketplace"

env

function scale_up_workers(){
local cluster_api_ns="openshift-machine-api"

oc get machineset -n ${cluster_api_ns} --show-labels

# Get the name of the first machineset that has at least 1 replica
local machineset=$(oc get machineset -n ${cluster_api_ns} -o custom-columns="name:{.metadata.name},replicas:{.spec.replicas}" | grep " 1" | head -n 1 | awk '{print $1}')
# Bump the number of replicas to 6 (+ 1 + 1 == 8 workers)
oc patch machineset -n ${cluster_api_ns} ${machineset} -p '{"spec":{"replicas":6}}' --type=merge
wait_until_machineset_scales_up ${cluster_api_ns} ${machineset} 6
}

# Waits until the machineset in the given namespaces scales up to the
# desired number of replicas
# Parameters: $1 - namespace
# $2 - machineset name
# $3 - desired number of replicas
function wait_until_machineset_scales_up() {
echo -n "Waiting until machineset $2 in namespace $1 scales up to $3 replicas"
for i in {1..150}; do # timeout after 15 minutes
local available=$(oc get machineset -n $1 $2 -o jsonpath="{.status.availableReplicas}")
if [[ ${available} -eq $3 ]]; then
echo -e "\nMachineSet $2 in namespace $1 successfully scaled up to $3 replicas"
return 0
fi
echo -n "."
sleep 6
done
echo - "\n\nError: timeout waiting for machineset $2 in namespace $1 to scale up to $3 replicas"
return 1
}

# Waits until the given hostname resolves via DNS
# Parameters: $1 - hostname
function wait_until_hostname_resolves() {
echo -n "Waiting until hostname $1 resolves via DNS"
for i in {1..150}; do # timeout after 15 minutes
local output="$(host -t a $1 | grep 'has address')"
if [[ -n "${output}" ]]; then
echo -e "\n${output}"
return 0
fi
echo -n "."
sleep 6
done
echo -e "\n\nERROR: timeout waiting for hostname $1 to resolve via DNS"
return 1
}

# Waits until the given hostname resolves via DNS
# Parameters: $1 - hostname
function wait_until_hostname_resolves() {
Expand Down Expand Up @@ -83,82 +125,76 @@ function timeout() {
return 0
}

function install_knative(){
header "Installing Knative serving"
function install_servicemesh(){
header "Installing ServiceMesh"

create_knative_namespace serving
# Install the ServiceMesh Operator
oc apply -f https://raw.githubusercontent.com/openshift/knative-serving/$SERVING_RELEASE/openshift/servicemesh/operator-install.yaml

echo ">> Patching Knative Serving CatalogSource to reference serving release ${SERVING_RELEASE_BRANCH}"
RELEASE_YAML="https://raw.githubusercontent.com/openshift/knative-serving/${SERVING_RELEASE_BRANCH}/openshift/release/knative-serving-${SERVING_RELEASE_TAG}.yaml"
sed "s|--filename=.*|--filename=${RELEASE_YAML}|" openshift/olm/knative-serving.catalogsource.yaml > knative-serving.catalogsource-ci.yaml
# Wait for the istio-operator pod to appear
timeout 900 '[[ $(oc get pods -n openshift-operators | grep -c istio-operator) -eq 0 ]]' || return 1

# Install CatalogSources in OLM namespace
oc apply -n $OLM_NAMESPACE -f knative-serving.catalogsource-ci.yaml
timeout 900 '[[ $(oc get pods -n $OLM_NAMESPACE | grep -c knative) -eq 0 ]]' || return 1
wait_until_pods_running $OLM_NAMESPACE
# Wait until the Operator pod is up and running
wait_until_pods_running openshift-operators || return 1

# Deploy Knative Operators Serving
deploy_knative_operator serving KnativeServing
# Deploy ServiceMesh
oc new-project $SERVICEMESH_NAMESPACE
oc apply -n $SERVICEMESH_NAMESPACE -f https://raw.githubusercontent.com/openshift/knative-serving/$SERVING_RELEASE/openshift/servicemesh/controlplane-install.yaml
cat <<EOF | oc apply -f -
apiVersion: maistra.io/v1
kind: ServiceMeshMemberRoll
metadata:
name: default
namespace: ${SERVICEMESH_NAMESPACE}
spec:
members:
- ${SERVING_NAMESPACE}
- ${TEST_NAMESPACE}
- ${TEST_NAMESPACE_ALT}
EOF

# Wait for 6 pods to appear first
timeout 900 '[[ $(oc get pods -n $SERVING_NAMESPACE --no-headers | wc -l) -lt 6 ]]' || return 1
wait_until_pods_running knative-serving || return 1
# Wait for the ingressgateway pod to appear.
timeout 900 '[[ $(oc get pods -n $SERVICEMESH_NAMESPACE | grep -c istio-ingressgateway) -eq 0 ]]' || return 1

# Wait for 2 pods to appear first
timeout 900 '[[ $(oc get pods -n istio-system --no-headers | wc -l) -lt 2 ]]' || return 1
wait_until_service_has_external_ip istio-system istio-ingressgateway || fail_test "Ingress has no external IP"
wait_until_service_has_external_ip $SERVICEMESH_NAMESPACE istio-ingressgateway || fail_test "Ingress has no external IP"
wait_until_hostname_resolves "$(kubectl get svc -n $SERVICEMESH_NAMESPACE istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')"

wait_until_hostname_resolves $(kubectl get svc -n istio-system istio-ingressgateway -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
wait_until_pods_running $SERVICEMESH_NAMESPACE

header "Knative serving Installed successfully"
header "ServiceMesh installed successfully"
}

function create_knative_namespace(){
local COMPONENT="knative-$1"
function install_knative_serving(){
header "Installing Knative serving"

cat <<-EOF | oc apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: ${COMPONENT}
EOF
}
oc new-project $SERVING_NAMESPACE

function deploy_knative_operator(){
local COMPONENT="knative-$1"
local KIND=$2

if oc get crd operatorgroups.operators.coreos.com >/dev/null 2>&1; then
cat <<-EOF | oc apply -f -
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: ${COMPONENT}
namespace: ${COMPONENT}
EOF
fi
cat <<-EOF | oc apply -f -
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: ${COMPONENT}-subscription
generateName: ${COMPONENT}-
namespace: ${COMPONENT}
spec:
source: ${COMPONENT}-operator
sourceNamespace: $OLM_NAMESPACE
name: ${COMPONENT}-operator
channel: alpha
EOF
# Deploy Serverless Operator
deploy_serverless_operator

# Wait for the CRD to appear
timeout 900 '[[ $(oc get crd | grep -c knativeservings) -eq 0 ]]' || return 1

# Install Knative Serving
cat <<-EOF | oc apply -f -
apiVersion: serving.knative.dev/v1alpha1
kind: $KIND
metadata:
name: ${COMPONENT}
namespace: ${COMPONENT}
EOF
apiVersion: serving.knative.dev/v1alpha1
kind: KnativeServing
metadata:
name: knative-serving
namespace: ${SERVING_NAMESPACE}
EOF

# Wait for 6 pods to appear first
timeout 900 '[[ $(oc get pods -n $SERVING_NAMESPACE --no-headers | wc -l) -lt 6 ]]' || return

wait_until_pods_running $SERVING_NAMESPACE || return 1

header "Knative Serving installed successfully"
}

function deploy_serverless_operator(){
oc apply -f openshift/serverless/operator-install.yaml
}

function enable_knative_interaction_with_registry() {
local configmap_name=config-service-ca
Expand Down Expand Up @@ -228,7 +264,7 @@ function wait_until_pods_running() {

function delete_knative_openshift() {
echo ">> Bringing down Knative Serving"
oc delete --ignore-not-found=true -n $OLM_NAMESPACE -f knative-serving.catalogsource-ci.yaml
oc delete --ignore-not-found=true -f openshift/serverless/operator-install.yaml
oc delete --ignore-not-found=true project $SERVING_NAMESPACE
}

Expand All @@ -238,8 +274,15 @@ function delete_test_namespace(){
oc delete project $TEST_NAMESPACE_ALT
}

function delete_service_mesh(){
echo ">> Bringin down Service Mesh"
oc delete --ignore-not-found=true -n $SERVICEMESH_NAMESPACE -f https://raw.githubusercontent.com/openshift/knative-serving/$SERVING_RELEASE/openshift/servicemesh/controlplane-install.yaml
oc delete --ignore-not-found=true -f https://raw.githubusercontent.com/openshift/knative-serving/$SERVING_RELEASE/openshift/servicemesh/operator-install.yaml
}

function teardown() {
delete_test_namespace
delete_service_mesh
delete_knative_openshift
}

Expand All @@ -253,13 +296,17 @@ cat /sys/fs/cgroup/cpu/cpu.cfs_period_us
echo ">> - cpu.cfs_quota_us"
cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us

scale_up_workers || exit 1

create_test_namespace || exit 1

failed=0

(( !failed )) && build_knative_client || failed=1

(( !failed )) && install_knative || failed=1
(( !failed )) && install_servicemesh || failed=1

(( !failed )) && install_knative_serving || failed=1

(( !failed )) && run_e2e_tests || failed=1

Expand Down
49 changes: 0 additions & 49 deletions openshift/olm/README.md

This file was deleted.

Loading

0 comments on commit 054a704

Please sign in to comment.