github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/prow/README.md (about) 1 # Prow 2 3 Prow is the system that handles GitHub events and commands for Kubernetes. It 4 currently comprises several related pieces that live in a Kubernetes cluster. 5 See the [GoDoc](https://godoc.org/k8s.io/test-infra/prow) for library docs. 6 Please note that these libraries are intended for use by prow only, and we do 7 not make any attempt to preserve backwards compatibility. 8 9 * `cmd/hook` is the most important piece. It is a stateless server that listens 10 for GitHub webhooks and dispatches them to the appropriate handlers. 11 * `cmd/plank` is the controller that manages jobs running in k8s pods. 12 * `cmd/jenkins-operator` is the controller that manages jobs running in Jenkins. 13 * `cmd/sinker` cleans up old jobs and pods. 14 * `cmd/splice` regularly schedules batch jobs. 15 * `cmd/deck` presents [a nice view](https://prow.k8s.io/) of recent jobs. 16 * `cmd/phony` sends fake webhooks. 17 * `cmd/tot` vends incrementing build numbers. 18 * `cmd/horologium` starts periodic jobs when necessary. 19 * `cmd/mkpj` creates `ProwJobs`. 20 21 See also: [Life of a Prow Job](./architecture.md) 22 23 ## Announcements 24 25 Breaking changes to external APIs (labels, GitHub interactions, configuration 26 or deployment) will be documented in this section. Prow is in a pre-release 27 state and no claims of backwards compatibility are made for any external API. 28 29 - *September 3, 2017* sinker:0.17 now deletes pods labeled by plank:0.42 in 30 order to avoid cleaning up unrelated pods that happen to be found in the 31 same namespace prow runs pods. If you run other pods in the same namespace, 32 you will have to manually delete or label the prow-owned pods, otherwise you 33 can bulk-label all of them with the following command and let sinker collect 34 them normally: 35 ``` 36 kubectl label pods --all -n pod_namespace created-by-prow=true 37 ``` 38 - *September 1, 2017* `deck` version 0.44 and `jenkins-operator` version 0.41 39 controllers no longer provide a default value for the `--jenkins-token-file` flag. 40 Cluster administrators should provide `--jenkins-token-file=/etc/jenkins/jenkins` 41 explicitly when upgrading to a new version of these components if they were 42 previously relying on the default. For more context, please see 43 [this pull request.](https://github.com/kubernetes/test-infra/pull/4210) 44 - *August 29, 2017* Configuration specific to plugins is now held in in the 45 `plugins` `ConfigMap` and serialized in this repo in the `plugins.yaml` file. 46 Cluster administrators upgrading to `hook` version 0.148 or newer should move 47 plugin configuration from the main `ConfigMap`. For more context, please see 48 [this pull request.](https://github.com/kubernetes/test-infra/pull/4213) 49 50 ## Getting started 51 52 [See the doc here.](./getting_started.md) 53 54 ## How to test prow 55 56 Build with: 57 ``` 58 bazel build //prow/... 59 ``` 60 Test with: 61 ``` 62 bazel test --features=race //prow/... 63 ``` 64 65 You can run `cmd/hook` in a local mode for testing, and hit it with arbitrary 66 fake webhooks. To do this, run in one shell: 67 ``` 68 ./bazel-bin/prow/cmd/hook/hook --local --config-path prow/config.yaml --plugin-config prow/plugins.yaml 69 ``` 70 This will listen on `localhost:8888` for webhooks. Send one with: 71 ``` 72 ./bazel-bin/prow/cmd/phony/phony --event issue_comment --payload prow/cmd/phony/examples/test_comment.json 73 ``` 74 75 ## How to run a given job on prow 76 77 Run the following, specifying `JOB_NAME`: 78 79 ``` 80 bazel run //prow/cmd/mkpj -- --job=JOB_NAME 81 ``` 82 83 This will print the ProwJob YAML to stdout. You may pipe it into `kubectl`. 84 Depending on the job, you will need to specify more information such as PR 85 number. 86 87 ## How to update the cluster 88 89 Any modifications to Go code will require redeploying the affected binaries. 90 Fortunately, this should result in no downtime for the system. Run `./bump.sh <program-name>` 91 to bump the relevant version number in the makefile as well as in the `cluster` manifest, 92 then run the image and deployment make targets on a branch which has the 93 changes. For instance, if you bumped the hook version, run 94 `make hook-image && make hook-deployment`. 95 96 **Please ensure that your git tree is up to date before updating anything.** 97 98 ## How to add new plugins 99 100 Add a new package under `plugins` with a method satisfying one of the handler 101 types in `plugins`. In that package's `init` function, call 102 `plugins.Register*Handler(name, handler)`. Then, in `hook/plugins.go`, add an 103 empty import so that your plugin is included. If you forget this step then a 104 unit test will fail when you try to add it to `plugins.yaml`. Don't add a brand 105 new plugin to the main `kubernetes/kubernetes` repo right away, start with 106 somewhere smaller and make sure it is well-behaved. If you add a command, 107 document it in [commands.md](../commands.md). 108 109 The LGTM plugin is a good place to start if you're looking for an example 110 plugin to mimic. 111 112 ## How to enable a plugin on a repo 113 114 Add an entry to [plugins.yaml](plugins.yaml). If you misspell the name then a 115 unit test will fail. If you have [update-config](plugins/updateconfig) plugin 116 deployed then the config will be automatically updated once the PR is merged, 117 else you will need to run `make update-plugins`. This does not require 118 redeploying the binaries, and will take effect within a minute. 119 120 Note that Github events triggered by the account that is managing the plugins 121 are ignored by some plugins. It is prudent to use a different bot account for 122 performing merges or rerunning tests, whether the deployment that drives the 123 second account is `tide` or the `submit-queue` munger. 124 125 ## How to add new jobs 126 127 To add a new job you'll need to add an entry into [config.yaml](config.yaml). 128 If you have [update-config](plugins/updateconfig) plugin deployed then the 129 config will be automatically updated once the PR is merged, else you will need 130 to run `make update-config`. This does not require redeploying any binaries, 131 and will take effect within a minute. 132 133 Periodic config looks like so: 134 135 ```yaml 136 periodics: 137 - name: foo-job # Names need not be unique. 138 interval: 1h # Anything that can be parsed by time.ParseDuration. 139 agent: kubernetes # See discussion. 140 spec: {} # Valid Kubernetes PodSpec. 141 run_after_success: [] # List of periodics. 142 ``` 143 144 The `agent` should be "kubernetes", but if you are running a controller for a 145 different job agent then you can fill that in here. The spec should be a valid 146 Kubernetes PodSpec iff `agent` is "kubernetes". 147 148 Postsubmit config looks like so: 149 150 ```yaml 151 postsubmits: 152 org/repo: 153 - name: bar-job # As for periodics. 154 agent: kubernetes # As for periodics. 155 spec: {} # As for periodics. 156 max_concurrency: 10 # Run no more than this number concurrently. 157 branches: # Only run against these branches. 158 - master 159 skip_branches: # Do not run against these branches. 160 - release 161 run_after_success: [] # List of postsubmits. 162 ``` 163 164 Postsubmits are run when a push event happens on a repo, hence they are 165 configured per-repo. If no `branches` are specified, then they will run against 166 every branch. 167 168 Presubmit config looks like so: 169 170 ```yaml 171 presubmits: 172 org/repo: 173 - name: qux-job # As for periodics. 174 always_run: true # Run for every PR, or only when requested. 175 run_if_changed: "qux/.*" # Regexp, only run on certain changed files. 176 skip_report: true # Whether to skip setting a status on GitHub. 177 context: qux-job # Status context. Usually the job name. 178 max_concurrency: 10 # As for postsubmits. 179 agent: kubernetes # As for periodics. 180 spec: {} # As for periodics. 181 run_after_success: [] # As for periodics. 182 branches: [] # As for postsubmits. 183 skip_branches: [] # As for postsubmits. 184 trigger: "(?m)qux test this( please)?" # Regexp, see discussion. 185 rerun_command: "qux test this please" # String, see discussion. 186 ``` 187 188 If you only want to run tests when specific files are touched, you can use 189 `run_if_changed`. A useful pattern when adding new jobs is to start with 190 `always_run` set to false and `skip_report` set to true. Test it out a few 191 times by manually triggering, then switch `always_run` to true. Watch for a 192 couple days, then switch `skip_report` to false. 193 194 The `trigger` is a regexp that matches the `rerun_command`. Users will be told 195 to input the `rerun_command` when they want to rerun the job. Actually, anything 196 that matches `trigger` will suffice. This is useful if you want to make one 197 command that reruns all jobs. 198 199 200 ### Job Evironment Variables 201 202 Prow will expose the following environment variables to your job. If the job 203 runs on Kubernetes, the variables will be injected into every container in 204 your pod, If the job is run in Jenkins, Prow will supply them as parameters to 205 the build. 206 207 Variable | Periodic | Postsubmit | Batch | Presubmit | Description | Example 208 --- |:---:|:---:|:---:|:---:| --- | --- 209 `JOB_NAME` | ✓ | ✓ | ✓ | ✓ | Name of the job. | `pull-test-infra-bazel` 210 `BUILD_NUMBER` | ✓ | ✓ | ✓ | ✓ | Unique build number for each run. | `12345` 211 `REPO_OWNER` | | ✓ | ✓ | ✓ | GitHub org that triggered the job. | `kubernetes` 212 `REPO_NAME` | | ✓ | ✓ | ✓ | GitHub repo that triggered the job. | `test-infra` 213 `PULL_BASE_REF` | | ✓ | ✓ | ✓ | Ref name of the base branch. | `master` 214 `PULL_BASE_SHA` | | ✓ | ✓ | ✓ | Git SHA of the base branch. | `123abc` 215 `PULL_REFS` | | ✓ | ✓ | ✓ | All refs to test. | `master:123abc,5:qwe456` 216 `PULL_NUMBER` | | | | ✓ | Pull request number. | `5` 217 `PULL_PULL_SHA` | | | | ✓ | Pull request head SHA. | `qwe456` 218 219 Note: to not overwrite the Jenkins `$BUILD_NUMBER` variable, the build identifier 220 will be passed as `$buildId` to Jenkins jobs. 221 222 ## Bots home 223 224 [@k8s-ci-robot](https://github.com/k8s-ci-robot) and its silent counterpart 225 [@k8s-bot](https://github.com/k8s-bot) both live here as triggers to GitHub 226 messages defined in [config.yaml](config.yaml). Here is a 227 [command list](https://github.com/kubernetes/test-infra/blob/master/commands.md) 228 for them.