Switch 'kubectl edit' to use unstructured objects, handle schemaless objects

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
This commit is contained in:
Jordan Liggitt
2017-02-12 19:31:06 -05:00
parent 5b805bc18a
commit ec271f5c09
25 changed files with 622 additions and 133 deletions

View File

@@ -0,0 +1,32 @@
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "kubernetes",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/services/kubernetes",
"uid": "6a8e8829-f15f-11e6-b041-acbc32c1ca87",
"resourceVersion": "16953",
"creationTimestamp": "2017-02-12T20:11:19Z",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"ports": [
{
"name": "https",
"protocol": "TCP",
"port": 443,
"targetPort": 443
}
],
"clusterIP": "10.0.0.1",
"type": "ClusterIP",
"sessionAffinity": "ClientIP"
},
"status": {
"loadBalancer": {}
}
}

View File

@@ -0,0 +1,16 @@
{
"apiVersion": "company.com/v1",
"kind": "Bar",
"metadata": {
"name": "test",
"namespace": "default",
"selfLink": "/apis/company.com/v1/namespaces/default/bars/test",
"uid": "fd16c23d-f185-11e6-b041-acbc32c1ca87",
"resourceVersion": "16954",
"creationTimestamp": "2017-02-13T00:47:26Z"
},
"some-field": "field1",
"third-field": {
"sub-field": "bar2"
}
}

View File

@@ -0,0 +1,21 @@
{
"apiVersion": "company.com/v1",
"field1": "value1",
"field2": true,
"field3": [
1
],
"field4": {
"a": true,
"b": false
},
"kind": "Bar",
"metadata": {
"name": "test2",
"namespace": "default",
"selfLink": "/apis/company.com/v1/namespaces/default/bars/test2",
"uid": "5ef5b446-f186-11e6-b041-acbc32c1ca87",
"resourceVersion": "16955",
"creationTimestamp": "2017-02-13T00:50:10Z"
}
}

View File

@@ -0,0 +1,62 @@
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
items:
- apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2017-02-12T20:11:19Z
labels:
component: apiserver
provider: kubernetes
new-label: new-value
name: kubernetes
namespace: default
resourceVersion: "16953"
selfLink: /api/v1/namespaces/default/services/kubernetes
uid: 6a8e8829-f15f-11e6-b041-acbc32c1ca87
spec:
clusterIP: 10.0.0.1
ports:
- name: https
port: 443
protocol: TCP
targetPort: 443
sessionAffinity: ClientIP
type: ClusterIP
status:
loadBalancer: {}
- apiVersion: company.com/v1
kind: Bar
metadata:
creationTimestamp: 2017-02-13T00:47:26Z
name: test
namespace: default
resourceVersion: "16954"
selfLink: /apis/company.com/v1/namespaces/default/bars/test
uid: fd16c23d-f185-11e6-b041-acbc32c1ca87
some-field: field1
other-field: other-value
third-field:
sub-field: bar2
- apiVersion: company.com/v1
field1: value1
field2: true
field3:
- 1
- 2
field4:
a: true
b: false
kind: Bar
metadata:
creationTimestamp: 2017-02-13T00:50:10Z
name: test2
namespace: default
resourceVersion: "16955"
selfLink: /apis/company.com/v1/namespaces/default/bars/test2
uid: 5ef5b446-f186-11e6-b041-acbc32c1ca87
kind: List
metadata: {}

View File

