diff --git a/.github/workflows/backstage-lint.yaml b/.github/workflows/backstage-lint.yaml new file mode 100644 index 00000000..ea3d1c8d --- /dev/null +++ b/.github/workflows/backstage-lint.yaml @@ -0,0 +1,35 @@ +name: Backstage lint + +on: + pull_request: + branches: + - 'release-*' + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version-file: 'backstage/.nvmrc' + cache: 'yarn' + cache-dependency-path: 'backstage/yarn.lock' + + - name: Print environment + run: | + node --version + yarn --version + + - name: Install dependencies + shell: bash + working-directory: ./backstage + run: yarn --prefer-offline --frozen-lockfile + + - name: Lint all code + shell: bash + working-directory: ./backstage + run: yarn backstage-cli repo lint diff --git a/.github/workflows/backstage-unit-tests.yaml b/.github/workflows/backstage-unit-tests.yaml new file mode 100644 index 00000000..c0f262cb --- /dev/null +++ b/.github/workflows/backstage-unit-tests.yaml @@ -0,0 +1,39 @@ +name: Backstage unit tests + +on: + pull_request: + branches: + - 'release-*' + +jobs: + unit-tests: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version-file: 'backstage/.nvmrc' + cache: 'yarn' + cache-dependency-path: 'backstage/yarn.lock' + + - name: Print environment + run: | + node --version + yarn --version + + - name: Install dependencies + shell: bash + working-directory: ./backstage + run: yarn --prefer-offline --frozen-lockfile + + - name: Run tests + shell: bash + working-directory: ./backstage + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn test + diff --git a/.github/workflows/go-unit-tests.yaml b/.github/workflows/go-unit-tests.yaml new file mode 100644 index 00000000..f3206684 --- /dev/null +++ b/.github/workflows/go-unit-tests.yaml @@ -0,0 +1,24 @@ +name: Go unit tests + +on: + pull_request: + branches: + - 'release-*' + +jobs: + build: + name: go unit tests + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Test + run: | + go test -v -race ./... diff --git a/.github/workflows/release-plugins.yaml b/.github/workflows/release-plugins.yaml new file mode 100644 index 00000000..544115b8 --- /dev/null +++ b/.github/workflows/release-plugins.yaml @@ -0,0 +1,170 @@ +name: Backstage plugin release + +on: + pull_request: + branches: + - 'release-*' + paths: + - 'backstage/plugins/knative-event-mesh-backend/**' + push: + branches: + - 'release-*' + # Do not run on push to release-next branch. We don't want to publish the plugin on every push to release-next. + # It might be okay to do so, but sobranch tool doesn't work well with release-next branch name. + - '!release-next' +# Ideally, we would want to only publish the plugin on NPM when there's an actual code change in the plugin. +# However, using the path filters block workflow execution on initial branch creation. +# So, let's publish on every push to a release branch. +# see https://github.com/openshift-knative/backstage-plugins/pull/15#issuecomment-2333324099 +# paths: +# - 'backstage/plugins/knative-event-mesh-backend/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + release: + name: Release + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: dorny/paths-filter@v3 + id: changes + with: + filters: | + event_mesh_plugin: + - 'backstage/plugins/knative-event-mesh-backend/**' + + - name: Setup Golang + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Checkout openshift-knative/hack + uses: actions/checkout@v4 + with: + repository: 'openshift-knative/hack' + ref: 'main' + path: ./src/github.com/openshift-knative/hack + + - name: Install sobranch + run: | + go install ./cmd/sobranch + working-directory: ./src/github.com/openshift-knative/hack + + - name: Setup release name for release branch push + # do not run the step on PRs against release-next branch. run it on: + # PRs against release-* branches, push to release-* branches, and creation of release-* branches + if: github.event.created || steps.changes.outputs.event_mesh_plugin == 'true' + run: | + BRANCH=$(git rev-parse --abbrev-ref HEAD) #e.g. release-v1.33 + echo "Release branch: ${BRANCH}" + + SO_RELEASE_NAME=$( $(go env GOPATH)/bin/sobranch --upstream-version "${BRANCH}") # input format: "release-v1.11" or "release-1.11" or "v1.11" or "1.11" + # SO_RELEASE_NAME will be something like "release-1.33" + echo "SO_RELEASE_NAME: ${SO_RELEASE_NAME}" + + # split the release name to get the version number + ## e.g. release-1.33 -> 1.33 + BASE_RELEASE_VERSION=${SO_RELEASE_NAME#*-} + echo "BASE_RELEASE_VERSION: ${BASE_RELEASE_VERSION}" + + RELEASE_NAME="${BASE_RELEASE_VERSION}.0" + + EXISTING_RELEASES="" + + if EXISTING_RELEASES=$(npm view @openshift-knative/plugin-knative-event-mesh-backend versions --json); then + echo "Package information fetched successfully" + echo "Existing releases: ${EXISTING_RELEASES}" + PATCH_RELEASES=$(echo "${EXISTING_RELEASES}" | grep ${BASE_RELEASE_VERSION}) + if [ -z "${PATCH_RELEASES}" ]; then + echo "No existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}" + echo "Going to publish a new .0 patch release" + RELEASE_NAME="${BASE_RELEASE_VERSION}.0" + else + echo "Existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}" + PATCH=$(echo "${PATCH_RELEASES}" | tail -1 | tr -d '"' | awk -F \. '{print $3+1}') + RELEASE_NAME="${BASE_RELEASE_VERSION}.${PATCH}" + fi + else + echo "Error fetching package information. Going to publish a new .0 patch release" + RELEASE_NAME="${BASE_RELEASE_VERSION}.0" + fi + + echo "RELEASE_NAME: ${RELEASE_NAME}" + echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_ENV + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version-file: 'backstage/.nvmrc' + cache: 'yarn' + cache-dependency-path: 'backstage/yarn.lock' + + - name: Print environment + run: | + node --version + yarn --version + + - name: Install dependencies + shell: bash + working-directory: ./backstage + run: yarn --prefer-offline --frozen-lockfile + + - name: Install tooling + shell: bash + working-directory: ./backstage + run: npm install @backstage/cli -g + + - name: Run tests + shell: bash + working-directory: ./backstage + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn test + + - name: Build + shell: bash + working-directory: ./backstage + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn tsc + yarn build:all + + - name: Update version of knative-event-mesh-backend plugin + # do not run the step on PRs against release-next branch. run it on: + # PRs against release-* branches, push to release-* branches, and creation of release-* branches + if: github.event.created || steps.changes.outputs.event_mesh_plugin == 'true' + shell: bash + working-directory: ./backstage/plugins/knative-event-mesh-backend + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn version --new-version ${RELEASE_NAME} --no-git-tag-version + + - name: Prepack knative-event-mesh-backend plugin + shell: bash + working-directory: ./backstage/plugins/knative-event-mesh-backend + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn prepack + + - name: Publish knative-event-mesh-backend plugin + uses: JS-DevTools/npm-publish@v3 + # do not run the step on PRs against release-next branch. run it on: + # PRs against release-* branches, push to release-* branches, and creation of release-* branches + if: github.event.created || steps.changes.outputs.event_mesh_plugin == 'true' + with: + token: ${{ secrets.NPM_TOKEN }} + access: public + package: backstage/plugins/knative-event-mesh-backend + tag: latest + + - name: Postpack knative-event-mesh-backend plugin + shell: bash + working-directory: ./backstage/plugins/knative-event-mesh-backend + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn postpack diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..661c7f00 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +#This makefile is used by ci-operator + +CGO_ENABLED=0 +GOOS=linux +BRANCH= +TEST= +IMAGE= +TEST_IMAGE_TAG ?= latest + + +test-e2e: + ./openshift/e2e-tests.sh +.PHONY: test-e2e + +# Generate an aggregated knative release yaml file, as well as a CI file with replaced image references +generate-release: + ./openshift/release/generate-release.sh +.PHONY: generate-release diff --git a/OWNERS b/OWNERS index f3ea797e..e0466c2e 100644 --- a/OWNERS +++ b/OWNERS @@ -1,11 +1,8 @@ -# Sponsored by the Eventing WG -# At least one WG lead from https://github.com/knative/community/blob/main/working-groups/WORKING-GROUPS.md#eventing -# must be in the "approvers" list. +# The OWNERS file is used by prow to automatically merge approved PRs. + approvers: -- technical-oversight-committee -- knative-release-leads -- eventing-writers -- backstage-plugins-writers +- eventing-approvers reviewers: -- backstage-plugins-reviewers +- eventing-reviewers + diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES index 6b1caaa5..0ce6c203 100644 --- a/OWNERS_ALIASES +++ b/OWNERS_ALIASES @@ -1,249 +1,15 @@ -# This file is auto-generated from peribolos. -# Do not modify this file, instead modify peribolos/knative-extensions.yaml - aliases: - autoscaler-keda-approvers: - - ReToCode - - skonto - backstage-plugins-reviewers: + eventing-approvers: - aliok - - cali0707 - - leo6leo + - creydr + - matzew - pierdipi - backstage-plugins-writers: - - aliok - - cali0707 - leo6leo - - pierdipi - client-wg-leads: - - dsimansk - - rhuss - client-writers: - - dsimansk - - rhuss - discovery-approvers: - - lberk - docs-writers: - - csantanapr - - retocode - - skonto - eventing-autoscaler-keda-approvers: [] - eventing-awssqs-approvers: - - lberk - - matzew - eventing-ceph-approvers: - - lberk - - matzew - eventing-couchdb-approvers: - - lberk - - lionelvillard - - matzew - eventing-github-approvers: - - lberk - - matzew - eventing-gitlab-approvers: - - lberk - - matzew - - sebgoa - eventing-kafka-approvers: - - aliok - - lberk - - matzew - - pierDipi - eventing-kafka-broker-approvers: - - aliok - - matzew - - pierDipi - eventing-kafka-broker-reviewers: - - Leo6Leo - cali0707 - eventing-kafka-writers: [] - eventing-natss-approvers: - - astelmashenko - - dan-j - eventing-prometheus-approvers: - - lberk - - matzew - eventing-rabbitmq-approvers: - - Zerpet - - ikavgo - - mkuratczyk - eventing-redis-approvers: - - aavarghese - - lionelvillard - - matzew eventing-reviewers: - - Leo6Leo - - cali0707 - - creydr - eventing-wg-leads: - - pierDipi - eventing-writers: - - Leo6Leo - aliok - - cali0707 - creydr - - lionelvillard - - matzew - - pierDipi - func-tastic-approvers: - - lance - - lkingland - - matejvasek - - nainaz - - salaboy - functastic-writers: - - lance - - lkingland - - matejvasek - matzew - - nainaz - - salaboy - function-runtime-approvers: - - lance - - lkingland - - matejvasek - - matzew - - nainaz - - salaboy - function-runtime-writers: - - lance - - lkingland - - matejvasek - - matzew - - nainaz - - salaboy - homebrew-kn-plugins-approvers: - - dsimansk - - rhuss - kn-plugin-admin-approvers: - - dsimansk - - rhuss - kn-plugin-event-approvers: - - cardil - - rhuss - kn-plugin-operator-approvers: - - dsimansk - - houshengbo - - rhuss - kn-plugin-quickstart-approvers: - - dsimansk - - psschwei - - rhuss - kn-plugin-sample-approvers: - - dsimansk - - rhuss - kn-plugin-service-log-approvers: - - rhuss - kn-plugin-source-kafka-approvers: - - daisy-ycguo - - dsimansk - - rhuss - kn-plugin-source-kamelet-approvers: - - christophd - - rhuss - knative-admin: - - aliok - - cardil - - davidhadas - - dprotaso - - dsimansk - - evankanderson - - knative-automation - - knative-prow-releaser-robot - - knative-prow-robot - - knative-prow-updater-robot - - knative-test-reporter-robot - - nainaz - - psschwei - - retocode - - salaboy - - skonto - - upodroid - knative-release-leads: - - dsimansk - - retocode - - skonto - knative-robots: - - knative-automation - - knative-prow-releaser-robot - - knative-prow-robot - - knative-prow-updater-robot - - knative-test-reporter-robot - net-contour-approvers: - - KauzClay - - dprotaso - net-gateway-api-approvers: - - dprotaso - net-http01-approvers: [] - net-istio-approvers: - - skonto - net-kourier-approvers: - - skonto - operations-wg-leads: - - houshengbo - operations-writers: - - dprotaso - - houshengbo - - upodroid - productivity-leads: - - cardil - - upodroid - productivity-wg-leads: - - cardil - - upodroid - productivity-writers: - - cardil - - upodroid - security-guard-approvers: - - davidhadas - - psschwei - - rhuss - security-wg-leads: - - davidhadas - - evankanderson - security-writers: - - davidhadas - - evankanderson - serving-approvers: - - ReToCode - - skonto - serving-progressive-rollout-approvers: - - alexagriffith - - houshengbo - - sukumargaonkar - - yuzisun - serving-reviewers: - - izabelacg - - retocode - - skonto - serving-triage: - - izabelacg - - retocode - - skonto - serving-wg-leads: - - dprotaso - serving-writers: - - ReToCode - - dprotaso - - skonto - steering-committee: - - aliok - - davidhadas - - dprotaso - - dsimansk - - evankanderson - - nainaz - - psschwei - - salaboy - technical-oversight-committee: [] - ux-wg-leads: - - cali0707 + - pierdipi - leo6leo - - mmejia02 - - zainabhusain227 - ux-writers: - cali0707 - - leo6leo - - mmejia02 - - zainabhusain227 diff --git a/openshift/ci-operator/build-image/Dockerfile b/openshift/ci-operator/build-image/Dockerfile new file mode 100755 index 00000000..eae243c9 --- /dev/null +++ b/openshift/ci-operator/build-image/Dockerfile @@ -0,0 +1,26 @@ +# DO NOT EDIT! Generated Dockerfile. + +FROM registry.ci.openshift.org/ocp/4.17:cli-artifacts as tools + +# Dockerfile to bootstrap build and test in openshift-ci +FROM registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.16 as builder + +ARG TARGETARCH + +COPY --from=tools /usr/share/openshift/linux_$TARGETARCH/oc.rhel8 /usr/bin/oc + +RUN ln -s /usr/bin/oc /usr/bin/kubectl + +RUN yum install -y httpd-tools + +RUN wget https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \ + chmod 700 ./get-helm-3 + +RUN ./get-helm-3 --version v3.11.3 --no-sudo && helm version + +RUN GOFLAGS='' go install github.com/mikefarah/yq/v3@latest +RUN GOFLAGS='' go install -tags="exclude_graphdriver_btrfs containers_image_openpgp" github.com/containers/skopeo/cmd/skopeo@v1.16.1 + +# go install creates $GOPATH/.cache with root permissions, we delete it here +# to avoid permission issues with the runtime users +RUN rm -rf $GOPATH/.cache diff --git a/openshift/ci-operator/knative-images/eventmesh/Dockerfile b/openshift/ci-operator/knative-images/eventmesh/Dockerfile new file mode 100755 index 00000000..24bd2b4b --- /dev/null +++ b/openshift/ci-operator/knative-images/eventmesh/Dockerfile @@ -0,0 +1,33 @@ +# DO NOT EDIT! Generated Dockerfile for backends/cmd/eventmesh. +ARG GO_BUILDER=registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.16 +ARG GO_RUNTIME=registry.access.redhat.com/ubi8/ubi-minimal + +FROM $GO_BUILDER as builder + +COPY . . + +ENV CGO_ENABLED=1 +ENV GOEXPERIMENT=strictfipsruntime + +RUN go build -tags strictfipsruntime -o /usr/bin/main ./backends/cmd/eventmesh + +FROM $GO_RUNTIME + +ARG VERSION=knative-v1.16 + +COPY --from=builder /usr/bin/main /usr/bin/eventmesh + +USER 65532 + +LABEL \ + com.redhat.component="openshift-serverless-1-backstage-plugins-eventmesh-rhel8-container" \ + name="openshift-serverless-1/backstage-plugins-eventmesh-rhel8" \ + version=$VERSION \ + summary="Red Hat OpenShift Serverless 1 Backstage Plugins Eventmesh" \ + maintainer="serverless-support@redhat.com" \ + description="Red Hat OpenShift Serverless 1 Backstage Plugins Eventmesh" \ + io.k8s.display-name="Red Hat OpenShift Serverless 1 Backstage Plugins Eventmesh" \ + io.k8s.description="Red Hat OpenShift Serverless Backstage Plugins Eventmesh" \ + io.openshift.tags="eventmesh" + +ENTRYPOINT ["/usr/bin/eventmesh"] diff --git a/openshift/ci-operator/knative-images/migrate/Dockerfile b/openshift/ci-operator/knative-images/migrate/Dockerfile new file mode 100755 index 00000000..a070ce0e --- /dev/null +++ b/openshift/ci-operator/knative-images/migrate/Dockerfile @@ -0,0 +1,33 @@ +# DO NOT EDIT! Generated Dockerfile for vendor/knative.dev/pkg/apiextensions/storageversion/cmd/migrate. +ARG GO_BUILDER=registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.16 +ARG GO_RUNTIME=registry.access.redhat.com/ubi8/ubi-minimal + +FROM $GO_BUILDER as builder + +COPY . . + +ENV CGO_ENABLED=1 +ENV GOEXPERIMENT=strictfipsruntime + +RUN go build -tags strictfipsruntime -o /usr/bin/main ./vendor/knative.dev/pkg/apiextensions/storageversion/cmd/migrate + +FROM $GO_RUNTIME + +ARG VERSION=knative-v1.16 + +COPY --from=builder /usr/bin/main /usr/bin/migrate + +USER 65532 + +LABEL \ + com.redhat.component="openshift-serverless-1-backstage-plugins-migrate-rhel8-container" \ + name="openshift-serverless-1/backstage-plugins-migrate-rhel8" \ + version=$VERSION \ + summary="Red Hat OpenShift Serverless 1 Backstage Plugins Migrate" \ + maintainer="serverless-support@redhat.com" \ + description="Red Hat OpenShift Serverless 1 Backstage Plugins Migrate" \ + io.k8s.display-name="Red Hat OpenShift Serverless 1 Backstage Plugins Migrate" \ + io.k8s.description="Red Hat OpenShift Serverless Backstage Plugins Migrate" \ + io.openshift.tags="migrate" + +ENTRYPOINT ["/usr/bin/migrate"] diff --git a/openshift/ci-operator/knative-test-images/eventshub/Dockerfile b/openshift/ci-operator/knative-test-images/eventshub/Dockerfile new file mode 100755 index 00000000..ad4099b5 --- /dev/null +++ b/openshift/ci-operator/knative-test-images/eventshub/Dockerfile @@ -0,0 +1,33 @@ +# DO NOT EDIT! Generated Dockerfile for vendor/knative.dev/reconciler-test/cmd/eventshub. +ARG GO_BUILDER=registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.16 +ARG GO_RUNTIME=registry.access.redhat.com/ubi8/ubi-minimal + +FROM $GO_BUILDER as builder + +COPY . . + +ENV CGO_ENABLED=1 +ENV GOEXPERIMENT=strictfipsruntime + +RUN go build -tags strictfipsruntime -o /usr/bin/main ./vendor/knative.dev/reconciler-test/cmd/eventshub + +FROM $GO_RUNTIME + +ARG VERSION=knative-v1.16 + +COPY --from=builder /usr/bin/main /usr/bin/eventshub + +USER 65532 + +LABEL \ + com.redhat.component="openshift-serverless-1-backstage-plugins-eventshub-rhel8-container" \ + name="openshift-serverless-1/backstage-plugins-eventshub-rhel8" \ + version=$VERSION \ + summary="Red Hat OpenShift Serverless 1 Backstage Plugins Eventshub" \ + maintainer="serverless-support@redhat.com" \ + description="Red Hat OpenShift Serverless 1 Backstage Plugins Eventshub" \ + io.k8s.display-name="Red Hat OpenShift Serverless 1 Backstage Plugins Eventshub" \ + io.k8s.description="Red Hat OpenShift Serverless Backstage Plugins Eventshub" \ + io.openshift.tags="eventshub" + +ENTRYPOINT ["/usr/bin/eventshub"] diff --git a/openshift/ci-operator/source-image/Dockerfile b/openshift/ci-operator/source-image/Dockerfile new file mode 100755 index 00000000..0bc58d0c --- /dev/null +++ b/openshift/ci-operator/source-image/Dockerfile @@ -0,0 +1,7 @@ +# DO NOT EDIT! Generated Dockerfile. + +FROM src + +RUN chmod +x vendor/k8s.io/code-generator/generate-groups.sh || true +RUN chmod +x vendor/knative.dev/pkg/hack/generate-knative.sh || true +RUN chmod +x vendor/k8s.io/code-generator/generate-internal-groups.sh || true diff --git a/openshift/e2e-tests.sh b/openshift/e2e-tests.sh new file mode 100755 index 00000000..922b9343 --- /dev/null +++ b/openshift/e2e-tests.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# shellcheck disable=SC1090 +source "$(dirname "$0")/../vendor/knative.dev/hack/e2e-tests.sh" + +set -Eeuox pipefail + +env + +failed=0 + +echo "TODO: going to run e2e tests" + +(( failed )) && dump_cluster_state + +(( failed )) && exit 1 + +success diff --git a/openshift/generate.sh b/openshift/generate.sh new file mode 100755 index 00000000..e995fa5e --- /dev/null +++ b/openshift/generate.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -euo pipefail + +repo_root_dir=$(dirname "$(realpath "${BASH_SOURCE[0]}")")/.. + +GOFLAGS='' go install github.com/openshift-knative/hack/cmd/generate@latest + + +$(go env GOPATH)/bin/generate \ + --root-dir "${repo_root_dir}" \ + --generators dockerfile \ + --dockerfile-image-builder-fmt "registry.ci.openshift.org/openshift/release:rhel-8-release-golang-%s-openshift-4.16" diff --git a/openshift/images.yaml b/openshift/images.yaml new file mode 100755 index 00000000..7a2000e4 --- /dev/null +++ b/openshift/images.yaml @@ -0,0 +1,3 @@ +knative.dev/backstage-plugins/backends/cmd/eventmesh: registry.ci.openshift.org/openshift/knative-backstage-plugins-eventmesh:knative-v1.16 +knative.dev/pkg/apiextensions/storageversion/cmd/migrate: registry.ci.openshift.org/openshift/knative-backstage-plugins-migrate:knative-v1.16 +knative.dev/reconciler-test/cmd/eventshub: registry.ci.openshift.org/openshift/knative-backstage-plugins-test-eventshub:knative-v1.16 diff --git a/openshift/project.yaml b/openshift/project.yaml new file mode 100644 index 00000000..b637c728 --- /dev/null +++ b/openshift/project.yaml @@ -0,0 +1,3 @@ +project: + tag: knative-v1.16 + imagePrefix: knative-backstage-plugins diff --git a/openshift/release/artifacts/backstage-plugins-eventmesh-backend.yaml b/openshift/release/artifacts/backstage-plugins-eventmesh-backend.yaml new file mode 100644 index 00000000..5de41198 --- /dev/null +++ b/openshift/release/artifacts/backstage-plugins-eventmesh-backend.yaml @@ -0,0 +1,166 @@ +--- +--- + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: eventmesh-backend + labels: + app.kubernetes.io/version: v1.16 + app.kubernetes.io/component: eventmesh-backend + +rules: + + - apiGroups: + - "" + resources: + # for config-logging and config-leader-election + - configmaps + verbs: + - get + - list + - watch + + # permissions for leader election + - apiGroups: + - "coordination.k8s.io" + resources: + - "leases" + verbs: + - get + - list + - create + - update + - delete + - patch + - watch +--- +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: eventmesh-backend + namespace: knative-eventing + labels: + app.kubernetes.io/version: v1.16 + app.kubernetes.io/component: eventmesh-backend +--- +--- + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: eventmesh-backend + labels: + app.kubernetes.io/version: v1.16 + app.kubernetes.io/component: eventmesh-backend +subjects: + - kind: ServiceAccount + name: eventmesh-backend + namespace: knative-eventing +roleRef: + kind: ClusterRole + name: eventmesh-backend + apiGroup: rbac.authorization.k8s.io +--- +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: eventmesh-backend + namespace: knative-eventing + labels: + app: eventmesh-backend + app.kubernetes.io/version: v1.16 + app.kubernetes.io/component: eventmesh-backend + app.kubernetes.io/name: knative-eventing +spec: + selector: + matchLabels: + app: eventmesh-backend + template: + metadata: + name: eventmesh-backend + labels: + app: eventmesh-backend + app.kubernetes.io/version: v1.16 + app.kubernetes.io/component: eventmesh-backend + app.kubernetes.io/name: knative-eventing + spec: + securityContext: + runAsNonRoot: true + serviceAccountName: eventmesh-backend + + # To avoid node becoming SPOF, spread our replicas to different nodes and zones. + topologySpreadConstraints: + - maxSkew: 2 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + app: eventmesh-backend + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchLabels: + app: eventmesh-backend + topologyKey: kubernetes.io/hostname + weight: 100 + + containers: + - name: controller + image: registry.ci.openshift.org/openshift/knative-v1.16:knative-backstage-plugins-eventmesh + imagePullPolicy: IfNotPresent + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + ports: + - containerPort: 9090 + name: metrics + resources: + requests: + cpu: 100m + memory: 100Mi + terminationMessagePolicy: FallbackToLogsOnError + terminationMessagePath: /dev/termination-log + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + restartPolicy: Always + +--- +apiVersion: v1 +kind: Service +metadata: + name: eventmesh-backend + namespace: knative-eventing + labels: + app: eventmesh-backend + app.kubernetes.io/version: v1.16 + app.kubernetes.io/component: eventmesh-backend + app.kubernetes.io/name: knative-eventing +spec: + ports: + - name: http + port: 8080 + targetPort: 8080 + - name: http-metrics + port: 9090 + targetPort: 9090 + selector: + app: eventmesh-backend diff --git a/openshift/release/create-release-branch.sh b/openshift/release/create-release-branch.sh new file mode 100755 index 00000000..56334c80 --- /dev/null +++ b/openshift/release/create-release-branch.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Usage: create-release-branch.sh v0.4.1 release-0.4 + +set -ex # Exit immediately on error. + +release=$1 +target=$2 + +# Fetch the latest tags and checkout a new branch from the wanted tag. +git fetch upstream -v --tags +git checkout -b "$target" "$release" + +# Remove GH Action hooks from upstream +rm -rf .github/workflows +git commit -sm ":fire: remove unneeded workflows" .github/ + +# Copy the openshift extra files from the OPENSHIFT/main branch. +git fetch openshift main +git checkout openshift/main -- .github/workflows openshift OWNERS OWNERS_ALIASES Makefile + +# There are no patches currently +# git apply openshift/patches/* + +# Generate our OCP artifacts +tag=${target/release-/} +yq write --inplace openshift/project.yaml project.tag "knative-$tag" +make generate-release +git add . +git commit -m "Add openshift specific files." diff --git a/openshift/release/generate-release.sh b/openshift/release/generate-release.sh new file mode 100755 index 00000000..eee7c019 --- /dev/null +++ b/openshift/release/generate-release.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source $(dirname $0)/resolve.sh + +root_dir=$(dirname $0)/../.. + +release=$(yq r openshift/project.yaml project.tag) +release=${release/knative-/} + +echo "Release: $release" + +./openshift/generate.sh + +artifacts_dir="openshift/release/artifacts" +rm -rf $artifacts_dir +mkdir -p $artifacts_dir + +image_prefix="registry.ci.openshift.org/openshift/knative-${release}:knative-backstage-plugins-" +tag="" + +plugins="${artifacts_dir}/backstage-plugins-eventmesh-backend.yaml" + +# EventMesh Backend resources +resolve_resources backends/config/100-eventmesh "${plugins}" "$image_prefix" "$tag" diff --git a/openshift/release/mirror-upstream-branches.sh b/openshift/release/mirror-upstream-branches.sh new file mode 100755 index 00000000..8c5d1494 --- /dev/null +++ b/openshift/release/mirror-upstream-branches.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Usage: openshift/release/mirror-upstream-branches.sh +# This should be run from the basedir of the repo with no arguments + + +set -ex +readonly TMPDIR=$(mktemp -d knativeBackstageBranchingCheckXXXX -p /tmp/) + +git fetch upstream --tags +git fetch openshift --tags + +# We need to seed this with a few releases that, otherwise, would make +# the processing regex less clear with more anomalies +cat >> "$TMPDIR"/midstream_branches < "$TMPDIR"/upstream_branches +git branch --list -a "openshift/release-v1.*" | cut -f3 -d'/' | cut -f2 -d'v' | cut -f1,2 -d'.' >> "$TMPDIR"/midstream_branches + +sort -o "$TMPDIR"/midstream_branches "$TMPDIR"/midstream_branches +sort -o "$TMPDIR"/upstream_branches "$TMPDIR"/upstream_branches +comm -32 "$TMPDIR"/upstream_branches "$TMPDIR"/midstream_branches > "$TMPDIR"/new_branches + +UPSTREAM_BRANCH=$(cat "$TMPDIR"/new_branches) +if [ -z "$UPSTREAM_BRANCH" ]; then + echo "no new branch, exiting" + exit 0 +fi +echo "found upstream branch: $UPSTREAM_BRANCH" +readonly UPSTREAM_TAG="knative-v$UPSTREAM_BRANCH.0" +readonly MIDSTREAM_BRANCH="release-v$UPSTREAM_BRANCH" +openshift/release/create-release-branch.sh "$UPSTREAM_TAG" "$MIDSTREAM_BRANCH" +# we would check the error code, but we 'set -e', so assume we're fine +git push openshift "$MIDSTREAM_BRANCH" diff --git a/openshift/release/resolve.sh b/openshift/release/resolve.sh new file mode 100644 index 00000000..9de74a9d --- /dev/null +++ b/openshift/release/resolve.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +function resolve_resources(){ + echo $@ + + local dir=$1 + local resolved_file_name=$2 + local image_prefix=$3 + local image_tag=${4-""} + + [[ -n $image_tag ]] && image_tag=":$image_tag" + + echo "Writing resolved yaml to $resolved_file_name" + + for yaml in "$dir"/*.yaml; do + echo "Resolving ${yaml}" + + echo "---" >> "$resolved_file_name" + # 1. Prefix test image references with test- + # 2. Rewrite image references + # 3. Remove comment lines + # 4. Remove empty lines + sed -e "s+\(.* image: \)\(knative.dev\)\(.*/\)\(test/\)\(.*\)+\1\2 \3\4test-\5+g" \ + -e "s+ko://++" \ + -e "s+eventing.knative.dev/release: devel+eventing.knative.dev/release: ${release}+" \ + -e "s+app.kubernetes.io/version: devel+app.kubernetes.io/version: ${release}+" \ + -e "s+\(.* image: \)\(knative.dev\)\(.*/\)\(.*\)+\1${image_prefix}\4${image_tag}+g" \ + "$yaml" >> "$resolved_file_name" + done +} diff --git a/openshift/release/update-to-head.sh b/openshift/release/update-to-head.sh new file mode 100755 index 00000000..8733d1dd --- /dev/null +++ b/openshift/release/update-to-head.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# Synchs the ${REPO_BRANCH} branch to main and then triggers CI +# Usage: update-to-head.sh + +set -e +REPO_NAME=$(basename $(git rev-parse --show-toplevel)) +REPO_OWNER_NAME="openshift-knative" +REPO_BRANCH=release-next +REPO_BRANCH_CI="${REPO_BRANCH}-ci" + +# Check if there's an upstream release we need to mirror downstream +openshift/release/mirror-upstream-branches.sh + +# Reset ${REPO_BRANCH} to upstream/main. +git fetch upstream main +git checkout upstream/main -B ${REPO_BRANCH} + +# Remove GH Action hooks from upstream +rm -rf .github/workflows +git commit -sm ":fire: remove unneeded workflows" .github/ + +# Update openshift's main and take all needed files from there. +git fetch openshift main +git checkout openshift/main openshift OWNERS_ALIASES OWNERS Makefile +git add openshift OWNERS_ALIASES OWNERS Makefile +git commit -m ":open_file_folder: Update openshift specific files." + +# There are no patches currently +# Apply patches . +# for p in openshift/patches/* +# do +# echo "Applying patch $p" +# # Apply patches and also add new files, created by the patches +# git apply --index -v $p +#done + +make generate-release +git add openshift +git commit -am ":fire: Apply carried patches." + +git push -f openshift ${REPO_BRANCH} + +# Trigger CI +git checkout ${REPO_BRANCH} -B ${REPO_BRANCH_CI} +date > ci +git add ci +git commit -m ":robot: Triggering CI on branch '${REPO_BRANCH}' after synching to upstream/main" +git push -f openshift ${REPO_BRANCH_CI} + +if hash hub 2>/dev/null; then + # Test if there is already a sync PR in + message=":robot: Triggering CI on branch '${REPO_BRANCH}' after synching to upstream/main" + COUNT=$(hub api -H "Accept: application/vnd.github.v3+json" repos/${REPO_OWNER_NAME}/${REPO_NAME}/pulls --flat \ + | grep -c "${message}") || true + if [ "$COUNT" = "0" ]; then + hub pull-request -m "${message}" --no-edit -l "kind/sync-fork-to-upstream,approved,lgtm" -b ${REPO_OWNER_NAME}/${REPO_NAME}:${REPO_BRANCH} -h ${REPO_OWNER_NAME}/${REPO_NAME}:${REPO_BRANCH_CI} + fi +else + echo "hub (https://github.com/github/hub) is not installed, so you'll need to create a PR manually." +fi