Skip to content

Commit

Permalink
📂 update OpenShift specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
serverless-qe committed May 3, 2024
1 parent eebea9f commit e648046
Show file tree
Hide file tree
Showing 32 changed files with 1,876 additions and 619 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test-e2e-oncluster-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
run: ./hack/allocate.sh
- name: Setup testing images
run: ./hack/setup-testing-images.sh
- name: Install RH pull secrets for KinD cluster
env:
RH_REG_USR: ${{ secrets.RH_REG_USR }}
RH_REG_PWD: ${{ secrets.RH_REG_PWD }}
run: ./hack/install-pull-secrets.sh
- name: Deploy Tekton
run: ./hack/install-tekton.sh
- name: Deploy Test Git Server
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-e2e-oncluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
run: ./hack/allocate.sh
- name: Setup testing images
run: ./hack/setup-testing-images.sh
- name: Install RH pull secrets for KinD cluster
env:
RH_REG_USR: ${{ secrets.RH_REG_USR }}
RH_REG_PWD: ${{ secrets.RH_REG_PWD }}
run: ./hack/install-pull-secrets.sh
- name: Deploy Tekton
run: ./hack/install-tekton.sh
- name: Deploy Test Git Server
Expand Down
1,215 changes: 611 additions & 604 deletions generate/zz_filesystem_generated.go

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions hack/install-pull-secrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

main() {
local -r tmp_docker_config="$(mktemp config.json-XXXXXXXX)"

cat <<EOF > "${tmp_docker_config}"
{
"auths": {
"registry.redhat.io": {
"auth": "$(echo -n "${RH_REG_USR}:${RH_REG_PWD}" | base64 -w0)"
}
}
}
EOF

local node
for node in $(kind get nodes --name "func"); do
tar -cf - "${tmp_docker_config}" --transform="flags=r;s|${tmp_docker_config}|config.json|" | \
docker cp - "${node}:/var/lib/kubelet/"
done
rm "${tmp_docker_config}"
}

main "$@"
85 changes: 85 additions & 0 deletions hack/openshift-pipelines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

# Copyright 2022 The OpenShift Knative Authors
#
# 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.

set -o errexit
set -o nounset
set -o pipefail

# source of tasks (in this case to the project root folder)
source_path=$(dirname $(cd $(dirname $0) && pwd ))

openshift_pipelines() {
echo "Installing Openshift Pipelines..."

PIPELINE_OPERATOR_DEFAULT_CHANNEL=$(oc get packagemanifests openshift-pipelines-operator-rh -n openshift-marketplace -o json | jq '.status.defaultChannel' | tr -d '"')
PIPELINE_OPERATOR_CHANNEL=${PIPELINE_OPERATOR_CHANNEL:-${PIPELINE_OPERATOR_DEFAULT_CHANNEL}}
PIPELINE_TARGET_VERSION=$(oc get packagemanifests openshift-pipelines-operator-rh -n openshift-marketplace -o json | CHANNEL=$PIPELINE_OPERATOR_CHANNEL jq '.status.channels[] | select(.name==env.CHANNEL) | .currentCSV')

echo Channel: $PIPELINE_OPERATOR_CHANNEL Target Version: $PIPELINE_TARGET_VERSION

cat << EOF | oc apply -f -
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-pipelines-operator-rh
namespace: openshift-operators
spec:
channel: $PIPELINE_OPERATOR_CHANNEL
name: openshift-pipelines-operator-rh
source: redhat-operators
sourceNamespace: openshift-marketplace
EOF

}

wait_pipelines_ready() {
echo "Waiting for Openshift Pipeline to get ready..."
rc=1
set +e
for i in $(seq 5); do
oc wait subscription.operators.coreos.com/openshift-pipelines-operator-rh -n openshift-operators --for=jsonpath='{.status.state}'="AtLatestKnown" --timeout=60s && \
oc wait pod --for=condition=Ready --timeout=180s -n openshift-pipelines -l "app=tekton-pipelines-controller" && \
oc wait pod --for=condition=Ready --timeout=180s -n openshift-pipelines -l "app=tekton-pipelines-webhook" && \
rc=0 && break || (echo "Conditions are not matched. Retrying in 10 secs" && sleep 10)
done
set -e
if (( $rc )); then
echo "Installing Openshift pipelines has failed"
exit 1
fi
}

tekton_tasks() {
echo "Creating Pipeline tasks..."
oc apply -f ${source_path}/pkg/pipelines/resources/tekton/task/func-deploy/0.1/func-deploy.yaml
oc apply -f ${source_path}/pkg/pipelines/resources/tekton/task/func-s2i/0.1/func-s2i.yaml
oc apply -f ${source_path}/pkg/pipelines/resources/tekton/task/func-buildpacks/0.1/func-buildpacks.yaml
}