@@ -0,0 +1,59 @@
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
items:
- apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2017-02-12T20:11:19Z
labels:
component: apiserver
provider: kubernetes
name: kubernetes
namespace: default
resourceVersion: "16953"
selfLink: /api/v1/namespaces/default/services/kubernetes
uid: 6a8e8829-f15f-11e6-b041-acbc32c1ca87
spec:
clusterIP: 10.0.0.1
ports:
- name: https
port: 443
protocol: TCP
targetPort: 443
sessionAffinity: ClientIP
type: ClusterIP
status:
loadBalancer: {}
- apiVersion: company.com/v1
kind: Bar
metadata:
creationTimestamp: 2017-02-13T00:47:26Z
name: test
namespace: default
resourceVersion: "16954"
selfLink: /apis/company.com/v1/namespaces/default/bars/test
uid: fd16c23d-f185-11e6-b041-acbc32c1ca87
some-field: field1
third-field:
sub-field: bar2
- apiVersion: company.com/v1
field1: value1
field2: true
field3:
- 1
field4:
a: true
b: false
kind: Bar
metadata:
creationTimestamp: 2017-02-13T00:50:10Z
name: test2
namespace: default
resourceVersion: "16955"
selfLink: /apis/company.com/v1/namespaces/default/bars/test2
uid: 5ef5b446-f186-11e6-b041-acbc32c1ca87
kind: List
metadata: {}

View File

@@ -0,0 +1,7 @@
{
"metadata": {
"labels": {
"new-label": "new-value"
}
}
}

View File

@@ -0,0 +1,33 @@
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "kubernetes",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/services/kubernetes",
"uid": "6a8e8829-f15f-11e6-b041-acbc32c1ca87",
"resourceVersion": "17087",
"creationTimestamp": "2017-02-12T20:11:19Z",
"labels": {
"component": "apiserver",
"new-label": "new-value",
"provider": "kubernetes"
}
},
"spec": {
"ports": [
{
"name": "https",
"protocol": "TCP",
"port": 443,
"targetPort": 443
}
],
"clusterIP": "10.0.0.1",
"type": "ClusterIP",
"sessionAffinity": "ClientIP"
},
"status": {
"loadBalancer": {}
}
}

View File

@@ -0,0 +1,3 @@
{
"other-field": "other-value"
}

View File

@@ -0,0 +1,17 @@
{
"apiVersion": "company.com/v1",
"kind": "Bar",
"metadata": {
"name": "test",
"namespace": "default",
"selfLink": "/apis/company.com/v1/namespaces/default/bars/test",
"uid": "fd16c23d-f185-11e6-b041-acbc32c1ca87",
"resourceVersion": "17088",
"creationTimestamp": "2017-02-13T00:47:26Z"
},
"other-field": "other-value",
"some-field": "field1",
"third-field": {
"sub-field": "bar2"
}
}

View File

@@ -0,0 +1,6 @@
{
"field3": [
1,
2
]
}

View File

@@ -0,0 +1,22 @@
{
"apiVersion": "company.com/v1",
"field1": "value1",
"field2": true,
"field3": [
1,
2
],
"field4": {
"a": true,
"b": false
},
"kind": "Bar",
"metadata": {
"name": "test2",
"namespace": "default",
"selfLink": "/apis/company.com/v1/namespaces/default/bars/test2",
"uid": "5ef5b446-f186-11e6-b041-acbc32c1ca87",
"resourceVersion": "17089",
"creationTimestamp": "2017-02-13T00:50:10Z"
}
}

View File

@@ -0,0 +1,55 @@
description: edit a mix of schema and schemaless data
mode: edit
args:
- service/kubernetes
- bars/test
- bars/test2
namespace: default
expectedStdout:
- "service \"kubernetes\" edited"
- "bar \"test\" edited"
- "bar \"test2\" edited"
expectedExitCode: 0
steps:
- type: request
expectedMethod: GET
expectedPath: /api/v1/namespaces/default/services/kubernetes
expectedInput: 0.request
resultingStatusCode: 200
resultingOutput: 0.response
- type: request
expectedMethod: GET
expectedPath: /apis/company.com/v1/namespaces/default/bars/test
expectedInput: 1.request
resultingStatusCode: 200
resultingOutput: 1.response
- type: request
expectedMethod: GET
expectedPath: /apis/company.com/v1/namespaces/default/bars/test2
expectedInput: 2.request
resultingStatusCode: 200
resultingOutput: 2.response
- type: edit
expectedInput: 3.original
resultingOutput: 3.edited
- type: request
expectedMethod: PATCH
expectedPath: /api/v1/namespaces/default/services/kubernetes
expectedContentType: application/strategic-merge-patch+json
expectedInput: 4.request
resultingStatusCode: 200
resultingOutput: 4.response
- type: request
expectedMethod: PATCH
expectedPath: /apis/company.com/v1/namespaces/default/bars/test
expectedContentType: application/merge-patch+json
expectedInput: 5.request
resultingStatusCode: 200
resultingOutput: 5.response
- type: request
expectedMethod: PATCH
expectedPath: /apis/company.com/v1/namespaces/default/bars/test2
expectedContentType: application/merge-patch+json
expectedInput: 6.request
resultingStatusCode: 200
resultingOutput: 6.response

