diff --git a/scripts/README.md b/scripts/README.md index 3c3f489a0d..05b7b44949 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,41 +1,5 @@ # Syncing downstream OLM -All of the staged repositories live in the top level `staging` directory. The versions of each staged dependency are tracked in the [`scripts/tracked`](./tracked) file. +All of the staged repositories live in the top level `staging` directory. -## Setup - -The sync process requires the git-subtree command. See [git subtree](https://github.com/git/git/blob/master/contrib/subtree/INSTALL) for more detailed instructions. - -The local repo also needs to track the upstream remotes in [`scripts/tracked`](./tracked). To add these to your repo, run the `init_remotes` script from the root of your repo: - -```bash -./scripts/init_remotes.sh -``` - -## Syncing with upstream - -To sync a staged dependency with an upstream version, you can use the `pull_upstream.sh` helper script. This adds a staged repo if it is not present and updates it to the provided tag/branch otherwise. The script is run as follows: - -```bash -./scripts/pull_upstream.sh [] -``` - -The ref can be a valid tag or branch on the remote, and defaults to master. A successful run adds a new commit to the current branch, similar to - -```text -1bec1e8bb Sync upstream api v0.6.1 -``` - -Commit history for the staged repositories is not preserved. The latest synced upstream commit for each staged repo can be found in the `./scripts/tracked` file. - -Once the sync is completed, verify it by running the unit tests for the dependencies. - -## Pushing changes upstream - -Changes made to the staged repositories may be pushed upstream by providing specific commit ranges. For this run: - -```bash -./scripts/push_upstream.sh -``` - -This creates a local branch containing from the last synced version of the staged dependency with the specified commits cherry-picked onto it. You can then create a PR from this branch to the required upstream repository. +Note: the process for porting upstream commits downstream is outlined in the [OLM downstreaming guide](https://docs.google.com/document/d/139yXeOqAJbV1ndC7Q4NbaOtzbSdNpcuJan0iemORd3g/edit#). diff --git a/scripts/generate_crds_manifests.sh b/scripts/generate_crds_manifests.sh index c691064051..5b535f35fe 100755 --- a/scripts/generate_crds_manifests.sh +++ b/scripts/generate_crds_manifests.sh @@ -59,11 +59,11 @@ add_ibm_managed_cloud_annotations() { done } -${YQ} merge --inplace -d'*' manifests/0000_50_olm_00-namespace.yaml scripts/namespaces.patch.yaml -${YQ} merge --inplace -d'0' manifests/0000_50_olm_00-namespace.yaml scripts/monitoring-namespace.patch.yaml -${YQ} write --inplace -s scripts/olm-deployment.patch.yaml manifests/0000_50_olm_07-olm-operator.deployment.yaml -${YQ} write --inplace -s scripts/catalog-deployment.patch.yaml manifests/0000_50_olm_08-catalog-operator.deployment.yaml -${YQ} write --inplace -s scripts/packageserver-deployment.patch.yaml manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml +${YQ} merge --inplace -d'*' manifests/0000_50_olm_00-namespace.yaml scripts/patches/namespaces.patch.yaml +${YQ} merge --inplace -d'0' manifests/0000_50_olm_00-namespace.yaml scripts/patches/monitoring-namespace.patch.yaml +${YQ} write --inplace -s scripts/patches/olm-deployment.patch.yaml manifests/0000_50_olm_07-olm-operator.deployment.yaml +${YQ} write --inplace -s scripts/patches/catalog-deployment.patch.yaml manifests/0000_50_olm_08-catalog-operator.deployment.yaml +${YQ} write --inplace -s scripts/patches/packageserver-deployment.patch.yaml manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml mv manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml pkg/manifests/csv.yaml cat << EOF > manifests/image-references @@ -267,7 +267,7 @@ spec: imagePullPolicy: IfNotPresent command: - bin/collect-profiles - args: + args: - -n - openshift-operator-lifecycle-manager - --config-mount-path diff --git a/scripts/init_remotes.sh b/scripts/init_remotes.sh deleted file mode 100755 index fb7cda493b..0000000000 --- a/scripts/init_remotes.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -case "$*" in - *" -h"*|"-h"|*" --help"*|"--help") - echo "Add the remotes in ${repo_list} to the local git repository" - echo "usage: $0" - exit 0 - ;; -esac - -repo_list="$(git rev-parse --show-toplevel)/scripts/tracked" - -while read -r remote_name remote_url; do - if git remote get-url "${remote_name}" &>/dev/null; then - tracked_url=$(git remote get-url "${remote_name}") - if [ "${tracked_url}" != "${remote_url}" ]; then - echo -e "\e[91mremote ${remote_name} present but does not track ${remote_url}\e[0m" - fi - else - git remote add "${remote_name}" "${remote_url}" - fi -done<<<"$(awk '{print $1, $2;}' ${repo_list})" diff --git a/scripts/olm/.build_local.sh.swp b/scripts/olm/.build_local.sh.swp deleted file mode 100644 index 3a47224bce..0000000000 Binary files a/scripts/olm/.build_local.sh.swp and /dev/null differ diff --git a/scripts/olm/build_bare.sh b/scripts/olm/build_bare.sh deleted file mode 100644 index e0520fa02f..0000000000 --- a/scripts/olm/build_bare.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -# Note: run from root -# This is used to start and build services for running e2e tests - -set -e - -if [ -z "$NO_MINIKUBE" ]; then - ps x | grep -q [m]inikube || minikube start --kubernetes-version="v1.11.0" --extra-config=apiserver.v=4 || { echo 'Cannot start minikube.'; exit 1; } - eval $(minikube docker-env) || { echo 'Cannot switch to minikube docker'; exit 1; } - kubectl config use-context minikube - umask 0077 && kubectl config view --minify --flatten --context=minikube > minikube.kubeconfig -fi - -kubectl delete crds --all -kubectl create namespace $(cat $(pwd)/e2e.namespace) diff --git a/scripts/olm/build_local.sh b/scripts/olm/build_local.sh deleted file mode 100755 index 94a9b4cd86..0000000000 --- a/scripts/olm/build_local.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -# Note: run from root -# This is used to start and build services for running e2e tests - -set -e - -[ -x "$(command -v kind)" ] && [[ "$(kubectl config current-context)" =~ ^kind-? ]] && KIND=1 NO_MINIKUBE=1 - -if [ -z "$NO_MINIKUBE" ]; then - pgrep -f "[m]inikube" >/dev/null || minikube start --kubernetes-version="v1.16.4" --extra-config=apiserver.v=4 || { echo 'Cannot start minikube.'; exit 1; } - eval "$(minikube docker-env)" || { echo 'Cannot switch to minikube docker'; exit 1; } - kubectl config use-context minikube -fi - -docker build -f e2e.Dockerfile -t quay.io/operator-framework/olm:local -t quay.io/operator-framework/olm-e2e:local ./bin -docker build -f test/e2e/hang.Dockerfile -t hang:10 ./bin - -if [ -n "$KIND" ]; then - kind load docker-image quay.io/operator-framework/olm:local - kind load docker-image quay.io/operator-framework/olm-e2e:local - kind load docker-image hang:10 -fi diff --git a/scripts/olm/copy_crds.sh b/scripts/olm/copy_crds.sh deleted file mode 100755 index 5d2bf5da44..0000000000 --- a/scripts/olm/copy_crds.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -CRD_PATH="${SCRIPT_ROOT}/crds" - -rm "${SCRIPT_ROOT}"/deploy/chart/crds/*.yaml -for f in "${CRD_PATH}"/*.yaml ; do - echo "copying ${f}" - cp "${f}" "${SCRIPT_ROOT}/deploy/chart/crds/0000_50_olm_00-$(basename "$f" | sed 's/^.*_\([^.]\+\)\.yaml/\1.crd.yaml/')" -done - diff --git a/scripts/olm/generate_fakes.sh b/scripts/olm/generate_fakes.sh deleted file mode 100755 index c041ea2ffc..0000000000 --- a/scripts/olm/generate_fakes.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -export GOFLAGS="-mod=vendor" -repo_root=$(git rev-parse --show-toplevel) -registry_repo=$repo_root/staging/operator-registry - -cd $registry_repo -go generate ./... -cd $repo_root - diff --git a/scripts/olm/generate_manifests.sh b/scripts/olm/generate_manifests.sh deleted file mode 100755 index ab9bdf8bb7..0000000000 --- a/scripts/olm/generate_manifests.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -set -o errexit -set -o nounset -set -o pipefail - -export GOFLAGS="-mod=vendor" -repo_root=$(git rev-parse --show-toplevel) -api_repo="$repo_root/staging/api" -controller_gen="$repo_root/bin/controller-gen" -crd_dir="$repo_root/crds" -yq="go run ./vendor/github.com/mikefarah/yq/v3/" -cd $repo_root - -# Download and build controller-gen -go mod tidy -v && go mod vendor -go build -o $controller_gen $repo_root/vendor/sigs.k8s.io/controller-tools/cmd/controller-gen - -cd $api_repo - -# Create CRDs for new APIs -$controller_gen crd:crdVersions=v1 output:crd:dir=$crd_dir paths=./... - -# Update existing CRDs from type changes -$controller_gen schemapatch:manifests=./crds output:dir=$crd_dir paths=./... - -cd $repo_root -# Add missing defaults in embedded core API schemas -$yq w --inplace "$crd_dir/operators.coreos.com_clusterserviceversions.yaml" 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.spec.properties.containers.items.properties.ports.items.properties.protocol.default' 'TCP' -$yq w --inplace "$crd_dir/operators.coreos.com_clusterserviceversions.yaml" 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.spec.properties.initContainers.items.properties.ports.items.properties.protocol.default' 'TCP' - -# Preserve fields for embedded metadata fields -$yq w --inplace "$crd_dir/operators.coreos.com_clusterserviceversions.yaml" 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.metadata.x-kubernetes-preserve-unknown-fields' 'true' - -# Remove OperatorCondition.spec.overrides[*].lastTransitionTime requirement -$yq d --inplace "$crd_dir/operators.coreos.com_operatorconditions.yaml" 'spec.versions[*].schema.openAPIV3Schema.properties.spec.properties.overrides.items.required(.==lastTransitionTime)' - -# Remove status subresource from the CRD manifests to ensure server-side apply works -for f in $crd_dir/*.yaml; do - $yq d --inplace "$f" 'status' -done - -# Update embedded CRD files. -go generate $crd_dir/... - - -# Copy CRDS manifests -rm "${repo_root}"/deploy/chart/crds/*.yaml -for f in "${crd_dir}"/*.yaml ; do - echo "copying ${f}" - cp "${f}" "${repo_root}/deploy/chart/crds/0000_50_olm_00-$(basename "$f" | sed 's/^.*_\([^.]\+\)\.yaml/\1.crd.yaml/')" -done - diff --git a/scripts/olm/install_bare.sh b/scripts/olm/install_bare.sh deleted file mode 100755 index d1849d0342..0000000000 --- a/scripts/olm/install_bare.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -# Note: run from root dir - -set -e - -if [[ ${#@} < 2 ]]; then - echo "Usage: $0 namespace chart" - echo "* namespace: namespace to install into" - echo "* chart: directory of chart manifests to install" - exit 1 -fi - -namespace=$1 -chart=$2 - -# create OLM resources, minus the running components (they will run locally) -for f in ${chart}/*.yaml -do - if [[ $f == *.configmap.yaml ]] - then - kubectl replace --force -f ${f}; - elif [[ $f == *.deployment.yaml ]] - then - # skip olm and catalog operator deployment - continue - else - kubectl apply -f ${f}; - fi -done diff --git a/scripts/olm/install_local.sh b/scripts/olm/install_local.sh deleted file mode 100755 index 3443984057..0000000000 --- a/scripts/olm/install_local.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -OLM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -source "${OLM_ROOT}/scripts/lib/olm_util.sh" - -set -e - -if [[ ${#@} -ne 2 ]]; then - echo "Usage: $0 namespace chart" - echo "* namespace: namespace to install into" - echo "* chart: directory of chart manifests to install" - exit 1 -fi - -namespace=$1 -chart=$2 - -# create OLM -for f in "${chart}"/*.yaml -do - if [[ $f == *.configmap.yaml ]] - then - kubectl replace --force -f "${f}" - else - kubectl apply -f "${f}" - fi -done - -if ! olm::util::await_olm_ready "${namespace}" ; then - echo "olm failed to become ready" - exit 1 -fi diff --git a/scripts/olm/lib/olm_util.sh b/scripts/olm/lib/olm_util.sh deleted file mode 100755 index 4a56b25ac1..0000000000 --- a/scripts/olm/lib/olm_util.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -olm::util::await_csv_success() { - local namespace="$1" - local csv="$2" - local retries="${3:-50}" - local phase - - echo "awaiting ${namespace}/${csv} csv installation success" - until [[ "${retries}" -le "0" || "${phase:=$(kubectl get csv -n "${namespace}" "${csv}" -o jsonpath='{.status.phase}' 2>/dev/null || echo "missing")}" == "Succeeded" ]]; do - retries=$((retries - 1)) - echo "current phase: ${phase}, remaining attempts: ${retries}" - unset phase - sleep 1 - done - - if [ "${retries}" -le "0" ] ; then - echo "${csv} csv installation unsuccessful" - return 1 - fi - - echo "${csv} csv installation succeeded" -} - -olm::util::await_olm_ready() { - local namespace="$1" - - kubectl rollout status -w deployment/olm-operator --namespace="${namespace}" || return - kubectl rollout status -w deployment/catalog-operator --namespace="${namespace}" || return - olm::util::await_csv_success "${namespace}" "packageserver" 32 || return -} \ No newline at end of file diff --git a/scripts/olm/package_release.sh b/scripts/olm/package_release.sh deleted file mode 100755 index 40b29d5843..0000000000 --- a/scripts/olm/package_release.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -if [[ ${#@} -lt 3 ]]; then - echo "Usage: $0 semver chart values" - echo "* semver: semver-formatted version for this package" - echo "* chart: the directory to output the chart" - echo "* values: the values file" - exit 1 -fi - -version=$1 -chartdir=$2 -values=$3 - -charttmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t charttmpdir) - -charttmpdir=${charttmpdir}/chart - -cp -R deploy/chart/ "${charttmpdir}" -sed -i "s/^[Vv]ersion:.*\$/version: ${version}/" "${charttmpdir}/Chart.yaml" - -mkdir -p "${chartdir}" - -go run -mod=vendor helm.sh/helm/v3/cmd/helm template -n olm -f "${values}" --include-crds --output-dir "${charttmpdir}" "${charttmpdir}" - -cp -R "${charttmpdir}"/olm/{templates,crds}/. "${chartdir}" diff --git a/scripts/olm/run_console_local.sh b/scripts/olm/run_console_local.sh deleted file mode 100755 index 08ccecee8d..0000000000 --- a/scripts/olm/run_console_local.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh - -# Colors definition -readonly RED=$(tput setaf 1) -readonly RESET=$(tput sgr0) -readonly GREEN=$(tput setaf 2) - -# Check if Podman binary exists -verify_podman_binary() { - if hash podman 2>/dev/null; then - POD_MANAGER="podman" - else - POD_MANAGER="docker" - fi -} - -# Add port as 9000:9000 as arg when the SO is MacOS or Win -add_host_port_arg (){ - args="--net=host" - if [ -z "${OSTYPE##*"darwin"*}" ] || uname -r | grep -q 'Microsoft'; then - args="-p 9000:9000" - fi -} - -pull_ocp_console_image (){ - $POD_MANAGER pull quay.io/openshift/origin-console:latest -} - -run_ocp_console_image (){ - secretname=$(kubectl get serviceaccount default --namespace=kube-system -o jsonpath='{.secrets[0].name}') - endpoint=$(kubectl config view -o json | jq '{myctx: .["current-context"], ctxs: .contexts[], clusters: .clusters[]}' | jq 'select(.myctx == .ctxs.name)' | jq 'select(.ctxs.context.cluster == .clusters.name)' | jq '.clusters.cluster.server' -r) - - echo "Using $endpoint" - $POD_MANAGER run -d --rm $args \ - -e BRIDGE_USER_AUTH="disabled" \ - -e BRIDGE_K8S_MODE="off-cluster" \ - -e BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT="$endpoint" \ - -e BRIDGE_K8S_MODE_OFF_CLUSTER_SKIP_VERIFY_TLS=true \ - -e BRIDGE_K8S_AUTH="bearer-token" \ - -e BRIDGE_K8S_AUTH_BEARER_TOKEN="$(kubectl get secret "$secretname" --namespace=kube-system -o template --template='{{.data.token}}' | base64 --decode)" \ - quay.io/openshift/origin-console:latest > /dev/null 2>&1 & -} - -verify_ocp_console_image (){ - # Try for 5 seconds to reach the image - for i in 1 2 3 4 5; do - if [ "$($POD_MANAGER ps -q -f label=io.openshift.build.source-location=https://github.com/openshift/console)" ]; then - container_id="$($POD_MANAGER ps -q -l -f label=io.openshift.build.source-location=https://github.com/openshift/console)" - echo "${GREEN}The OLM is accessible via web console at:${RESET}" - echo "${GREEN}http://localhost:9000/${RESET}" - echo "${GREEN}Press Ctrl-C to quit${RESET}"; - $POD_MANAGER attach "$container_id" - exit 0 - fi - sleep 1 # Wait one second to try again - done - echo "${RED}Unable to run the console locally. May this port is in usage already.${RESET}" - echo "${RED}Check if the OLM is not accessible via web console at: http://localhost:9000/${RESET}" - exit 1 -} - -# Calling the functions -verify_podman_binary -add_host_port_arg -pull_ocp_console_image -run_ocp_console_image -verify_ocp_console_image diff --git a/scripts/olm/run_e2e_bare.sh b/scripts/olm/run_e2e_bare.sh deleted file mode 100755 index 5116feb59d..0000000000 --- a/scripts/olm/run_e2e_bare.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# Note: run from root -# Individual tests can be run by calling ./test/e2e/run_e2e_bare.sh TestName - -set -e - -# run tests -if [ -z "$1" ]; then - test_flags=""; -else - test_flags="-test.run ${1}" -fi - -echo "${test_flags}" -go test -c -tags=bare -mod=mod -v -o e2e-bare github.com/openshift/operator-framework-olm/test/e2e -./e2e-bare -test.v -test.timeout 20m ${test_flags} -kubeconfig=${KUBECONFIG:-minikube.kubeconfig} -namespace=$(cat e2e.namespace) -olmNamespace=operator-lifecycle-manager -dummyImage=hang:10 diff --git a/scripts/olm/run_e2e_docker.sh b/scripts/olm/run_e2e_docker.sh deleted file mode 100755 index 58753ce4c1..0000000000 --- a/scripts/olm/run_e2e_docker.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -# Note: run from root - -set -e - -timestamp=$(date +%s) -namespace="e2e-tests-${timestamp}-$RANDOM" -operator_namespace="$namespace-operator" - -tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'valuetmpdir') -test_e2e_config=${tmpdir}/e2e-values.yaml -cp test/e2e/e2e-values.yaml "$test_e2e_config" - -{ echo "namespace: ${namespace}"; - echo "watchedNamespaces: \"\""; - echo "catalog_namespace: ${namespace}"; - echo "operator_namespace: ${operator_namespace}"; } >> "$test_e2e_config" - -./scripts/package_release.sh 1.0.0 test/e2e/resources "$test_e2e_config" - -function cleanup { - for resource in test/e2e/test-resources/*.yaml; do - [ -e "$resource" ] || continue - echo "Running kubectl delete -f $resource..." - kubectl delete -f "$resource" &> /dev/null || continue - done - rm -rf test/e2e/resources - rm -rf test/e2e/test-resources -} - -function cleanupAndExit { - exitCode=$? - if [ "$exitCode" -ne "0" ]; then - echo "error running tests. logs written to olm.log and catalog.log"; - kubectl -n "${namespace}" logs -l app=alm-operator > olm.log; - kubectl -n "${namespace}" logs -l app=catalog-operator > catalog.log; - kubectl -n "${namespace}" logs -l app=package-server > package.log - fi - cleanup - exit $exitCode -} - -trap cleanupAndExit SIGINT SIGTERM EXIT - -./scripts/install_local.sh "${namespace}" test/e2e/resources - -mkdir -p test/e2e/test-resources -helm template --set namespace="${namespace}" -f test/e2e/e2e-values.yaml test/e2e/chart --output-dir test/e2e/test-resources - -eval "$(minikube docker-env)" || { echo 'Cannot switch to minikube docker'; exit 1; } -kubectl apply -f test/e2e/test-resources/olm-e2e/templates -until kubectl -n "${namespace}" logs job/e2e | grep -v "ContainerCreating"; do echo "waiting for job to run" && sleep 1; done -kubectl -n "${namespace}" logs job/e2e -f - - diff --git a/scripts/olm/run_e2e_local.sh b/scripts/olm/run_e2e_local.sh deleted file mode 100755 index a7e323638e..0000000000 --- a/scripts/olm/run_e2e_local.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -# Note: run from root -# Individual tests can be run by calling ./test/e2e/run_e2e_local.sh TestName - -set -e - -timestamp=$(date +%s) -namespace="e2e-tests-${timestamp}-$RANDOM" -operator_namespace="$namespace-operator" - -tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'valuetmpdir') -test_e2e_config=${tmpdir}/e2e-values.yaml -cp test/e2e/e2e-values.yaml "$test_e2e_config" - -{ echo "namespace: ${namespace}"; - echo "watchedNamespaces: \"\""; - echo "catalog_namespace: ${namespace}"; - echo "operator_namespace: ${operator_namespace}"; } >> "$test_e2e_config" - -./scripts/package_release.sh 1.0.0 test/e2e/resources "$test_e2e_config" - -function cleanup { - for resource in test/e2e/resources/*.yaml; do - [ -e "$resource" ] || continue - echo "Running kubectl delete -f $resource..." - kubectl delete -f "$resource" &> /dev/null || continue - done - rm -rf test/e2e/resources -} - -function cleanupAndExit { - exitCode=$? - if [ "$exitCode" -ne "0" ]; then - echo "error running tests. logs written to olm.log, catalog.log, and package.log"; - kubectl -n "${namespace}" logs -l app=olm-operator > olm.log; - kubectl -n "${namespace}" logs -l app=catalog-operator > catalog.log; - kubectl -n "${namespace}" logs -l app=packageserver > package.log - - # make it obvious if a pod is crashing or has restarted - kubectl get po --all-namespaces - else - cleanup - fi - - exit $exitCode -} - -trap cleanupAndExit SIGINT SIGTERM EXIT - -./scripts/install_local.sh "${namespace}" test/e2e/resources - -# run tests -if [ -z "$1" ]; then - test_flags=""; -else - test_flags="-test.run ${1}" -fi - -echo "${test_flags}" -go test -mod=vendor -count=1 -failfast -tags=local -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 30m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace}-operator -olmNamespace=${namespace} -dummyImage=hang:10 diff --git a/scripts/olm/update_codegen.sh b/scripts/olm/update_codegen.sh deleted file mode 100755 index 5d120fd9a9..0000000000 --- a/scripts/olm/update_codegen.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 The Kubernetes 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 - -SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. -CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} - -# create a temporary directory to generate code in and ensure we clean it up on exit -OUTPUT_BASE=$(mktemp -d) -trap 'rm -rf "${OUTPUT_BASE}"' ERR EXIT - -ORG="github.com/operator-framework" -STAGING_DIR="${SCRIPT_ROOT}/staging" -API_MODULE="${STAGING_DIR}/api" -MODULE="${ORG}/operator-framework-olm" - -# generate the code with: -# --output-base because this script should also be able to run inside the vendor dir of -# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir -# instead of the $GOPATH directly. For normal projects this can be dropped. -bash "${CODEGEN_PKG}/generate-groups.sh" "client,lister,informer" \ - "${MODULE}/pkg/api/client" \ - "${API_MODULE}/pkg" \ - "operators:v1alpha1,v1alpha2,v1" \ - --output-base "${OUTPUT_BASE}" \ - --go-header-file "${SCRIPT_ROOT}/boilerplate.go.txt" - -export OPENAPI_EXTRA_PACKAGES="${API_MODULE}/pkg/operators/v1alpha1,${API_MODULE}/pkg/lib/version" -bash "${CODEGEN_PKG}/generate-internal-groups.sh" all \ - "${MODULE}/pkg/package-server/client" \ - "${MODULE}/pkg/package-server/apis" \ - "${MODULE}/pkg/package-server/apis" \ - "operators:v1" \ - --output-base "${OUTPUT_BASE}" \ - --go-header-file "${SCRIPT_ROOT}/boilerplate.go.txt" - -# correct import paths -find "${OUTPUT_BASE}" -type f -print0 | xargs -0 sed -i 's!'"${STAGING_DIR}"'!'"${ORG}"'!' - -# copy the generated resources -cp -R "${OUTPUT_BASE}/${MODULE}/." "${SCRIPT_ROOT}" diff --git a/scripts/olm/update_mockgen.sh b/scripts/olm/update_mockgen.sh deleted file mode 100755 index c36a5dbf14..0000000000 --- a/scripts/olm/update_mockgen.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -# install dependencies -go install -mod=vendor ./vendor/github.com/golang/mock/mockgen -go install -mod=vendor ./vendor/github.com/maxbrunsfeld/counterfeiter/v6 - -SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. -STAGING_DIR="${SCRIPT_ROOT}/staging" -OLM_STAGING_DIR="${STAGING_DIR}/operator-lifecycle-manager" - -# generate fakes and mocks -cd ${OLM_STAGING_DIR} && go generate -mod=vendor ./pkg/... diff --git a/scripts/catalog-deployment.patch.yaml b/scripts/patches/catalog-deployment.patch.yaml similarity index 100% rename from scripts/catalog-deployment.patch.yaml rename to scripts/patches/catalog-deployment.patch.yaml diff --git a/scripts/monitoring-namespace.patch.yaml b/scripts/patches/monitoring-namespace.patch.yaml similarity index 100% rename from scripts/monitoring-namespace.patch.yaml rename to scripts/patches/monitoring-namespace.patch.yaml diff --git a/scripts/namespaces.patch.yaml b/scripts/patches/namespaces.patch.yaml similarity index 100% rename from scripts/namespaces.patch.yaml rename to scripts/patches/namespaces.patch.yaml diff --git a/scripts/olm-deployment.patch.yaml b/scripts/patches/olm-deployment.patch.yaml similarity index 100% rename from scripts/olm-deployment.patch.yaml rename to scripts/patches/olm-deployment.patch.yaml diff --git a/scripts/packageserver-deployment.patch.yaml b/scripts/patches/packageserver-deployment.patch.yaml similarity index 100% rename from scripts/packageserver-deployment.patch.yaml rename to scripts/patches/packageserver-deployment.patch.yaml diff --git a/scripts/pull_upstream.sh b/scripts/pull_upstream.sh deleted file mode 100755 index f3beeea3f1..0000000000 --- a/scripts/pull_upstream.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/bash - -set -E - -case "$*" in - *" -h"*|"-h"|*" --help"*|"--help"|"") - echo "Pull from specified upstream staged repository. Syncs with upstream master if branch isn't specified." - echo "usage: $0 []" - exit 0 - ;; -esac - -if [ $# -lt 1 ]; then - echo "Pull from specified upstream staged repository. Syncs with upstream master if branch isn't specified." - echo "usage: $0 []" - exit 0 -fi - -source "$(dirname $0)/utils.sh" - -remote_url=$(git remote get-url "$1" 2>/dev/null) && remote_name=$1 || remote_url=$1 -if $(git ls-remote "$1" --quiet 2>/dev/null) && [ -z "${remote_name}" ]; then # $1 is a url - # Attempt to get staged remote name from tracked list, default to repository name. - tracked_name=$(cat ${repo_list} | grep " ${remote_url}" | awk '{print $1;}') - tracked_name=${tracked_name:-$(echo "${remote_url}" | sed 's!.*/\([^\/]*\)!\1!' | sed 's/.git$//')} - if [ $(echo "${tracked_name}" | wc -w) -eq 1 ]; then - tracked_url=$(git remote get-url "${tracked_name}" 2>/dev/null) || true - if [ -n "${tracked_url}" ] && [ "${tracked_url}" != "${remote_url}" ]; then - exit_on_error "cannot add ${remote_url}; default remote name ${tracked_name} already tracked by ${tracked_url}" 1 - fi - remote_name="${tracked_name}" - else - exit_on_error "ambiguous remote url ${remote_url} in ${repo_list}, tracked by: ${tracked_name}" 1 - fi -else - if [ -z "${remote_name}" ]; then - remote_name=$1 - remote_url=$(cat "${repo_list}" | grep "^${remote_name} " | awk '{print $2;}') - if [ $(echo "${remote_name}" | wc -w) -ne 1 ]; then - exit_on_error "invalid remote ${remote_name}: not tracked in git or ${repo_list}" 1 - fi - fi - - tracked_url=$(cat "${repo_list}" | grep "^${remote_name} " | awk '{print $2;}') || true - if [ -n "${tracked_url}" ] && [ "${tracked_url}" != "${remote_url}" ]; then - exit_on_error "ambiguous remote ""${remote_name}"": expected: ""${remote_url}""; tracking: ""${tracked_url}" 1 - fi -fi - -if [ -z "${remote_name}" ] || [ -z "${remote_url}" ]; then - exit_on_error "empty remote: ${remote_name}; url: ${remote_url}" 1 -fi - -# track url if not already tracked. -git remote get-url "${remote_name}" 2>/dev/null || \ - git remote add "${remote_name}" "${remote_url}" - -remote_dir="${staging_dir}/${remote_name}" - -tracked_ref=$(cat "${repo_list}" | grep "^${remote_name} " | awk '{print $3;}') -remote_ref=${2:-${tracked_ref:-master}} - -git rev-parse --symbolic-full-name --abbrev-ref HEAD >/dev/null 2>&1 || exit_on_error "invalid ref HEAD, cannot add subtree" $? -git diff-index --quiet HEAD || exit_on_error "Git status not clean, aborting !!\\n\\n$(git status)" $? - -rel_remote_dir="$(realpath --relative-to ${repo_root} ${remote_dir})" -git fetch -t "${remote_name}" "${remote_ref}" -if [ ! -d "$remote_dir" ]; then - #subtree add - git subtree add -q --prefix="${rel_remote_dir}" "${remote_name}" --squash "${remote_ref}" - - new_mod=$(cd ${remote_dir} && go list -m) - sh -c "go mod edit -require ${new_mod}@v0.0.0-00010101000000-000000000000 && \ - go mod edit -replace ${new_mod}=./$(realpath --relative-to ${repo_root} ${remote_dir}) && \ - git add go.mod go.sum" - for staged_dep in $(find "${staging_dir}" -mindepth 1 -maxdepth 1 ! -path "${remote_dir}"); do - staged_mod=$(cd "${staged_dep}" && go list -m -mod=mod) - grep "${staged_mod}" "${remote_dir}/go.mod" | grep -v "^module ${staged_mod}" && sh -c "cd ${remote_dir} && \ - go mod edit -require ${staged_mod}@v0.0.0-00010101000000-000000000000 && \ - go mod edit -replace ${staged_mod}=$(realpath --relative-to ${remote_dir} ${staged_dep})" - grep "${new_mod}" "${staged_dep}/go.mod" | grep -v "^module ${new_mod}" && sh -c "cd ${staged_dep} && \ - go mod edit -require ${new_mod}@v0.0.0-00010101000000-000000000000 && \ - go mod edit -replace ${new_mod}=$(realpath --relative-to ${staged_dep} ${remote_dir}) && \ - go mod tidy -e ; \ - git add go.mod go.sum" - done -else - split_branch="${remote_name}-$(date +%s)" - git subtree split -q --prefix="${rel_remote_dir}" --rejoin -b "${split_branch}" - - git subtree pull -q --squash -m "Sync upstream ${remote_name} ${remote_ref}" --prefix="${rel_remote_dir}" "${remote_name}" "${remote_ref}" - git branch -D "${split_branch}" || true - for staged_dep in $(find "${staging_dir}" -mindepth 1 -maxdepth 1 ! -path "${remote_dir}"); do - staged_mod=$(cd "${staged_dep}" && go list -m -mod=mod) - grep "${staged_mod}" "${remote_dir}/go.mod" | grep -v "^module ${staged_mod}" && sh -c "cd ${remote_dir} && \ - go mod edit -require ${staged_mod}@v0.0.0-00010101000000-000000000000 && \ - go mod edit -replace ${staged_mod}=$(realpath --relative-to ${remote_dir} ${staged_dep})" - done -fi - -sh -c "cd ${remote_dir} && \ - git rm -rq vendor && \ - go mod tidy -e && \ - git add go.mod go.sum" - -# remove nested OWNERS file for openshift CI -git rm "${remote_dir}/OWNERS" - -# find commit for tracked target to write to repo_list -git fetch --tags "${remote_name}" +"${remote_ref}":refs/remotetags/"${remote_name}"/"${remote_ref}" -remote_hash=$(git show-ref remotetags/${remote_name}/${remote_ref} -s) -grep "^${remote_name} " "${repo_list}" && \ - sed -i 's!\('"${remote_name}"' '"${remote_url}"'\).*!\1 '"${remote_ref}"' '"${remote_hash}"'!' "${repo_list}" || \ - echo "${remote_name} ${remote_url} ${remote_ref} ${remote_hash}" >> "${repo_list}" -git add "${repo_list}" "${staging_dir}" - -git commit --amend --no-edit - -FORK_REMOTE=${FORK_REMOTE:-origin} -git diff --dirstat "${current_branch}".."${temp_branch}" - -git checkout "${current_branch}" -git merge --squash -s recursive -X theirs -m "Sync upstream ${remote_name} ${remote_ref}" "${temp_branch}" -git commit -m "Sync upstream ${remote_name} ${remote_ref}" -git branch -D "${temp_branch}" -echo "" -echo "!!! Upstream merge complete!" -echo "" -echo "!!! You can now inspect the branch." -echo "" -echo "!!! Once the changes look good, you can push the changes to the remote repository with:" -echo " git push ${FORK_REMOTE} ${current_branch}" diff --git a/scripts/push_upstream.sh b/scripts/push_upstream.sh deleted file mode 100755 index 8be60019ec..0000000000 --- a/scripts/push_upstream.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash - -if [ $# -lt 2 ]; then - echo "Push a commit range or list to a staged upstream repository" - echo "If provided a ref, it will cherrypick only the commit pointed to" - echo "usage: $0 [...]" - exit 0 -fi - -source "$(dirname $0)/utils.sh" - -remote_name=$1 -remote_dir="${staging_dir}/${remote_name}" - -tracked_ref=$(grep "^${remote_name} " "${repo_list}" | awk '{print $3;}') -remote_ref=${tracked_ref:-master} - -if [ "$remote_dir" = "${staging_dir}/" ] || [ ! -d "${remote_dir}" ]; then - echo "Missing remote from ${repo_list}" - exit 1 -fi - -rel_remote_dir="$(realpath --relative-to ${repo_root} ${remote_dir})" - -git fetch -t "${remote_name}" "${remote_ref}" - -localrev=$(git subtree split --prefix="${rel_remote_dir}") || exit_on_error "failed to create subtree branch" - -refs=" ${@:2:$#} " -mapped_refs="" -cachedir="${repo_root}/.git/subtree-cache/$(ls -t ${repo_root}/.git/subtree-cache/ | head -n 1)" - -st=0 -ln=0 -sst=0 -sln=0 -for i in $(seq 0 $(( ${#refs} - 1 )) ); do - if [[ ${refs:$i:1} =~ [^\ ~:^\.\\] ]]; then - if [ $sln -gt 0 ]; then - mapped_refs="$mapped_refs""${refs:$sst:$sln}" - sln=0 - st=$i - ln=1 - else - ln=$(( ln + 1 )) - fi - else - if [ $ln -gt 0 ]; then - ds_ref="${refs:$st:$ln}" - ds_commit=$(git rev-parse "${ds_ref}") - commit_count=$(ls "${cachedir}/${ds_commit}"* | wc -l) - if [ "${commit_count}" -eq 0 ]; then - exit_on_error "no commit ${ds_commit} found for subtree" - elif [ "${commit_count}" -gt 1 ]; then - exit_on_error "ambiguous ref ${ds_commit}: $(ls ${cachedir}/${ds_commit}*)" - fi - us_commit=$(cat "${cachedir}/${ds_commit}"*) - mapped_refs="${mapped_refs}""${us_commit}" - ln=0 - sst=$i - sln=1 - else - sln=$(( sln + 1 )) - fi - fi -done - -newbranch="${remote_name}-downstream-cherry-pick-$(date "+%s")" - -staged_mods=$(find "${staging_dir}" -mindepth 1 -maxdepth 1 ! -path "${remote_dir}" -exec sh -c "cd {} && go list -m -mod=mod" \;) - -git checkout -b "${newbranch}" "${remote_name}/${remote_ref}" -git branch -D "${temp_branch}" -temp_branch="${newbranch}" -git cherry-pick ${mapped_refs} --strategy recursive -X theirs - -# revert go build files -git checkout "${remote_name}/${remote_ref}" -- OWNERS vendor -go mod edit -dropreplace "${downstream_repo}" -git show "${remote_name}/${remote_ref}":go.mod > ".go.mod.bk" -for mod in ${staged_mods}; do - go mod edit -dropreplace "${mod}" - mod_version=$(grep "${mod}" ".go.mod.bk" | awk '{print $2;}' || true) - if [ -n "${mod_version}" ]; then - go mod edit -require "${mod}@${mod_version}" - else - go mod edit -droprequire "${mod}" - fi -done -go mod tidy && go mod vendor || true # leave vendor errors to be corrected later -rm ".go.mod.bk" -git add go.mod go.sum -git commit --amend --no-edit - -git diff --dirstat "${current_branch}".."${temp_branch}" -printf "\\n\\n!!! Upstream cherry-pick complete!\\n" -echo "!!! You can now inspect the branch." -echo "" -echo "!!! To switch back to your original branch, run:" -echo " git checkout ${current_branch}" -echo "" -echo "!!! Once the changes look good, you can push the changes to the remote repository with:" -echo " git push ${remote_name} ${temp_branch}:" -#git push ${remote_name} ${temp_branch}:"refs/heads/${temp_branch}" - -#cleanup_and_reset_branch - -exit 0 diff --git a/scripts/utils.sh b/scripts/utils.sh deleted file mode 100755 index 18c55579a7..0000000000 --- a/scripts/utils.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -current_branch=$(git symbolic-ref --short HEAD) -repo_root=$(git rev-parse --show-toplevel) -staging_dir="${repo_root}/staging" -scripts_dir="${repo_root}/scripts" -repo_list="${scripts_dir}/tracked" -temp_branch="automated-sync-$(date +%s)" -downstream_repo="github.com/openshift/operator-framework-olm" - -function cleanup_and_reset_branch { - if [ -n ${temp_branch} ]; then - git checkout -f "${current_branch}" >/dev/null 2>&1 || true - git branch -D "${temp_branch}" >/dev/null 2>&1 || true - fi -} - -function exit_on_error { - last="$#" - code=1 - if [ $# -gt 0 ]; then - usr_code=$(eval echo "\${$last}") - if [[ "${usr_code}" =~ ^[0-9]+$ ]]; then - last=$(( $# - 1 )) - code=${usr_code} - fi - fi - if [ -z $code ]; then - return - fi - msg="[ERROR] line $(caller)" - if [ "${last}" -gt -1 ]; then - msg="${msg}: ${@:1:${last}}" - fi - echo -e "\e[91m${msg}\e[0m" - cleanup_and_reset_branch - exit "${code}" -} - -## required for creating automated PRs with hub -#if [[ -z ${GITHUB_USER:-} ]]; then -# exit_on_error "Please export GITHUB_USER= (or GH organization, if that's where your fork lives)" -#fi - -if ! which git > /dev/null; then - exit_on_error "Can't find git in PATH" -fi - -git subtree &>/dev/null || subtree_exit_code=$? -if [ "$subtree_exit_code" -eq 1 ]; then - exit_on_error "installed git version does not support subtree command, please see https://github.com/git/git/tree/master/contrib/subtree" -fi - -if git_status=$(git status --porcelain --untracked=no 2>/dev/null) && [[ -n "${git_status}" ]]; then - exit_on_error "Git status not clean, aborting !!\\n\\n$(git status)" $? - exit 1 -fi - -trap 'exit_on_error "$0:" $?' ERR - -if [[ -e "${repo_root}/.git/rebase-apply" ]]; then - exit_on_error "!!! 'git rebase' or 'git am' in progress, aborting" -fi - -git checkout -b "${temp_branch}" - -if [ ! -f "${repo_list}" ]; then - mkdir -p "${scripts_dir}" && touch "${repo_list}" -fi - -if [ ! -d "${staging_dir}" ]; then - mkdir -p "${staging_dir}" -fi -