Merge pull request #54024 from pwittrock/resource-validation-deps

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

kubectl resource builder to use versioned list

Switch to using a versioned listed when return an object from the resource builder.

This is necessary to allow cli's built outside the kubernetes/kubernetes repo to vendor the resource builder logic without vendoring all of Kubernetes.

The following commands call the modified function.  (identified by changing the function name and recompiling)

- [x] `attach`
  - pkg/kubectl/cmd/attach.go:155: builder.Do().Object
  - passes to `AttachablePodForObject` which does not support Lists of any kind
- [x] `get`
  - pkg/kubectl/cmd/get.go:251: r.Object
  - [x] check if isList with `IsListType` -> `GetItemsPtr` -> check for presence of `Items` field
  - [x] pass to `ResourceVersion` -> `CommonAccessor` -> checks for `metav1.ListInterface` (which this PR introduces a compile time check to ensure v1.List implements this)
  - [x] pass to `ExtractList` -> checks if items implement `runtime.RawExtension`
- [x] `rolling_update`
  - pkg/kubectl/cmd/rollingupdate.go:207: request.Object
  - only accepts lists of length 1.  updated in PR to support both api.List and v1.List
- [x] `rollout_status`
  - pkg/kubectl/cmd/rollout/rollout_status.go:107: r.Object
  - passes to `ResourceVersion` -> `CommonAccessor` -> checks for `metav1.ListInterface`

```release-note
NONE
```

Closes kubernetes/kubectl#81
This commit is contained in:
Kubernetes Submit Queue
2017-10-20 21:31:10 -07:00
committed by GitHub
4 changed files with 30 additions and 15 deletions

View File

@@ -212,14 +212,14 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
var ok bool
// Handle filename input from stdin. The resource builder always returns an api.List
// when creating resource(s) from a stream.
if list, ok := obj.(*api.List); ok {
if list, ok := obj.(*v1.List); ok {
if len(list.Items) > 1 {
return cmdutil.UsageErrorf(cmd, "%s specifies multiple items", filename)
}
if len(list.Items) == 0 {
return cmdutil.UsageErrorf(cmd, "please make sure %s exists and is not empty", filename)
}
obj = list.Items[0]
obj = list.Items[0].Object
}
newRc, ok = obj.(*api.ReplicationController)
if !ok {