tasks_only=false
if [[ $# -ge 1 && "$1" == "--tasks-only" ]]; then
tasks_only=true
elif [[ $# -ge 1 ]]; then
echo "Unknown parameters, use '--tasks-only' to only install Tekton Tasks"
fi

if [ $tasks_only = false ] ; then
openshift_pipelines
wait_pipelines_ready
fi
tekton_tasks

echo Done
12 changes: 12 additions & 0 deletions openshift/ci-operator/build-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG OCP_VERSION=4.16
ARG GOLANG_VERSION=1.21
FROM registry.ci.openshift.org/ocp/${OCP_VERSION}:tools as tools

FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-${GOLANG_VERSION}-openshift-${OCP_VERSION}

COPY --from=tools /usr/bin/oc /usr/bin/
RUN ln -s /usr/bin/oc /usr/bin/kubectl

# Reset the goflags to avoid the -mod=vendor flag
ENV GOFLAGS=

55 changes: 55 additions & 0 deletions openshift/cluster-prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
#
# Prepare Cluster on Openshift CI
# - Creates testing Namespace
# - Setup Openshift Serverless and Openshift Pipelines
# - Creates Test GitServer service

set -o errexit
set -o nounset
set -o pipefail

BASEDIR=$(dirname "$0")
INSTALL_SERVERLESS="${INSTALL_SERVERLESS:-true}"
INSTALL_PIPELINES="${INSTALL_PIPELINES:-true}"
INSTALL_GITSERVER="${INSTALL_GITSERVER:-true}"
GITSERVER_IMAGE="${GITSERVER_IMAGE:-ghcr.io/jrangelramos/gitserver-unpriv:latest}"

go env
source "$(go run knative.dev/hack/cmd/script e2e-tests.sh)"

# Prepare Namespace
TEST_NAMESPACE="${TEST_NAMESPACE:-knfunc-oncluster-test-$(head -c 128 </dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | fold -w 6 | head -n 1)}"
oc new-project "${TEST_NAMESPACE}" || true
oc project "${TEST_NAMESPACE}"

# Installs Openshift Serverless
if [ "$INSTALL_SERVERLESS" == "true" ] ; then
header "Installing Openshift Serverless"
oc apply -f "${BASEDIR}/deploy/serverless-subscription.yaml"
wait_until_pods_running openshift-serverless

subheader "Installing Serving and Eventing"
oc apply -f "${BASEDIR}/deploy/knative-serving.yaml"
oc apply -f "${BASEDIR}/deploy/knative-eventing.yaml"
oc wait --for=condition=Ready --timeout=10m knativeserving knative-serving -n knative-serving
oc wait --for=condition=Ready --timeout=10m knativeeventing knative-eventing -n knative-eventing
fi

# Installs Openshift Pipelines
if [ "$INSTALL_PIPELINES" == "true" ] ; then
header "Installing Openshift Pipelines"
oc apply -f "${BASEDIR}/deploy/pipelines-subscription.yaml"
wait_until_pods_running openshift-pipelines
fi

# Installs Test Git Server
if [ "$INSTALL_GITSERVER" == "true" ] ; then
header "Installing Test GitServer"
sed "s!_GITSERVER_IMAGE_!${GITSERVER_IMAGE}!g" "${BASEDIR}/deploy/gitserver-service.yaml" > "${BASEDIR}/deploy/gitserver.yaml"
oc apply -f "${BASEDIR}/deploy/gitserver.yaml"
oc wait pod/gitserver --for=condition=Ready --timeout=15s

subheader "Exposing Test GitServer route"
oc expose service gitserver --name=gitserver --port=8080
fi
28 changes: 28 additions & 0 deletions openshift/deploy/gitserver-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Git Server used by OnCluster tests on Openshift CI
# Default Image is ghcr.io/jrangelramos/gitserver-unpriv:latest
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: gitserver
name: gitserver
spec:
containers:
- image: _GITSERVER_IMAGE_
name: user-container
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: gitserver
spec:
type: NodePort
selector:
app: gitserver
ports:
- protocol: TCP
port: 80
targetPort: 8080
14 changes: 14 additions & 0 deletions openshift/deploy/knative-eventing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: knative-eventing
---
apiVersion: operator.knative.dev/v1beta1
kind: KnativeEventing
metadata:
name: knative-eventing
namespace: knative-eventing
spec:
high-availability:
replicas: 1
14 changes: 14 additions & 0 deletions openshift/deploy/knative-serving.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: knative-serving
---
apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
name: knative-serving
namespace: knative-serving
spec:
high-availability:
replicas: 1
12 changes: 12 additions & 0 deletions openshift/deploy/pipelines-subscription.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OpenShift Pipelines subscription
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-pipelines-operator-rh
namespace: openshift-operators
spec:
channel: latest
name: openshift-pipelines-operator-rh
source: redhat-operators
sourceNamespace: openshift-marketplace
24 changes: 24 additions & 0 deletions openshift/deploy/serverless-subscription.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# OpenShift Serverless subscription
---
apiVersion: v1
kind: Namespace
metadata:
name: openshift-serverless
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: serverless-operators
namespace: openshift-serverless
spec: {}
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: serverless-operator
namespace: openshift-serverless
spec:
channel: stable
name: serverless-operator
source: redhat-operators
sourceNamespace: openshift-marketplace
71 changes: 71 additions & 0 deletions openshift/e2e_oncluster_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# 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
#
# https://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.

#
# Runs basic lifecycle E2E tests against kn func cli for a given language/runtime.
# By default it will run e2e tests against 'func' binary, but you can change it to use 'kn func' instead
#
# The following environment variable can be set in order to customize e2e execution:
#
# E2E_USE_KN_FUNC When set to "true" indicates e2e to issue func command using kn cli.
#
# E2E_REGISTRY_URL Indicates a specific registry (i.e: "quay.io/user") should be used. Make sure
# to authenticate to the registry (i.e: docker login ...) prior to execute the script
# By default it uses "ttl.sh" registry
#
# E2E_FUNC_BIN_PATH Path to func binary. Derived by this script when not set
#
# E2E_RUNTIMES List of runtimes (space separated) to execute TestRuntime.
#

set -o errexit
set -o nounset
set -o pipefail

source "$(go run knative.dev/hack/cmd/script e2e-tests.sh)"

pushd "$(dirname "$0")/.."

export BUILD_NUMBER=${BUILD_NUMBER:-$(head -c 128 < /dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | head -c 8)}
export ARTIFACT_DIR="${ARTIFACT_DIR:-$(dirname "$(mktemp -d -u)")/build-${BUILD_NUMBER}}"
export ARTIFACTS="${ARTIFACTS:-${ARTIFACT_DIR}}/kn-func/e2e-oncluster-tests"
mkdir -p "${ARTIFACTS}"

export E2E_REGISTRY_URL="${E2E_REGISTRY_URL:-ttl.sh/knfuncci$(head -c 128 </dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | head -c 6)}"
export E2E_FUNC_BIN_PATH="${E2E_FUNC_BIN_PATH:-$(pwd)/func}"
export E2E_USE_KN_FUNC="false"
export E2E_GIT_SERVER_PODNAME="gitserver"
export E2E_GIT_SERVER_ROUTE_URL="http://$(oc get route gitserver -o jsonpath='{.spec.host}')"
FUNC_REPO_REF="${FUNC_REPO_REF:-openshift-knative/kn-plugin-func}"
FUNC_REPO_BRANCH_REF="${FUNC_REPO_BRANCH_REF:-release-next}"

# Ensure 'func' binary is built
if [[ ! -f "$E2E_FUNC_BIN_PATH" ]]; then
echo "=== building func binary"
env FUNC_REPO_REF=${FUNC_REPO_REF} FUNC_REPO_BRANCH_REF=${FUNC_REPO_BRANCH_REF} make build
fi

# For now, let's skips tests that depends on Podman/Docker on Openshift CI
if [[ "${OPENSHIFT_CI}" == "true" ]] ; then
mv ./test/oncluster/scenario_from-cli-local_test.go ./test/oncluster/scenario_from-cli-local_test.skip
fi

# Execute on cluster tests (s2i only)
echo "=== running e2e oncluster test"
export FUNC_BUILDER="s2i"
export FUNC_INSECURE="true"
go_test_e2e -v -timeout 90m -tags="oncluster" ./test/oncluster/ || fail_test 'kn-func e2e tests'
ret=$?

popd
exit $ret
13 changes: 13 additions & 0 deletions openshift/patches/0001-default-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/pkg/builders/builders.go b/pkg/builders/builders.go
index e172834c..44d00311 100644
--- a/pkg/builders/builders.go
+++ b/pkg/builders/builders.go
@@ -16,7 +16,7 @@ const (
Host = "host"
Pack = "pack"
S2I = "s2i"
- Default = Pack
+ Default = S2I
)

// Known builder names with a pretty-printed string representation
Loading

0 comments on commit e648046

Please sign in to comment.