#!/usr/bin/env bash
# Copyright 2025 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

readonly OUTPUT="$(dirname $0)/k8s-staging-perf-tests.yaml"
readonly IMAGES=(
    access-tokens
    containerd
    network/netperfbenchmark
    probes
    request-benchmark
    scratch
    sleep
    watch-list
)

cat >"${OUTPUT}" <<EOF
# Automatically generated by k8s-staging-perf-tests.sh.

postsubmits:
  kubernetes/perf-tests:
EOF

for image in "${IMAGES[@]}"; do
    cat >>"${OUTPUT}" <<EOF
    - name: post-kubernetes-push-perf-tests-${image//\//}
      rerun_auth_config:
        github_team_slugs:
          - org: kubernetes
            slug: sig-scalability-leads
        github_users:
          # TODO: Added for initial testing; remove after the job stabilizes.
          - mkumatag
      cluster: k8s-infra-prow-build-trusted
      annotations:
        testgrid-dashboards: sig-scalability-perf-tests, sig-k8s-infra-gcb
      decorate: true
      # we only need to run if the test images have been changed.
      run_if_changed: '^util-images\/${image//\//\\/}\/'
      branches:
        - ^master$
      spec:
        serviceAccountName: gcb-builder
        containers:
          - image: gcr.io/k8s-staging-test-infra/image-builder:v20250914-3092127382
            command:
              - /run.sh
            args:
              # this is the project GCB will run in, which is the same as the GCR
              # images are pushed to.
              - --project=k8s-staging-perf-tests
              # This is the same as above, but with -gcb appended.
              - --scratch-bucket=gs://k8s-staging-perf-tests-gcb
              - --env-passthrough=WHAT
              - --build-dir=.
              - util-images
            env:
              - name: WHAT
                value: "${image}"
EOF
done
