@@ -172,6 +172,39 @@ During bootstrap, for each resource, the API server
172
172
to avoid conflicting with other API servers.
173
173
* installs the resource handler.
174
174
175
+ The above mentioned process requires an API server to update the storageVersion
176
+ before accepting API requests. If we don't enforce this order, data encoded in
177
+ an unexpected version can sneak into etcd. For example, an API server persists a
178
+ write request encoded in an obsoleted version, then it crashes before it can
179
+ update the storageVersion. The storage migrator has no way to detect this write.
180
+
181
+ For the cmd/kube-apiserver binary, we plan to enforce this order by adding a new
182
+ filter to the [ handler chain] [ ] . Before kube-aggregator, kube-apiserver, and
183
+ apiextension-apiserver have registered the storage version of the built-in
184
+ resources they host, this filter only allows the following requests to pass:
185
+ 1 . a request sent by the loopbackClient and is destined to the storageVersion
186
+ API.
187
+ 2 . the verb of the request is GET.
188
+ 3 . the request is for an API that is not persisted, e.g.,
189
+ SubjectAccessReview and TokenReview. [ Here] is a complete list.
190
+ 4 . the request is for an aggregated API, because the request is handled by the
191
+ aggregated API server.
192
+ 5 . the request is for a custom resource, because the apiextension apiserver
193
+ makes sure that it updates the storage version before it serves the CR (see
194
+ [ CRDs] ( #crds ) ).
195
+
196
+ The filter rejects other requests with a 503 Service Unavailable response code.
197
+
198
+ [ handler chain ] :https://github.com/kubernetes/kubernetes/blob/fc8f5a64106c30c50ee2bbcd1d35e6cd05f63b00/staging/src/k8s.io/apiserver/pkg/server/config.go#L639
199
+ [ Here ] :https://github.com/kubernetes/kubernetes/blob/709a0c4f7bfec2063cb856f3cdf4105ce984e247/pkg/master/storageversionhashdata/data.go#L26
200
+
201
+ One concern is that the storageVersion API becomes a single-point-of-failure,
202
+ though it seems inevitable in order to ensure the correctness of the storage
203
+ migration.
204
+
205
+ We will also add a post-start hook to ensure that the API server reports not
206
+ ready until the storageVersions are up-to-date and the filter is turned off.
207
+
175
208
### Garbage collection
176
209
177
210
There are two kinds of "garbage":
@@ -217,11 +250,14 @@ details.
217
250
[ appendix ] :#appendix
218
251
[ storageVersionHash ] :https://github.com/kubernetes/kubernetes/blob/c008cf95a92c5bbea67aeab6a765d7cb1ac68bd7/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L989
219
252
220
- To accurately reflect the storage version being used, the apiextension-apiserver
221
- needs to update the storageVersion object when it [ creates] [ ] the custom
222
- resource handler upon CRD creation or changes.
253
+ To ensure that the storageVersion.status always shows the actual encoding
254
+ versions, the apiextension-apiserver must update the storageVersion.status
255
+ before it [ enables] [ ] the custom resource handler. This way it does not require
256
+ the [ filter] [ ] mechanism that is used by the kube-apiserver to ensure the
257
+ correct order.
223
258
224
- [ creates ] :https://github.com/kubernetes/kubernetes/blob/220498b83af8b5cbf8c1c1a012b64c956d3ebf9b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go#L721
259
+ [ enables ] :https://github.com/kubernetes/kubernetes/blob/220498b83af8b5cbf8c1c1a012b64c956d3ebf9b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go#L703
260
+ [ filter ] :#updating-storageversion
225
261
226
262
### Aggregated API servers
227
263
0 commit comments