Reduce all uses of Unstructured to the simpler form, and avoid asking
for mapper or typer unless it is required. Use Typed() for places that
previously used VersionedObject, and remove paths for versioned objects
from code that is now using unstructured.
If a user edits last-applied-configuration and it doesn't have an
apiVersion or kind, the command should error out. Now that we check for
kind and version on the unstructured object typer, the previously
passing test now correctly fails. Add a new explicit failure test and
make the existing test pass.
Automatic merge from submit-queue (batch tested with PRs 50537, 49699, 50160, 49025, 50205)
not allowing "kubectl edit <resource>" when you got an empty list
**What this PR does / why we need it**:
`kubectl edit` will panic when adding an empty list.
> panic: runtime error: index out of range
**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes#50147
**Special notes for your reviewer**:
/assign @errordeveloper @mengqiy @janetkuo @fabianofranz
/cc @rootfs @soltysh @sttts
**Release note**:
```release-note
not allowing "kubectl edit <resource>" when you got an empty list
```
Automatic merge from submit-queue (batch tested with PRs 46091, 48280)
allow output patch string in edit command
**What this PR does / why we need it**:
allow user to get the patch from edit command if user is not familiar with the patch format.
```
# ./cluster/kubectl.sh create role a --verb=get,list --resource=no
role "a" created
# ./cluster/kubectl.sh edit role a --output-patch=true
Patch: {"rules":[{"apiGroups":[""],"resources":["nodes"],"verbs":["get","list","delete"]}]}
role "a" edited
# ./cluster/kubectl.sh create role b --verb=get,list --resource=no
role "b" created
# ./cluster/kubectl.sh patch role b -p '{"rules":[{"apiGroups":[""],"resources":["nodes"],"verbs":["get","list","delete"]}]}'
role "b" patched
```
**Which issue this PR fixes**: fixes#47173
**Special notes for your reviewer**:
**Release note**:
```release-note
Could get the patch from kubectl edit command
```
**What this PR does / why we need it**:
Visibility rules allow dependency control. The rules currently in
place make all targets public, to override the default state of
private. This PR removes public visibility from kubectl code. It
uses specially named pacakge groups to identify "bad" dependencies on
kubectl code for later refactoring or removal.
**Which issue this PR fixes**
First in a series of PRs to address kubernetes/community#598
**Release note**:
```release-note
NONE
```
mark --output-version as deprecated, add example for fully-qualifying version to edit
Add 'kubectl edit' testcase for editing schemaed and schemaless data together
Add 'kubectl edit' testcase for editing unknown version of known group/kind
edit: make editFn operate on arguments regardless of mode
edit: simplify short-circuiting logic when re-editing a file containing an error
edit: factor out visitor building
edit: use resource builder to get results from edited file
Add 'kubectl edit' testcase for saving a repeated error
Add 'kubectl edit' testcase for preserving an edited file with a syntax error
Add 'kubectl edit' testcase for recording command on list of objects