Skip to content

Commit 0802267

Browse files
authored
Merge pull request #5079 from soltysh/kubectl_subresource
KEP 2590: Graduate kubectl subresource to GA
2 parents fa51189 + 67b794d commit 0802267

File tree

3 files changed

+103
-75
lines changed

3 files changed

+103
-75
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ kep-number: 2590
22
alpha:
33
approver: "@johnbelamaric"
44
beta:
5+
approver: "@johnbelamaric"
6+
stable:
57
approver: "@johnbelamaric"

keps/sig-cli/2590-kubectl-subresource/README.md

Lines changed: 94 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
- [Goals](#goals)
88
- [Non-Goals](#non-goals)
99
- [Proposal](#proposal)
10-
- [Notes/Constraints/Caveats](#notesconstraintscaveats)
11-
- [Examples](#examples)
12-
- [get](#get)
13-
- [patch](#patch)
10+
- [User Stories (Optional)](#user-stories-optional)
11+
- [Story 1](#story-1)
12+
- [Story 2](#story-2)
13+
- [Risks and Mitigations](#risks-and-mitigations)
1414
- [Design Details](#design-details)
1515
- [Subresource support](#subresource-support)
1616
- [Table printer](#table-printer)
@@ -43,43 +43,44 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
4343
- [x] (R) KEP approvers have approved the KEP status as `implementable`
4444
- [x] (R) Design details are appropriately documented
4545
- [x] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
46+
- [x] e2e Tests for all Beta API Operations (endpoints)
47+
- [x] (R) Ensure GA e2e tests meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
48+
- [x] (R) Minimum Two Week Window for GA e2e tests to prove flake free
4649
- [x] (R) Graduation criteria is in place
50+
- [x] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
4751
- [x] (R) Production readiness review completed
4852
- [x] (R) Production readiness review approved
4953
- [x] "Implementation History" section is up-to-date for milestone
5054
- [x] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io]
5155
- [x] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
5256

53-
<!--
54-
**Note:** This checklist is iterative and should be reviewed and updated every time this enhancement is being considered for a milestone.
55-
-->
56-
5757
[kubernetes.io]: https://kubernetes.io/
5858
[kubernetes/enhancements]: https://git.k8s.io/enhancements
5959
[kubernetes/kubernetes]: https://git.k8s.io/kubernetes
6060
[kubernetes/website]: https://git.k8s.io/website
6161

6262
## Summary
6363

64-
This KEP proposes supporting a new flag `--subresource` to get, patch, edit and replace kubectl
65-
commands to fetch and update `status` and `scale` subresources.
64+
This document proposes adding a new `--subresource` flag to the following kubectl
65+
subcommands: `get`, `patch`, `edit`, `apply` and `replace`. The goal of this flag
66+
is to simplify the process of fetching and updating `status` and `scale` subresources.
6667

6768
## Motivation
6869

69-
Today while testing or debugging, fetching subresources (like status) of API objects via kubectl
70-
involves using `kubectl --raw`. Patching subresources using kubectl is not possible at all and
71-
requires using curl directly. This method is very cumbersome and not user-friendly.
70+
Today while testing or debugging, fetching subresources (like `status`) of API objects via kubectl
71+
involves using `kubectl --raw`. Patching subresources using kubectl is not possible at all and
72+
requires using `curl` directly. This method is very cumbersome and not user-friendly.
7273

73-
This KEP adds subresources as a first class option in kubectl to allow users to work with the API
74-
in a generic fashion.
74+
This enhancement adds subresources as a first class option in kubectl to allow users
75+
to work with the API in a generic fashion.
7576

7677
### Goals
7778

78-
- Add a new flag `--subresource=[subresource-name]` to get, patch, edit
79-
and replace kubectl commands to allow fetching and updating `status` and `scale`
80-
subresources for all resources (built-in and CRs) that support these subresources.
81-
- Display pretty printed table columns for the status (uses same columns as the main resource)
82-
and scale subresources.
79+
- Add a new flag `--subresource=[subresource-name]` to `get`, `patch`, `edit`, `apply`
80+
and `replace` kubectl commands to allow fetching and updating `status` and `scale`
81+
subresources for all resources (built-in and custom resources) that support these.
82+
- Display pretty printed table columns for the `status` (uses same columns as the main resource)
83+
and `scale` subresources.
8384

8485
### Non-Goals
8586

@@ -88,25 +89,21 @@ and scale subresources.
8889

8990
## Proposal
9091

91-
kubectl commands like get, patch, edit and replace will now contain a
92+
kubectl commands like `get`, `patch`, `edit`, `apply` and `replace` will now contain a
9293
new flag `--subresource=[subresource-name]` which will allow fetching and updating
9394
`status` and `scale` subresources for all API resources.
9495

95-
Note that the API contract against the subresource is identical to a full resource. Therefore updating
96-
the status subresource to hold new value which could potentially be reconciled by a controller
97-
to a different value is *expected behavior*.
96+
Note that the API contract against the subresource is identical to a full resource.
97+
Therefore updating the status subresource to hold new value which could potentially
98+
be reconciled by a controller to a different value is *expected behavior*.
9899

99-
If `--subresource` flag is used for a resource that doesn't support the subresource,
100+
If `--subresource` flag is used for a resource that doesn't support the subresource,
100101
a `NotFound` error will be returned.
101102

102-
### Notes/Constraints/Caveats
103103

104-
Due to additional complexity and the general purpose of `apply` being a
105-
declarative command, `--subresource` will not be expanded to the `apply` command.
104+
### User Stories (Optional)
106105

107-
### Examples
108-
109-
#### get
106+
#### Story 1
110107

111108
```shell
112109
# for built-in types
@@ -142,7 +139,7 @@ $ kubectl get pod nginx-deployment-66b6c48dd5-dv6gl --subresource=scale
142139
Error from server (NotFound): the server could not find the requested resource
143140
```
144141

145-
#### patch
142+
#### Story 2
146143

147144
```shell
148145
# For built-in types
@@ -164,6 +161,12 @@ NAME DESIREDREPLICAS AVAILABLEREPLICAS
164161
cron 3 2
165162
```
166163

164+
### Risks and Mitigations
165+
166+
This feature adds a new flag which will be validated like any other flag for a limited
167+
set of inputs. The remaining flags passed to every command will be validated as
168+
before.
169+
167170
## Design Details
168171

169172
### Subresource support
@@ -182,8 +185,8 @@ If the subresource does not exist for an API resource, a `NotFound` error is ret
182185

183186
### Table printer
184187

185-
To support table view for subresources using kubectl get, table convertor support is added to
186-
the scale and status subresoruces for built-in and CRD types.
188+
To support table view for subresources using `kubectl get`, table convertor support is added to
189+
the scale and status subresources for built-in and custom resource types.
187190

188191
For built-in types, `StatusStore` and `ScaleStore` are updated to implement the `TableConvertor` interface.
189192
`StatusStore` uses the same columns as the main resource object.
@@ -193,7 +196,7 @@ The following column definitions for the `Scale` object are added to [printers.g
193196
- `Desired Replicas` uses the json path of `.spec.replicas` of autoscalingv1.Scale object
194197

195198
For custom resources:
196-
- the status subresoruce uses the same columns as defined for the full resource, i.e., `additionalPrinterColumns` defined in the CRD.
199+
- the status subresource uses the same columns as defined for the full resource, i.e., `additionalPrinterColumns` defined in the CRD.
197200
- the scale subresource follows the same column definitions as the built-in types, and are defined in [helpers.go].
198201

199202
[printers.go]: https://github.com/kubernetes/kubernetes/blob/master/pkg/printers/internalversion/printers.go#L88
@@ -207,45 +210,57 @@ to implement this enhancement.
207210

208211
##### Unit tests
209212

210-
- `k8s.io/kubernetes/pkg/printers/internalversion`: `2023-01-12` - 71.2
211-
- `k8s.io/kubernetes/vendor/k8s.io/cli-runtime/pkg/resource`: `2023-01-12` - 70.9
212-
- `k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/edit`: `2023-01-12` - 100
213-
- `k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/get`: `2023-01-12` - 80.7
214-
- `k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/patch`: `2023-01-12` - 56.3
215-
- `k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/replace`: `2023-01-12` - 63.6
213+
- `k8s.io/kubernetes/pkg/printers/internalversion`: `2025-01-23` - 73.5
214+
- `k8s.io/cli-runtime/pkg/resource`: `2025-01-23` - 71.8
215+
- `k8s.io/kubectl/pkg/cmd/apply`: `2025-01-23` - 82
216+
- `k8s.io/kubectl/pkg/cmd/edit`: `2025-01-23` - 100
217+
- `k8s.io/kubectl/pkg/cmd/get`: `2025-01-23` - 80.8
218+
- `k8s.io/kubectl/pkg/cmd/patch`: `2025-01-23` - 56.4
219+
- `k8s.io/kubectl/pkg/cmd/replace`: `2025-01-23` - 63.8
216220

217221
##### Integration tests
218222

219-
- `kubectl get`: [link to test coverage](https://github.com/kubernetes/kubernetes/blob/4802d7bb62c2623be8e4f940f6b5c1fcddd6c744/test/cmd/get.sh#L178-L184)
223+
- [kubectl get](https://github.com/kubernetes/kubernetes/blob/00fa8f119077da3c96090aa5efc5dfc9c5a78977/test/cmd/get.sh#L178-L184): https://storage.googleapis.com/k8s-triage/index.html?pr=1&job=pull-kubernetes-integration&test=test-cmd%3A%20run_kubectl_get_tests
224+
- [kubectl apply](https://github.com/kubernetes/kubernetes/blob/00fa8f119077da3c96090aa5efc5dfc9c5a78977/test/cmd/apply.sh#L417): https://storage.googleapis.com/k8s-triage/index.html?pr=1&job=pull-kubernetes-integration&test=test-cmd%3A%20run_kubectl_server_side_apply_tests
225+
- [TestGetSubresourcesAsTables](https://github.com/kubernetes/kubernetes/blob/00fa8f119077da3c96090aa5efc5dfc9c5a78977/test/integration/apiserver/apiserver_test.go#L1458-L1678): https://storage.googleapis.com/k8s-triage/index.html?pr=1&job=pull-kubernetes-integration&test=TestGetSubresourcesAsTables
226+
- [TestGetScaleSubresourceAsTableForAllBuiltins](https://github.com/kubernetes/kubernetes/blob/ed9572d9c7733602de43979caf886fd4092a7b0f/test/integration/apiserver/apiserver_test.go#L1681-L1876): https://storage.googleapis.com/k8s-triage/index.html?pr=1&job=pull-kubernetes-integration&test=TestGetScaleSubresourceAsTableForAllBuiltins
220227

221228
##### e2e tests
222229

230+
- [kubectl subresource flag](https://github.com/kubernetes/kubernetes/blob/00fa8f119077da3c96090aa5efc5dfc9c5a78977/test/e2e/kubectl/kubectl.go#L2090-L2118): https://testgrid.k8s.io/sig-testing-canaries#ci-kubernetes-coverage-e2e-gci-gce&include-filter-by-regex=kubectl%20subresource
231+
223232
### Graduation Criteria
224233

225234
#### Alpha
226235

227-
- Add the `--subresource` flag to get, patch, edit and replace commands.
236+
- Add the `--subresource` flag to `get`, `patch`, `edit` and `replace` subcommands.
228237
- Unit tests and integration tests are added.
229238

230239
#### Beta
231240

232241
- Gather feedback from users.
233242
- e2e tests are added.
243+
- Add the `--subresource` flag to `apply` subcommand.
234244

235245
#### GA
236246

237-
- User feedback gathered for at least 1 cycle.
247+
Since v1.27 when the feature moved to beta, there have been no reported bugs concerning this feature.
248+
In fact, it is reassuring to see the community use this feature quite commonly such as in bug reports:
249+
https://github.com/kubernetes/kubernetes/issues/116311
238250

251+
Seeing this and given our added unit, integration and e2e tests gives us the confidence to graduate to stable.
239252

240253
### Upgrade / Downgrade Strategy
241254

242-
This functionality is contained entirely within kubectl and shares its strategy.
243-
No configuration changes are required.
255+
See [Version Skew Strategy](#version-skew-strategy).
244256

245257
### Version Skew Strategy
246258

247-
Not applicable. There is nothing required of the API Server, so there
248-
can be no version skew.
259+
The [kube-apiserver functionality](https://github.com/kubernetes/kubernetes/pull/103516)
260+
required for the `--subresource` flag to work correctly was introduced in Kubernetes v1.24.
261+
The current release (v1.33) exceeds the [supported version skew policy](https://kubernetes.io/releases/version-skew-policy/).
262+
Therefore, there are no requirements for planning the upgrade or downgrade process.
263+
needs to be completed.
249264

250265
## Production Readiness Review Questionnaire
251266

@@ -262,21 +277,21 @@ Pick one of these and delete the rest.
262277
- Components depending on the feature gate:
263278
- [x] Other
264279
- Describe the mechanism: A new flag for kubectl commands.
265-
For the alpha stage, description will be added to expicitly call
280+
For the alpha stage, description will be added to explicitly call
266281
out this flag as an alpha feature.
267282
- Will enabling / disabling the feature require downtime of the control
268-
plane? No, disabling the feature would be a client behaviour.
283+
plane? No, disabling the feature would be a client behavior.
269284
- Will enabling / disabling the feature require downtime or reprovisioning
270-
of a node?
271-
No, disabling the feature would be a client behaviour.
285+
of a node?
286+
No, disabling the feature would be a client behavior.
272287

273288
###### Does enabling the feature change any default behavior?
274289

275290
While the feature now updates kubectl's behavior to allow updating subresources,
276291
it is gated by the `--subresource` flag so it does not change kubectl's default
277292
behavior.
278293

279-
Subresources can also be updated using curl today so this feature only
294+
Subresources can also be updated using `curl` today so this feature only
280295
provides a consistent way to use the API via kubectl, but does not allow additional
281296
changes to the API that are not possible today.
282297

@@ -287,8 +302,8 @@ for the `--subresource` flag and the ability to update subresources via kubectl.
287302

288303
However, this does not "lock" us to any changes to the subresources that were made
289304
when the feature was enabled i.e. it does not remove the ability to update subresources
290-
for existing API resources completely. If a subresource of an exisiting API resource needs
291-
to be updated, this can be done via curl.
305+
for existing API resources completely. If a subresource of an existing API resource needs
306+
to be updated, this can be done via `curl`.
292307

293308
###### What happens if we reenable the feature if it was previously rolled back?
294309

@@ -300,31 +315,25 @@ No, because it cannot be disabled or enabled in a single release.
300315

301316
### Rollout, Upgrade and Rollback Planning
302317

303-
<!--
304-
This section must be completed when targeting beta to a release.
305-
-->
306-
307318
###### How can a rollout fail? Can it impact already running workloads?
308319

309320
The feature is encapsulated entirely within the kubectl binary, so rollout is
310-
an atomic client binary update. Subresources can always be updated via curl,
321+
an atomic client binary update. Subresources can always be updated via `curl`,
311322
so there are no version dependencies.
312323

324+
For kube-apiserver changes see [Version Skew Strategy](#version-skew-strategy).
325+
313326
###### What specific metrics should inform a rollback?
314327

315328
N/A
316329

317330
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
318331

319-
This feature is completely with in the client. The upgrades and rollback of cluster will not be affected by this change.
332+
This feature is completely within the client. The upgrades and rollback of cluster will not be affected by this change.
320333
The update and downgrade of the kubectl version will only limit the availability of the `--subresource` flag and will not
321334
change any API behavior.
322335

323-
<!--
324-
Describe manual testing that was done and the outcomes.
325-
Longer term, we may want to require automated upgrade/rollback tests, but we
326-
are missing a bunch of machinery and tooling and can't do that now.
327-
-->
336+
For kube-apiserver changes see [Version Skew Strategy](#version-skew-strategy).
328337

329338
###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.?
330339

@@ -334,14 +343,21 @@ No.
334343

335344
###### How can an operator determine if the feature is in use by workloads?
336345

337-
N/A
346+
Cluster administrator can verify [audit entries](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/)
347+
looking for `kubectl` invocations targeting `scale` and `status` subresources.
338348

339-
###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service?
349+
###### How can someone using this feature know that it is working for their instance?
340350

341351
N/A
342352

343353
###### What are the reasonable SLOs (Service Level Objectives) for the above SLIs?
344354

355+
Since this functionality doesn't heavily modify kube-apiserver I'd expected
356+
the SLO defined [here](https://github.com/kubernetes/community/blob/master/sig-scalability/slos/slos.md)
357+
to apply.
358+
359+
###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service?
360+
345361
N/A
346362

347363
###### Are there any missing metrics that would be useful to have to improve observability of this feature?
@@ -352,7 +368,7 @@ N/A
352368

353369
###### Does this feature depend on any specific services running in the cluster?
354370

355-
No
371+
No.
356372

357373
### Scalability
358374

@@ -388,6 +404,10 @@ No
388404

389405
No
390406

407+
###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)?
408+
409+
No
410+
391411
### Troubleshooting
392412

393413
###### How does this feature react if the API server and/or etcd is unavailable?
@@ -404,14 +424,17 @@ N/A
404424

405425
## Implementation History
406426

407-
2021-03-01: Initial [POC PR] created
427+
2021-03-01: Initial [POC PR] created
408428
2021-04-06: KEP proposed
409429
2021-04-07: [Demo] in SIG CLI meeting
410430
2022-05-25: PR for alpha implementation merged
431+
2023-01-12: KEP graduated to Beta
432+
2023-03-15: e2e test added for KEP as part of beta graduation
433+
2025-01-23: KEP graduated to Stable
411434

412435
[POC PR]: https://github.com/kubernetes/kubernetes/pull/99556
413436
[Demo]: https://youtu.be/zUa7dudYCQM?t=299
414437

415438
## Alternatives
416439

417-
Alternatives would be to use curl commands directly to update subresources.
440+
Alternatives would be to use `curl` commands directly to update subresources.

keps/sig-cli/2590-kubectl-subresource/kep.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ participating-sigs:
88
- sig-arch
99
reviewers:
1010
- "@soltysh"
11+
- "@MadhavJivrajani"
1112
approvers:
1213
- "@soltysh"
14+
- "@ardaguclu"
1315

1416
creation-date: 2021-04-06
15-
last-updated: 2023-01-12
17+
last-updated: 2025-01-23
1618

17-
status: implementable
18-
stage: beta
19+
status: implemented
20+
stage: stable
1921

20-
latest-milestone: "v1.27"
22+
latest-milestone: "v1.33"
2123

2224
milestone:
2325
alpha: "v1.24"
2426
beta: "v1.27"
27+
stable: "v1.33"

0 commit comments

Comments
 (0)