Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kubectl edit work with unstructured objects #41304

Merged
merged 3 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
296 changes: 147 additions & 149 deletions pkg/kubectl/cmd/edit.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pkg/kubectl/cmd/edit_test.go
Expand Up @@ -205,9 +205,9 @@ func TestEdit(t *testing.T) {
t.Fatalf("%s: %v", name, err)
}

f, tf, _, ns := cmdtesting.NewAPIFactory()
f, tf, _, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.ClientForMappingFunc = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
tf.UnstructuredClientForMappingFunc = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
versionedAPIPath := ""
if mapping.GroupVersionKind.Group == "" {
versionedAPIPath = "/api/" + mapping.GroupVersionKind.Version
Expand All @@ -217,7 +217,7 @@ func TestEdit(t *testing.T) {
return &fake.RESTClient{
APIRegistry: api.Registry,
VersionedAPIPath: versionedAPIPath,
NegotiatedSerializer: ns, //unstructuredSerializer,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(reqResp),
}, nil
}
Expand All @@ -226,6 +226,7 @@ func TestEdit(t *testing.T) {
tf.Namespace = testcase.Namespace
}
tf.ClientConfig = defaultClientConfig()
tf.Command = "edit test cmd invocation"
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})

Expand Down
21 changes: 11 additions & 10 deletions pkg/kubectl/cmd/testdata/edit/testcase-create-list-error/1.request
@@ -1,31 +1,32 @@
{
"kind": "Service",
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "svc1",
"namespace": "edit-test",
"selfLink": "/api/v1/namespaces/edit-test/services/svc1",
"uid": "4149f70e-e9dc-11e6-8c3b-acbc32c1ca87",
"creationTimestamp": "2017-02-03T06:44:47Z",
"labels": {
"app": "svc1modified"
}
},
"name": "svc1",
"namespace": "edit-test",
"resourceVersion": "",
"selfLink": "/api/v1/namespaces/edit-test/services/svc1",
"uid": "4149f70e-e9dc-11e6-8c3b-acbc32c1ca87"
},
"spec": {
"clusterIP": "10.0.0.118",
"ports": [
{
"name": "81",
"protocol": "TCP",
"port": 82,
"protocol": "TCP",
"targetPort": 81
}
],
"selector": {
"app": "svc1"
},
"clusterIP": "10.0.0.118",
"type": "ClusterIP",
"sessionAffinity": "None"
"sessionAffinity": "None",
"type": "ClusterIP"
},
"status": {
"loadBalancer": {}
Expand Down
21 changes: 11 additions & 10 deletions pkg/kubectl/cmd/testdata/edit/testcase-create-list-error/3.request
@@ -1,31 +1,32 @@
{
"kind": "Service",
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "svc2",
"namespace": "edit-test",
"selfLink": "/api/v1/namespaces/edit-test/services/svc2",
"uid": "3e9b10db-e9dc-11e6-8c3b-acbc32c1ca87",
"creationTimestamp": "2017-02-03T06:44:43Z",
"labels": {
"app": "svc2modified"
}
},
"name": "svc2",
"namespace": "edit-test",
"resourceVersion": "",
"selfLink": "/api/v1/namespaces/edit-test/services/svc2",
"uid": "3e9b10db-e9dc-11e6-8c3b-acbc32c1ca87"
},
"spec": {
"clusterIP": "10.0.0.182.1",
"ports": [
{
"name": "80",
"protocol": "VHF",
"port": 80,
"protocol": "VHF",
"targetPort": 80
}
],
"selector": {
"app": "svc2"
},
"clusterIP": "10.0.0.182.1",
"type": "ClusterIP",
"sessionAffinity": "None"
"sessionAffinity": "None",
"type": "ClusterIP"
},
"status": {
"loadBalancer": {}
Expand Down
18 changes: 7 additions & 11 deletions pkg/kubectl/cmd/testdata/edit/testcase-create-list/1.request
@@ -1,31 +1,27 @@
{
"kind": "Service",
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "svc1",
"namespace": "edit-test",
"creationTimestamp": null,
"labels": {
"app": "svc1",
"new-label": "new-value"
}
},
"name": "svc1",
"namespace": "edit-test"
},
"spec": {
"ports": [
{
"name": "81",
"protocol": "TCP",
"port": 82,
"protocol": "TCP",
"targetPort": 81
}
],
"selector": {
"app": "svc1"
},
"type": "ClusterIP",
"sessionAffinity": "None"
},
"status": {
"loadBalancer": {}
"sessionAffinity": "None",
"type": "ClusterIP"
}
}
18 changes: 7 additions & 11 deletions pkg/kubectl/cmd/testdata/edit/testcase-create-list/3.request
@@ -1,31 +1,27 @@
{
"kind": "Service",
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "svc2",
"namespace": "edit-test",
"creationTimestamp": null,
"labels": {
"app": "svc2"
}
},
"name": "svc2",
"namespace": "edit-test"
},
"spec": {
"ports": [
{
"name": "80",
"protocol": "TCP",
"port": 80,
"protocol": "TCP",
"targetPort": 81
}
],
"selector": {
"app": "svc2",
"new-label": "new-value"
},
"type": "ClusterIP",
"sessionAffinity": "None"
},
"status": {
"loadBalancer": {}
"sessionAffinity": "None",
"type": "ClusterIP"
}
}
Empty file.
19 changes: 19 additions & 0 deletions pkg/kubectl/cmd/testdata/edit/testcase-list-record/0.response
@@ -0,0 +1,19 @@
{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "cm1",
"namespace": "edit-test",
"selfLink": "/api/v1/namespaces/edit-test/configmaps/cm1",
"uid": "b09bffab-e9d7-11e6-8c3b-acbc32c1ca87",
"resourceVersion": "1414",
"creationTimestamp": "2017-02-03T06:12:07Z",
"annotations":{"kubernetes.io/change-cause":"original creating command a"}
},
"data": {
"baz": "qux",
"foo": "changed-value",
"new-data": "new-value",
"new-data2": "new-value"
}
}
Empty file.
33 changes: 33 additions & 0 deletions pkg/kubectl/cmd/testdata/edit/testcase-list-record/1.response
@@ -0,0 +1,33 @@
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "svc1",
"namespace": "edit-test",
"selfLink": "/api/v1/namespaces/edit-test/services/svc1",
"uid": "9bec82be-e9d7-11e6-8c3b-acbc32c1ca87",
"resourceVersion": "1064",
"creationTimestamp": "2017-02-03T06:11:32Z",
"annotations":{"kubernetes.io/change-cause":"original creating command b"},
"labels": {
"app": "svc1",
"new-label": "foo"
}
},
"spec": {
"ports": [
{
"name": "80",
"protocol": "TCP",
"port": 81,
"targetPort": 81
}
],
"clusterIP": "10.0.0.248",
"type": "ClusterIP",
"sessionAffinity": "None"
},
"status": {
"loadBalancer": {}
}
}
51 changes: 51 additions & 0 deletions pkg/kubectl/cmd/testdata/edit/testcase-list-record/2.edited
@@ -0,0 +1,51 @@
# 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
data:
baz: qux
foo: changed-value
new-data: new-value
new-data2: new-value
new-data3: newivalue
kind: ConfigMap
metadata:
annotations:
kubernetes.io/change-cause: original creating command a
creationTimestamp: 2017-02-03T06:12:07Z
name: cm1
namespace: edit-test
resourceVersion: "1414"
selfLink: /api/v1/namespaces/edit-test/configmaps/cm1
uid: b09bffab-e9d7-11e6-8c3b-acbc32c1ca87
- apiVersion: v1
kind: Service
metadata:
annotations:
kubernetes.io/change-cause: original creating command b
creationTimestamp: 2017-02-03T06:11:32Z
labels:
app: svc1
new-label: foo
new-label2: foo2
name: svc1
namespace: edit-test
resourceVersion: "1064"
selfLink: /api/v1/namespaces/edit-test/services/svc1
uid: 9bec82be-e9d7-11e6-8c3b-acbc32c1ca87
spec:
clusterIP: 10.0.0.248
ports:
- name: "80"
port: 82
protocol: TCP
targetPort: 81
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
kind: List
metadata: {}
49 changes: 49 additions & 0 deletions pkg/kubectl/cmd/testdata/edit/testcase-list-record/2.original
@@ -0,0 +1,49 @@
# 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
data:
baz: qux
foo: changed-value
new-data: new-value
new-data2: new-value
kind: ConfigMap
metadata:
annotations:
kubernetes.io/change-cause: original creating command a
creationTimestamp: 2017-02-03T06:12:07Z
name: cm1
namespace: edit-test
resourceVersion: "1414"
selfLink: /api/v1/namespaces/edit-test/configmaps/cm1
uid: b09bffab-e9d7-11e6-8c3b-acbc32c1ca87
- apiVersion: v1
kind: Service
metadata:
annotations:
kubernetes.io/change-cause: original creating command b
creationTimestamp: 2017-02-03T06:11:32Z
labels:
app: svc1
new-label: foo
name: svc1
namespace: edit-test
resourceVersion: "1064"
selfLink: /api/v1/namespaces/edit-test/services/svc1
uid: 9bec82be-e9d7-11e6-8c3b-acbc32c1ca87
spec:
clusterIP: 10.0.0.248
ports:
- name: "80"
port: 81
protocol: TCP
targetPort: 81
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
kind: List
metadata: {}
10 changes: 10 additions & 0 deletions pkg/kubectl/cmd/testdata/edit/testcase-list-record/3.request
@@ -0,0 +1,10 @@
{
"data": {
"new-data3": "newivalue"
},
"metadata": {
"annotations": {
"kubernetes.io/change-cause": "edit test cmd invocation"
}
}
}
20 changes: 20 additions & 0 deletions pkg/kubectl/cmd/testdata/edit/testcase-list-record/3.response
@@ -0,0 +1,20 @@
{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "cm1",
"namespace": "edit-test",
"selfLink": "/api/v1/namespaces/edit-test/configmaps/cm1",
"uid": "b09bffab-e9d7-11e6-8c3b-acbc32c1ca87",
"resourceVersion": "1465",
"creationTimestamp": "2017-02-03T06:12:07Z",
"annotations":{"kubernetes.io/change-cause":"edit test cmd invocation"}
},
"data": {
"baz": "qux",
"foo": "changed-value",
"new-data": "new-value",
"new-data2": "new-value",
"new-data3": "newivalue"
}
}