You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add some Makefile variables for more granular construction of the
build image URI to facilitate simpler overriding for personal builds.
- Document the process to build, tag, push, and deploy a personal build
to a personal cluster.
-[Is The Request Valid and Authorized](#is-the-request-valid-and-authorized)
11
+
-[Building a Response](#building-a-response)
12
+
-[Sending Responses](#sending-responses)
13
+
-[Writing Unit Tests](#writing-unit-tests)
14
+
-[Local Live Testing](#local-live-testing)
15
+
-[Create a Repository](#create-a-repository)
16
+
-[Build and Push the Image](#build-and-push-the-image)
17
+
-[Pare Down Your Daemonset (Optional)](#pare-down-your-daemonset-optional)
18
+
-[Deploy the Image](#deploy-the-image)
19
+
-[Test Your Changes](#test-your-changes)
20
+
-[End to End Testing](#end-to-end-testing)
21
+
-[Disabling Webhooks](#disabling-webhooks)
22
+
-[Removing a Webhook](#removing-a-webhook)
23
+
5
24
## Updating SelectorSyncSet Template
6
25
7
26
Ensure the git branch is current and run `make syncset`. The updated Template will be [build/selectorsyncset.yaml](build/selectorsyncset.yaml) by default.
@@ -104,7 +123,7 @@ It is important to retain the UID from the incoming request with the outgoing re
104
123
105
124
Once a [response is built](#building-a-response), it must be sent back to the HTTP client. This is done by returning the `admissionctl.Response` in the `Authorized` method. This structure can be [built up with the helpers mentioned above](#building-a-response).
106
125
107
-
### Writing Tests
126
+
### Writing Unit Tests
108
127
109
128
Unit tests are important to ensure that webhooks behave as expected, and to help with that process, there is a [testutils](pkg/testutils/testutils.go) helper package designed to unify several processes. The package exports:
110
129
@@ -117,6 +136,117 @@ The first function, `CanCanNot`, is very simple and designed to make test failur
117
136
118
137
The three helper functions are intended to provide for more integration style tests than true unit tests, as they assist in turning a specific set of test criteria a JSON representation and sending via `net/http/httptest` to the webhook's `Authorized`. When using `testutils.SendHTTPRequest`, the response is a `Response` object that can be used in the test suite to access the result of the webhook.
119
138
139
+
### Local Live Testing
140
+
141
+
Build and test your changes against your own cluster.
142
+
Here is a [recorded demo](https://drive.google.com/file/d/1UaMz-siFDRaSKPVKxjLOneqGgbBuwpBF/view) of this process.
143
+
144
+
#### Create a Repository
145
+
146
+
Make sure you have a repository to host the image you are going to build.
147
+
It must be **public** so your cluster is able to download the image.
148
+
For subsequent steps, you will need the name of the registry, the organization, and the repository.
149
+
For example, in the image URI `quay.io/my-user/managed-cluster-validating-webhooks:latest`:
150
+
-`quay.io` is the *registry*
151
+
-`my-user` is the *organization*
152
+
-`managed-cluster-validating-webhooks` is the *repository*
153
+
-`latest` is the *image tag*
154
+
155
+
#### Build and Push the Image
156
+
157
+
Use `make build-base` to build and tag the image; and `make push-base` to push it.
158
+
In order to use your personal repository, you can override any of the components of this URI by setting the following variables:
159
+
-`IMG_REGISTRY` overrides the *registry* (default: `quay.io`)
160
+
-`IMG_ORG` overrides the *organization* (default: `app-sre`)
161
+
-`BASE_IMG` overrides the *repository name* (default: `managed-cluster-validating-webhooks`)
162
+
-`IMAGETAG` overrides the *image tag*. (By default this is the current commit hash of your local clone of the git repository; but `make build-base` will also always tag `latest`)
163
+
164
+
For example, to build, tag, and push `quay.io/my-user/managed-cluster-validating-webhooks:latest`, you can run:
165
+
166
+
```
167
+
make IMG_ORG=my-user build-base push-base
168
+
```
169
+
170
+
#### Pare Down Your Daemonset (Optional)
171
+
172
+
**Note:** Editing the daemonset requires elevated privileges.
173
+
174
+
By default, the image will run on all master nodes.
175
+
For testing purposes, you may find it easier to run on only one node.
176
+
To facilitate this:
177
+
1. Pick a master node to use. Any one will do. For example:
3. Edit the `validation-webhook` daemonset's `.spec.template.spec.affinity.nodeAffinity`, replacing the `matchExpressions` entry for `node-role.kubernetes.io/master` to match your label instead.
Once these changes are saved, you should see `validation-webhook-*` pods cycle.
216
+
When they have settled, you can confirm that only one pod is running and that it is running on your desired node.
217
+
For example:
218
+
219
+
```
220
+
$ oc describe pod -n openshift-validation-webhook | grep ^Node:
221
+
Node: ip-10-0-147-186.ec2.internal/10.0.147.186
222
+
```
223
+
224
+
#### Deploy the Image
225
+
226
+
**Note:** Editing the daemonset requires elevated privileges.
227
+
228
+
Edit the `validation-webhook` daemonset's `.spec.template.spec.containers[0].image`, replacing it with the URI of the image you built and pushed [above](#build-and-push-the-image).
229
+
For example, if you created `quay.io/my-user/managed-cluster-validating-webhooks:latest`, replace
0 commit comments