k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/config/jobs/README.md (about)

     1  # Kubernetes Prow Job Configs
     2  
     3  All prow job configs for [prow.k8s.io] live here.
     4  
     5  They are tested and validated by tests in [`config/tests`](/config/tests)
     6  
     7  ## Job Cookbook
     8  
     9  This document attempts to be a step-by-step, copy-pastable guide to the use
    10  of prow jobs for the Kubernetes project. It may fall out of date. For more
    11  info, it was sourced from the following:
    12  
    13  - [ProwJob docs](https://docs.prow.k8s.io/docs/jobs/)
    14  - [Life of a Prow Job](https://docs.prow.k8s.io/docs/life-of-a-prow-job/)
    15  - [Pod Utilities](https://docs.prow.k8s.io/docs/components/pod-utilities/)
    16  - [How to Test a Prow Job](https://docs.prow.k8s.io/docs/build-test-update/#how-to-test-a-prowjob)
    17  
    18  ### Job Types
    19  
    20  There are three types of prow jobs:
    21  
    22  - **Presubmits** run against code in PRs
    23  - **Postsubmits** run after merging code
    24  - **Periodics** run on a periodic basis
    25  
    26  Please see [ProwJob docs](https://docs.prow.k8s.io/docs/jobs/) for more info
    27  
    28  ### Job Images
    29  
    30  Where possible, we prefer that jobs use images that are pinned to a specific
    31  version, containing only what is needed.
    32  
    33  Some good examples include:
    34  
    35  - [pull-release-unit] uses `golang:1.12` to run `go test ./...`
    36  - [pull-release-notes-lint] uses `node:11` to run `npm ci && npm lint`
    37  - [pull-org-test-all] uses `launcher.gcr.io/google/bazel:0.26.0` to run `bazel test //...`
    38  
    39  Many jobs use `gcr.io/k8s-testimages/foo` images that are built from source in
    40  [`images/`]. Some of these have evolved organically, with way more dependencies
    41  than needed, and will be periodically bumped by PRs. These are sources of
    42  technical debt that are often not very well maintained. Use at your own risk,
    43  eg:
    44  
    45  - [periodic-kubernetes-e2e-packages-pushed] uses `gcr.io/k8s-staging-test-infra/kubekins:latest-master`
    46    to run `./tests/e2e/packages/verify_packages_published.sh` which ends up
    47    running `apt-get` and `yum` commands. Perhaps a `debian` image would be
    48    better.
    49  
    50  ## Job Presets
    51  
    52  Prow supports [Presets](https://docs.prow.k8s.io/docs/jobs/#presets) to define and patch in common
    53  env vars and volumes used for credentials or common job config. Some are
    54  defined centrally in [`config/prow/config.yaml`], while others can be defined in
    55  files here. eg:
    56  
    57  - [`preset-service-account: "true"`] ensures the prowjob has a GCP service
    58    account in a well known location, with well known env vars pointing to it.
    59  - [`preset-pull-kubernetes-e2e: "true"`] sets environment variables to make
    60    kubernetes e2e tests less susceptible to flakes
    61  - [`preset-aws-credentials: "true"`] ensures the prowjob has AWS credentials
    62    for kops tests in a well known location, with an env var pointing to it
    63  - [the default preset with no labels] is used to set the `GOPROXY` env var
    64    for all jobs by default
    65  
    66  ## Secrets
    67  
    68  Prow jobs can use secrets located in the same namespace within the cluster
    69  where the jobs are executed, by using the [same mechanism of
    70  podspec](https://kubernetes.io/docs/concepts/configuration/secret/#using-a-secret).
    71  The secrets used in prow jobs can be source controlled and synced from any major
    72  secret manager provider, such as google secret manager, see
    73  [prow_secret](https://docs.prow.k8s.io/docs/prow-secrets/) for instructions.
    74  
    75  ## Job Examples
    76  
    77  A presubmit job named "pull-community-verify" that will run against all PRs to
    78  kubernetes/community's master branch. It will run `make verify` in a checkout
    79  of kubernetes/community at the PR's HEAD. It will report back to the PR via a
    80  status context named `pull-kubernetes-community`. Its logs and results are going
    81  to end up in GCS under `kubernetes-jenkins/pr-logs/pull/community`. Historical
    82  results will display in testgrid on the `sig-contribex-community` dashboard
    83  under the `pull-verify` tab
    84  
    85  ```yaml
    86  presubmits:
    87    kubernetes/community:
    88    - name: pull-community-verify  # convention: (job type)-(repo name)-(suite name)
    89      annotations:
    90        testgrid-dashboards: sig-contribex-community
    91        testgrid-tab-name: pull-verify
    92      branches:
    93      - master
    94      decorate: true
    95      always_run: true
    96      spec:
    97        containers:
    98        - image: public.ecr.aws/docker/library/golang:1.12.5
    99          command:
   100          - /bin/bash
   101          args:
   102          - -c
   103          # Add GOPATH/bin back to PATH to workaround #9469
   104          - "export PATH=$GOPATH/bin:$PATH && make verify"
   105  ```
   106  
   107  A periodic job named "periodic-cluster-api-provider-aws-test-creds" that will
   108  run every 4 hours against kubernetes-sigs/cluster-api-provider-aws's master
   109  branch. It will run `./scripts/ci-aws-cred-test.sh` in a checkout of the repo
   110  located at `sigs.k8s.io/cluster-api-provider-aws`. The presets it's using will
   111  ensure it has aws credentials and aws ssh keys in well known locations. Its
   112  logs and results are going to end up in GCS under 
   113  `kubernetes-jenkins/logs/periodic-cluster-api-provider-aws-test-creds`.
   114  Historical results will display in testgrid on the `sig-cluster-lifecycle-cluster-api-provider-aws`
   115  dashboard under the `test-creds` tab
   116  
   117  It's using the `kubekins-e2e` image which [isn't recommended](#job-images),
   118  but works for now.
   119  
   120  ```yaml
   121  periodics:
   122  - name: periodic-cluster-api-provider-aws-test-creds
   123    annotations:
   124      testgrid-dashboards: sig-cluster-lifecycle-cluster-api-provider-aws
   125      testgrid-tab-name: test-creds
   126    decorate: true
   127    interval: 4h
   128    labels:
   129      preset-service-account: "true"
   130      preset-aws-ssh: "true"
   131      preset-aws-credential: "true"
   132    extra_refs:
   133    - org: kubernetes-sigs
   134      repo: cluster-api-provider-aws
   135      base_ref: master
   136      path_alias: "sigs.k8s.io/cluster-api-provider-aws"
   137    spec:
   138      containers:
   139      - image: gcr.io/k8s-staging-test-infra/kubekins-e2e:v20240515-17c6d50e24-master
   140        command:
   141        - "./scripts/ci-aws-cred-test.sh"
   142  ```
   143  
   144  ## Adding or Updating Jobs
   145  
   146  1. Find or create the prowjob config file in this directory
   147      - In general jobs for `github.com/org/repo` use `org/repo/filename.yaml`
   148      - For kubernetes/kubernetes we prefer `kubernetes/sig-foo/filename.yaml`
   149      - Ensure `filename.yaml` is unique across the config subdir; prow uses this as a key in its configmap
   150  1. Ensure an [`OWNERS`](https://go.k8s.io/owners) file exists in the directory for job, and has appropriate approvers/reviewers
   151  1. Write or edit the job config (please see [How to configure new jobs](https://docs.prow.k8s.io/docs/jobs/#how-to-configure-new-jobs))
   152  1. Ensure the job is configured to display its results in [testgrid.k8s.io]
   153      - The simple way: add [testgrid annotations]
   154      - Please see the testgrid [documentation](/testgrid/config.md) for more details on configuration options
   155  1. Open a PR with the changes; when it merges [@k8s-ci-robot] will deploy the changes automatically
   156  
   157  ## Deleting Jobs
   158  
   159  1. Find the prowjob config file in this directory
   160  1. Remove the entry for your job; if that was the last job in the file, remove the file
   161  1. If the job had no [testgrid annotations], ensure its [`testgrid/config.yaml`] entries are gone
   162  1. Open a PR with the changes; when it merges [@k8s-ci-robot] will deploy the changes automatically
   163  
   164  ## Testing Jobs
   165  
   166  You can read about how to test changes to ProwJobs both locally and remotely in the [prow documentation](https://docs.prow.k8s.io/docs/build-test-update/#how-to-test-a-prowjob).
   167  
   168  ### Testing Jobs Remotely
   169  
   170  This requires a running instance of prow. In general, we discourage the use of
   171  [prow.k8s.io] as a testbed for job development, and recommend the use of your
   172  own instance of prow for faster iteration. That said, an approach that people
   173  have used in the past with mostly-there jobs is to iterate via PRs; just
   174  recognize this is going to depend on review latency.
   175  
   176  ## Running a Production Job
   177  
   178  Normally prow will automatically schedule your job, however if for some reason you
   179  need to trigger it again and are a Prow administrator you have a few options:
   180  
   181  - you can use the rerun feature in prow.k8s.io to run the job again *with the same config*
   182  - you can use [`config/mkpj.sh`](/config/mkpj.sh) to create a prowjob CR from your local config
   183  - you can use `bazel run //prow/cmd/mkpj -- --job=foo ...` to create a prowjob CR from your local config
   184  
   185  For the latter two options you'll need to submit the resulting CR via `kubectl` configured against
   186  the prow services cluster.
   187  
   188  ## Generated Jobs
   189  
   190  There are some sets of jobs that are generated and should not be edited by hand.
   191  These specific instructions should probably just live adjacent to the jobs rather
   192  than in this central README, but here we are for now.
   193  
   194  ### image-validation jobs
   195  
   196  These test different master/node image versions against multiple k8s branches. If you
   197  want to change these, update [`releng/test_config.yaml`](/releng/test_config.yaml)
   198  and then run
   199  
   200  ```sh
   201  # from test-infra root
   202  $ ./hack/update-generated-tests.sh
   203  ```
   204  
   205  ### release-branch jobs
   206  
   207  When a release branch of kubernetes is first cut, the current set of master jobs
   208  must be forked to use the new release branch. Use [`releng/config-forker`] to
   209  accomplish this, eg:
   210  
   211  ```sh
   212  # from test-infra root
   213  $ go run ./releng/config-forker \
   214    --job-config $(pwd)/config/jobs \
   215    --version 1.27 \
   216    --go-version 1.20.2 \
   217    --output $(pwd)/config/jobs/kubernetes/sig-release/release-branch-jobs/1.27.yaml
   218  ```
   219  
   220  [prow.k8s.io]: https://prow.k8s.io
   221  [@k8s-ci-robot]: https://github.com/k8s-ci-robot
   222  [testgrid annotations]: /testgrid/config.md#prow-job-configuration
   223  [testgrid.k8s.io]: https://testgrid.k8s.io
   224  
   225  [`releng/config-forker`]: /releng/config-forker
   226  [`images/`]: /images
   227  
   228  [periodic-kubernetes-e2e-packages-pushed]: https://github.com/kubernetes/test-infra/blob/688d365adf7f71e33a4249c7b90d7e84c105dfc5/config/jobs/kubernetes/sig-cluster-lifecycle/packages.yaml#L3-L16
   229  [pull-community-verify]: https://github.com/kubernetes/test-infra/blob/f4e6553b27d9ee8b35b2f2e588ea2e18c3fa818b/config/jobs/kubernetes/community/community-presubmit.yaml#L3-L19
   230  [pull-release-unit]: https://github.com/kubernetes/test-infra/blob/294d73f1e1c87e6b93f60287196438325bc35677/config/jobs/kubernetes/release/release-config.yaml#L37
   231  [pull-release-notes-lint]: https://github.com/kubernetes/test-infra/blob/294d73f1e1c87e6b93f60287196438325bc35677/config/jobs/kubernetes-sigs/release-notes/release-notes-presubmits.yaml#L69-L80
   232  [pull-org-test-all]: https://github.com/kubernetes/test-infra/blob/294d73f1e1c87e6b93f60287196438325bc35677/config/jobs/kubernetes/org/kubernetes-org-jobs.yaml#L3-L13
   233  
   234  [`preset-service-account: "true"`]: https://github.com/kubernetes/test-infra/blob/f4e6553b27d9ee8b35b2f2e588ea2e18c3fa818b/prow/config.yaml#L467-L483
   235  [`preset-pull-kubernetes-e2e: "true"`]: https://github.com/kubernetes/test-infra/blob/f4e6553b27d9ee8b35b2f2e588ea2e18c3fa818b/config/jobs/kubernetes/sig-gcp/sig-gcp-gce-config.yaml#L2-L8
   236  [`preset-aws-credentials: "true"`]: https://github.com/kubernetes/test-infra/blob/f4e6553b27d9ee8b35b2f2e588ea2e18c3fa818b/config/jobs/kubernetes/sig-aws/sig-aws-credentials.yaml#L3-L15
   237  [the default preset with no labels]: https://github.com/kubernetes/test-infra/blob/551edb4702e262989fe5d162a2c642c3201bf68e/prow/config.yaml#L630