Skip to content

Commit d78aa0c

Browse files
authored
Merge pull request kubernetes#2600 from ykakarap/kubectl_subresource
kubectl subresource KEP
2 parents 171f02c + 6094074 commit d78aa0c

File tree

3 files changed

+416
-0
lines changed

3 files changed

+416
-0
lines changed

keps/prod-readiness/sig-cli/2590.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kep-number: 2590
2+
alpha:
3+
approver: "@johnbelamaric"
Lines changed: 388 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,388 @@
1+
# KEP-2590: Kubectl Subresource Support
2+
3+
<!-- toc -->
4+
- [Release Signoff Checklist](#release-signoff-checklist)
5+
- [Summary](#summary)
6+
- [Motivation](#motivation)
7+
- [Goals](#goals)
8+
- [Non-Goals](#non-goals)
9+
- [Proposal](#proposal)
10+
- [Notes](#notes)
11+
- [Examples](#examples)
12+
- [get](#get)
13+
- [patch](#patch)
14+
- [Design Details](#design-details)
15+
- [Subresource support](#subresource-support)
16+
- [Table printer](#table-printer)
17+
- [Test Plan](#test-plan)
18+
- [Graduation Criteria](#graduation-criteria)
19+
- [Alpha -&gt; Beta Graduation](#alpha---beta-graduation)
20+
- [Beta -&gt; GA Graduation](#beta---ga-graduation)
21+
- [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy)
22+
- [Version Skew Strategy](#version-skew-strategy)
23+
- [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire)
24+
- [Feature Enablement and Rollback](#feature-enablement-and-rollback)
25+
- [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning)
26+
- [Monitoring Requirements](#monitoring-requirements)
27+
- [Dependencies](#dependencies)
28+
- [Scalability](#scalability)
29+
- [Troubleshooting](#troubleshooting)
30+
- [Implementation History](#implementation-history)
31+
- [Alternatives](#alternatives)
32+
<!-- /toc -->
33+
34+
## Release Signoff Checklist
35+
36+
Items marked with (R) are required *prior to targeting to a milestone / release*.
37+
38+
- [x] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR)
39+
- [x] (R) KEP approvers have approved the KEP status as `implementable`
40+
- [x] (R) Design details are appropriately documented
41+
- [x] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
42+
- [x] (R) Graduation criteria is in place
43+
- [ ] (R) Production readiness review completed
44+
- [ ] (R) Production readiness review approved
45+
- [x] "Implementation History" section is up-to-date for milestone
46+
- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io]
47+
- [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
48+
49+
<!--
50+
**Note:** This checklist is iterative and should be reviewed and updated every time this enhancement is being considered for a milestone.
51+
-->
52+
53+
[kubernetes.io]: https://kubernetes.io/
54+
[kubernetes/enhancements]: https://git.k8s.io/enhancements
55+
[kubernetes/kubernetes]: https://git.k8s.io/kubernetes
56+
[kubernetes/website]: https://git.k8s.io/website
57+
58+
## Summary
59+
60+
This KEP proposes supporting a new flag `--subresource` to get, patch, edit and replace kubectl
61+
commands to fetch and update `status` and `scale` subresources.
62+
63+
## Motivation
64+
65+
Today while testing or debugging, fetching subresources (like status) of API objects via kubectl
66+
involves using `kubectl --raw`. Patching subresources using kubectl is not possible at all and
67+
requires using curl directly. This method is very cumbersome and not user-friendly.
68+
69+
This KEP adds subresources as a first class option in kubectl to allow users to work with the API
70+
in a generic fashion.
71+
72+
### Goals
73+
74+
- Add a new flag `--subresource=[subresource-name]` to get, patch, edit
75+
and replace kubectl commands to allow fetching and updating `status` and `scale`
76+
subresources for all resources (built-in and CRs) that support these subresources.
77+
- Display pretty printed table columns for the status (uses same columns as the main resource)
78+
and scale subresources.
79+
80+
### Non-Goals
81+
82+
- Support subresources other than `status` and `scale`.
83+
- Allow specifying `additionalPrinterColumns` for CRDs for the status subresource.
84+
85+
## Proposal
86+
87+
kubectl commands like get, patch, edit and replace will now contain a
88+
new flag `--subresource=[subresource-name]` which will allow fetching and updating
89+
`status` and `scale` subresources for all API resources.
90+
91+
Note that the API contract against the subresource is identical to a full resource. Therefore updating
92+
the status subresource to hold new value which could protentially be reconciled by a controller
93+
to a different value is *expected behavior*.
94+
95+
If `--subresource` flag is used for a resource that doesn't support the subresource,
96+
a `NotFound` error will be returned.
97+
98+
## Notes
99+
100+
The alpha stage of this KEP does not change any behavior of the `apply` command.
101+
The support for `--subresource` in this command will be added later.
102+
103+
## Examples
104+
105+
#### get
106+
107+
```shell
108+
# for built-in types
109+
# a `get` on a status subresource will return identical information
110+
# to that of a full resource
111+
$ kubectl get deployment nginx-deployment --subresource=status
112+
NAME READY UP-TO-DATE AVAILABLE AGE
113+
nginx-deployment 3/3 3 3 43s
114+
115+
$ kubectl get deployment nginx-deployment --subresource=scale
116+
NAME DESIREDREPLICAS AVAILABLEREPLICAS
117+
nginx-deployment 3 3
118+
119+
# for CRDS
120+
# a `get` on a status subresource will return identical information
121+
# to that of a full resource
122+
$ kubectl get crontab cron--subresource=status
123+
NAME SPEC REPLICAS AGE
124+
cron * * * * */5 3 4m52s
125+
126+
$ kubectl get vmset vmset-1 --subresource=scale
127+
NAME DESIREDREPLICAS AVAILABLEREPLICAS
128+
cron 3 0
129+
```
130+
131+
Invalid subresources:
132+
133+
```shell
134+
$ kubectl get pod nginx-deployment-66b6c48dd5-dv6gl --subresource=logs
135+
error: --subresource must be one of [status scale], not "logs"
136+
137+
$ kubectl get pod nginx-deployment-66b6c48dd5-dv6gl --subresource=scale
138+
Error from server (NotFound): the server could not find the requested resource
139+
```
140+
141+
#### patch
142+
143+
```shell
144+
# For built-in types
145+
# update spec.replicas through scale subresource
146+
$ kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -p '{"spec":{"replicas":2}}'
147+
scale.autoscaling/nginx-deployment patched
148+
149+
# spec.replicas is updated for the main resource
150+
$ k get deploy nginx-deployment
151+
NAME READY UP-TO-DATE AVAILABLE AGE
152+
nginx-deployment 2/2 2 2 4m
153+
154+
# For CRDs
155+
$ kubectl patch crontabs cron --subresource='status' --type='merge' -p '{"status":{"replicas":2}}'
156+
crontab.stable.example.com/cron patched
157+
158+
$ kubectl get crontab cron --subresource=scale
159+
NAME DESIREDREPLICAS AVAILABLEREPLICAS
160+
cron 3 2
161+
```
162+
163+
## Design Details
164+
165+
### Subresource support
166+
167+
A new field `Subresource` and method `Subresource`/`WithSubresource` is added to
168+
the [builder], [helper] and [visitor] code to use the API object at the subresource path.
169+
170+
[builder]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go
171+
[helper]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/resource/helper.go
172+
[visitor]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/resource/visitor.go
173+
174+
For each relevant kubectl command, a new flag `--subresource` is added. If the flag is specified,
175+
the value is also validated to ensure that it is a valid subresource.
176+
177+
If the subresource does not exist for an API resource, a `NotFound` error is returned.
178+
179+
### Table printer
180+
181+
To support table view for subresources using kubectl get, table convertor support is added to
182+
the scale and status subresoruces for built-in and CRD types.
183+
184+
For built-in types, `StatusStore` and `ScaleStore` are updated to implement the `TableConvertor` interface.
185+
`StatusStore` uses the same columns as the main resource object.
186+
187+
The following column definitions for the `Scale` object are added to [printers.go] to support the scale subresource:
188+
- `Available Replicas` uses the json path `.status.replicas` of autoscalingv1.Scale object
189+
- `Desired Replicas` uses the json path of `.spec.replicas` of autoscalingv1.Scale object
190+
191+
For custom resources:
192+
- the status subresoruce uses the same columns as defined for the full resource, i.e., `additionalPrinterColumns` defined in the CRD.
193+
- the scale subresource follows the same column definitions as the built-in types, and are defined in [helpers.go].
194+
195+
[printers.go]: https://github.com/kubernetes/kubernetes/blob/master/pkg/printers/internalversion/printers.go#L88
196+
[helpers.go]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/helpers.go
197+
198+
### Test Plan
199+
200+
- Unit tests, integration and e2e tests will be added.
201+
202+
### Graduation Criteria
203+
204+
#### Alpha -> Beta Graduation
205+
206+
- [ ] Collect user feedback on adding support of `--subresource` for `apply`
207+
208+
#### Beta -> GA Graduation
209+
210+
- [ ] User feedback gathered for atleast 1 cycle
211+
212+
### Upgrade / Downgrade Strategy
213+
214+
This functionality is contained entirely within kubectl and shares its strategy.
215+
No configuration changes are required.
216+
217+
### Version Skew Strategy
218+
219+
Not applicable. There is nothing required of the API Server, so there
220+
can be no version skew.
221+
222+
## Production Readiness Review Questionnaire
223+
224+
### Feature Enablement and Rollback
225+
226+
###### How can this feature be enabled / disabled in a live cluster?
227+
228+
<!--
229+
Pick one of these and delete the rest.
230+
-->
231+
232+
- [ ] Feature gate (also fill in values in `kep.yaml`)
233+
- Feature gate name:
234+
- Components depending on the feature gate:
235+
- [x] Other
236+
- Describe the mechanism: A new flag for kubectl commands.
237+
For the alpha stage, description will be added to expicitly call
238+
out this flag as an alpha feature.
239+
- Will enabling / disabling the feature require downtime of the control
240+
plane? No, disabling the feature would be a client behaviour.
241+
- Will enabling / disabling the feature require downtime or reprovisioning
242+
of a node? (Do not assume `Dynamic Kubelet Config` feature is enabled).
243+
No, disabling the feature would be a client behaviour.
244+
245+
###### Does enabling the feature change any default behavior?
246+
247+
While the feature now updates kubectl's behavior to allow updating subresources,
248+
it is gated by the `--subresource` flag so it does not change kubectl's default
249+
behavior.
250+
251+
Subresources can also be updated using curl today so this feature only
252+
provides a consistent way to use the API via kubectl, but does not allow additional
253+
changes to the API that are not possible today.
254+
255+
###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)?
256+
257+
Yes, rolling back to a previous version of `kubectl` will remove support
258+
for the `--subresource` flag and the ability to update subresources via kubectl.
259+
260+
However, this does not "lock" us to any changes to the subresources that were made
261+
when the feature was enabled i.e. it does not remove the ability to update subresources
262+
for existing API resources completely. If a subresource of an exisiting API resource needs
263+
to be updated, this can be done via curl.
264+
265+
###### What happens if we reenable the feature if it was previously rolled back?
266+
267+
The `--subresource` flag can be used and subresources can be updated via kubectl again.
268+
269+
###### Are there any tests for feature enablement/disablement?
270+
271+
No, because it cannot be disabled or enabled in a single release.
272+
273+
### Rollout, Upgrade and Rollback Planning
274+
275+
<!--
276+
This section must be completed when targeting beta to a release.
277+
-->
278+
279+
###### How can a rollout fail? Can it impact already running workloads?
280+
281+
The feature is encapsulated entirely within the kubectl binary, so rollout is
282+
an atomic client binary update. Subresources can always be updated via curl,
283+
so there are no version dependencies.
284+
285+
###### What specific metrics should inform a rollback?
286+
287+
N/A
288+
289+
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
290+
291+
This feature is completely with in the client. The upgrades and rollback of cluster will not be affected by this change.
292+
The update and downgrade of the kubectl version will only limit the availability of the `--subresource` flag and will not
293+
change any API behavior.
294+
295+
<!--
296+
Describe manual testing that was done and the outcomes.
297+
Longer term, we may want to require automated upgrade/rollback tests, but we
298+
are missing a bunch of machinery and tooling and can't do that now.
299+
-->
300+
301+
###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.?
302+
303+
No.
304+
305+
### Monitoring Requirements
306+
307+
###### How can an operator determine if the feature is in use by workloads?
308+
309+
N/A
310+
311+
###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service?
312+
313+
N/A
314+
315+
###### What are the reasonable SLOs (Service Level Objectives) for the above SLIs?
316+
317+
N/A
318+
319+
###### Are there any missing metrics that would be useful to have to improve observability of this feature?
320+
321+
N/A
322+
323+
### Dependencies
324+
325+
###### Does this feature depend on any specific services running in the cluster?
326+
327+
No
328+
329+
### Scalability
330+
331+
###### Will enabling / using this feature result in any new API calls?
332+
333+
- API call type (e.g. PATCH pods):
334+
GET, PATCH, PUT `/<subresource>`
335+
336+
- Estimated throughput:
337+
Negligible, because it's human initiated. At maximum, each command would involve
338+
two calls: 1 read and 1 mutate.
339+
340+
- Originating component(s):
341+
kubectl
342+
343+
###### Will enabling / using this feature result in introducing new API types?
344+
345+
No
346+
347+
###### Will enabling / using this feature result in any new calls to the cloud provider?
348+
349+
No
350+
351+
###### Will enabling / using this feature result in increasing size or count of the existing API objects?
352+
353+
No
354+
355+
###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs?
356+
357+
No
358+
359+
###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components?
360+
361+
No
362+
363+
### Troubleshooting
364+
365+
###### How does this feature react if the API server and/or etcd is unavailable?
366+
367+
`kubectl` is not resilient to API server unavailability.
368+
369+
###### What are other known failure modes?
370+
371+
N/A
372+
373+
###### What steps should be taken if SLOs are not being met to determine the problem?
374+
375+
N/A
376+
377+
## Implementation History
378+
379+
2021-03-01: Initial [POC PR] created
380+
2021-04-06: KEP proposed
381+
382+
[POC PR]: https://github.com/kubernetes/kubernetes/pull/99556
383+
384+
## Alternatives
385+
386+
Alternatives would be to use curl commands directly to update subresources.
387+
388+

0 commit comments

Comments
 (0)