• Kubernetes Submit Queue's avatar
    Merge pull request #41304 from liggitt/edit-refactor · cf10f532
    Kubernetes Submit Queue authored
    Automatic merge from submit-queue
    
    Make kubectl edit work with unstructured objects
    
    Fixes https://github.com/kubernetes/kubernetes/issues/35993
    
    
    1. First (before any other changes), added several test cases for complex edit scenarios:
       - [x] ensure the edit loop bails out if given the same result that already caused errors
       - [x] ensure an edited file with a syntax error is reopened preserving the input
       - [x] ensure objects with existing "caused-by" annotations get updated with the current command
    
    2. Refactored the edit code to prep for switching to unstructured:
       - [x] made editFn operate on a slice of resource.Info objects passed as an arg, regardless of edit mode
       - [x] simplified short-circuiting logic when re-editing a file containing an error
       - [x] refactored how we build the various visitors (namespace enforcement, annotation application, patching, creating) so we could easily switch to just using a single visitor over a set of resource infos read from the updated input for all of them
    
    3. Switched to using a resource builder to parse the stream of the user's edited output
       - [x] improve the error message you get on syntax errors
       - [x] preserve the user's input more faithfully (see how the captured testcase requests to the server changed to reflect exactly what the user edited)
       - [x] stopped doing client-side conversion (means deprecating `--output-version`)
    
    4. Switched edit to work with generic objects
       - [x] use unstructured objects
       - [x] fall back to generic json merge patch for unrecognized group/version/kinds
    
    5. Added new test cases
       - [x] schemaless objects falls back to generic json merge (covers TPR scenario)
       - [x] edit unknown version of known kind (version "v0" of storageclass) falls back to generic json merge
    
    ```release-note
    `kubectl edit` now edits objects exactly as they were retrieved from the API. This allows using `kubectl edit` with third-party resources and extension API servers. Because client-side conversion is no longer done, the `--output-version` option is deprecated for `kubectl edit`. To edit using a particular API version, fully-qualify the resource, version, and group used to fetch the object (for example, `job.v1.batch/myjob`)
    ```
    cf10f532
Name
Last commit
Last update
..
cmd Loading commit data...
metricsutil Loading commit data...
resource Loading commit data...
testing Loading commit data...
BUILD Loading commit data...
OWNERS Loading commit data...
apply.go Loading commit data...
autoscale.go Loading commit data...
bash_comp_utils.go Loading commit data...
cluster.go Loading commit data...
cluster_test.go Loading commit data...
clusterrolebinding.go Loading commit data...
configmap.go Loading commit data...
configmap_test.go Loading commit data...
custom_column_printer.go Loading commit data...
custom_column_printer_test.go Loading commit data...
deployment.go Loading commit data...
deployment_test.go Loading commit data...
describe.go Loading commit data...
describe_test.go Loading commit data...
doc.go Loading commit data...
explain.go Loading commit data...
generate.go Loading commit data...
generate_test.go Loading commit data...
history.go Loading commit data...
interfaces.go Loading commit data...
kubectl.go Loading commit data...
kubectl_test.go Loading commit data...
namespace.go Loading commit data...
namespace_test.go Loading commit data...
pdb.go Loading commit data...
proxy_server.go Loading commit data...
proxy_server_test.go Loading commit data...
quota.go Loading commit data...
quota_test.go Loading commit data...
resource_filter.go Loading commit data...
resource_printer.go Loading commit data...
resource_printer_test.go Loading commit data...
rolebinding.go Loading commit data...
rollback.go Loading commit data...
rolling_updater.go Loading commit data...
rolling_updater_test.go Loading commit data...
rollout_status.go Loading commit data...
rollout_status_test.go Loading commit data...
run.go Loading commit data...
run_test.go Loading commit data...
scale.go Loading commit data...
scale_test.go Loading commit data...
secret.go Loading commit data...
secret_for_docker_registry.go Loading commit data...
secret_for_docker_registry_test.go Loading commit data...
secret_for_tls.go Loading commit data...
secret_for_tls_test.go Loading commit data...
secret_test.go Loading commit data...
service.go Loading commit data...
service_basic.go Loading commit data...
service_basic_test.go Loading commit data...
service_test.go Loading commit data...
serviceaccount.go Loading commit data...
serviceaccount_test.go Loading commit data...
sorted_resource_name_list.go Loading commit data...
sorted_resource_name_list_test.go Loading commit data...
sorting_printer.go Loading commit data...
sorting_printer_test.go Loading commit data...
stop.go Loading commit data...
stop_test.go Loading commit data...
versioned_client.go Loading commit data...