View File

@@ -0,0 +1,22 @@
{
"kind": "StorageClass",
"apiVersion": "storage.k8s.io/v0",
"metadata": {
"name": "foo",
"selfLink": "/apis/storage.k8s.io/v0/storageclassesfoo",
"uid": "b2287558-f190-11e6-b041-acbc32c1ca87",
"resourceVersion": "21388",
"creationTimestamp": "2017-02-13T02:04:04Z",
"labels": {
"label1": "value1"
}
},
"provisioner": "foo",
"parameters": {
"baz": "qux",
"foo": "bar"
},
"extraField": {
"otherData": true
}
}

View File

@@ -0,0 +1,22 @@
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: storage.k8s.io/v0
extraField:
otherData: true
addedData: "foo"
kind: StorageClass
metadata:
creationTimestamp: 2017-02-13T02:04:04Z
labels:
label1: value1
label2: value2
name: foo
resourceVersion: "21388"
selfLink: /apis/storage.k8s.io/v0/storageclassesfoo
uid: b2287558-f190-11e6-b041-acbc32c1ca87
parameters:
baz: qux
foo: bar
provisioner: foo

View File

@@ -0,0 +1,20 @@
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: storage.k8s.io/v0
extraField:
otherData: true
kind: StorageClass
metadata:
creationTimestamp: 2017-02-13T02:04:04Z
labels:
label1: value1
name: foo
resourceVersion: "21388"
selfLink: /apis/storage.k8s.io/v0/storageclassesfoo
uid: b2287558-f190-11e6-b041-acbc32c1ca87
parameters:
baz: qux
foo: bar
provisioner: foo

View File

@@ -0,0 +1,11 @@
{
"extraField": {
"addedData": "foo"
},
"metadata": {
"labels": {
"label2": "value2"
},
"namespace": ""
}
}

View File

@@ -0,0 +1,24 @@
{
"kind": "StorageClass",
"apiVersion": "storage.k8s.io/v0",
"metadata": {
"name": "foo",
"selfLink": "/apis/storage.k8s.io/v0/storageclassesfoo",
"uid": "b2287558-f190-11e6-b041-acbc32c1ca87",
"resourceVersion": "21431",
"creationTimestamp": "2017-02-13T02:04:04Z",
"labels": {
"label1": "value1",
"label2": "value2"
}
},
"provisioner": "foo",
"parameters": {
"baz": "qux",
"foo": "bar"
},
"extraField": {
"otherData": true,
"addedData": true
}
}

View File

@@ -0,0 +1,25 @@
description: edit an unknown version of a known group/kind
mode: edit
args:
- storageclasses.v0.storage.k8s.io/foo
namespace: default
expectedStdout:
- "storageclass \"foo\" edited"
expectedExitCode: 0
steps:
- type: request
expectedMethod: GET
expectedPath: /apis/storage.k8s.io/v0/storageclasses/foo
expectedInput: 0.request
resultingStatusCode: 200
resultingOutput: 0.response
- type: edit
expectedInput: 1.original
resultingOutput: 1.edited
- type: request
expectedMethod: PATCH
expectedPath: /apis/storage.k8s.io/v0/storageclasses/foo
expectedContentType: application/merge-patch+json
expectedInput: 2.request
resultingStatusCode: 200
resultingOutput: 2.response