mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
kubectl apply edit-last-applied should fail when version is missing
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.
This commit is contained in:
0
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/0.request
vendored
Executable file
0
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/0.request
vendored
Executable file
21
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/0.response
vendored
Executable file
21
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/0.response
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"kind": "ConfigMap",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "cm1",
|
||||
"namespace": "myproject",
|
||||
"selfLink": "/api/v1/namespaces/myproject/configmaps/cm1",
|
||||
"uid": "cc08a131-3d6f-11e7-8ef0-c85b76034b7b",
|
||||
"resourceVersion": "3518",
|
||||
"creationTimestamp": "2017-05-20T15:20:03Z",
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"baz\":\"qux\",\"foo\":\"changed-value\",\"new-data\":\"new-value\",\"new-data2\":\"new-value\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"cm1\",\"namespace\":\"myproject\"}}\n"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
"baz": "qux",
|
||||
"foo": "changed-value",
|
||||
"new-data": "new-value",
|
||||
"new-data2": "new-value"
|
||||
}
|
||||
}
|
0
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/1.request
vendored
Executable file
0
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/1.request
vendored
Executable file
35
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/1.response
vendored
Executable file
35
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/1.response
vendored
Executable file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "svc1",
|
||||
"namespace": "myproject",
|
||||
"selfLink": "/api/v1/namespaces/myproject/services/svc1",
|
||||
"uid": "d8b96f0b-3d6f-11e7-8ef0-c85b76034b7b",
|
||||
"resourceVersion": "3525",
|
||||
"creationTimestamp": "2017-05-20T15:20:24Z",
|
||||
"labels": {
|
||||
"app": "svc1",
|
||||
"new-label": "foo"
|
||||
},
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"svc1\",\"new-label\":\"foo\"},\"name\":\"svc1\",\"namespace\":\"myproject\"},\"spec\":{\"ports\":[{\"name\":\"80\",\"port\":81,\"protocol\":\"TCP\",\"targetPort\":81}],\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "80",
|
||||
"protocol": "TCP",
|
||||
"port": 81,
|
||||
"targetPort": 81
|
||||
}
|
||||
],
|
||||
"clusterIP": "172.30.32.183",
|
||||
"type": "ClusterIP",
|
||||
"sessionAffinity": "None"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
}
|
38
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/2.edited
vendored
Executable file
38
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/2.edited
vendored
Executable file
@@ -0,0 +1,38 @@
|
||||
# Please edit the 'last-applied-configuration' annotations below.
|
||||
# Lines beginning with a '#' will be ignored, and an empty file will abort the edit.
|
||||
#
|
||||
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: {}
|
||||
name: cm1
|
||||
namespace: myproject
|
||||
- kind: Service
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: svc1
|
||||
new-label: foo
|
||||
new-label2: foo2
|
||||
name: svc1
|
||||
namespace: myproject
|
||||
spec:
|
||||
ports:
|
||||
- name: "80"
|
||||
port: 82
|
||||
protocol: TCP
|
||||
targetPort: 81
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
||||
status:
|
||||
loadBalancer: {}
|
||||
kind: List
|
||||
metadata: {}
|
36
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/2.original
vendored
Executable file
36
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/2.original
vendored
Executable file
@@ -0,0 +1,36 @@
|
||||
# Please edit the 'last-applied-configuration' annotations below.
|
||||
# Lines beginning with a '#' will be ignored, and an empty file will abort the edit.
|
||||
#
|
||||
apiVersion: v1
|
||||
items:
|
||||
- apiVersion: v1
|
||||
data:
|
||||
baz: qux
|
||||
foo: changed-value
|
||||
new-data: new-value
|
||||
new-data2: new-value
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
name: cm1
|
||||
namespace: myproject
|
||||
- kind: Service
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: svc1
|
||||
new-label: foo
|
||||
name: svc1
|
||||
namespace: myproject
|
||||
spec:
|
||||
ports:
|
||||
- name: "80"
|
||||
port: 81
|
||||
protocol: TCP
|
||||
targetPort: 81
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
||||
status:
|
||||
loadBalancer: {}
|
||||
kind: List
|
||||
metadata: {}
|
41
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/3.edited
vendored
Normal file
41
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/3.edited
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# Please edit the 'last-applied-configuration' annotations below.
|
||||
# Lines beginning with a '#' will be ignored, and an empty file will abort the edit.
|
||||
#
|
||||
# The edited file had a syntax error: error converting YAML to JSON: yaml: line 12: could not find expected ':'
|
||||
#
|
||||
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: {}
|
||||
name: cm1
|
||||
namespace: myproject
|
||||
- kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: svc1
|
||||
new-label: foo
|
||||
new-label2: foo2
|
||||
name: svc1
|
||||
namespace: myproject
|
||||
spec:
|
||||
ports:
|
||||
- name: "80"
|
||||
port: 82
|
||||
protocol: TCP
|
||||
targetPort: 81
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
||||
status:
|
||||
loadBalancer: {}
|
||||
kind: List
|
||||
metadata: {}
|
40
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/3.original
vendored
Normal file
40
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/3.original
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Please edit the 'last-applied-configuration' annotations below.
|
||||
# Lines beginning with a '#' will be ignored, and an empty file will abort the edit.
|
||||
#
|
||||
# The edited file had a syntax error: unable to get type info from the object "*unstructured.Unstructured": Object 'apiVersion' is missing in 'unstructured object has no version'
|
||||
#
|
||||
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: {}
|
||||
name: cm1
|
||||
namespace: myproject
|
||||
- kind: Service
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: svc1
|
||||
new-label: foo
|
||||
new-label2: foo2
|
||||
name: svc1
|
||||
namespace: myproject
|
||||
spec:
|
||||
ports:
|
||||
- name: "80"
|
||||
port: 82
|
||||
protocol: TCP
|
||||
targetPort: 81
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
||||
status:
|
||||
loadBalancer: {}
|
||||
kind: List
|
||||
metadata: {}
|
7
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/4.request
vendored
Executable file
7
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/4.request
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"baz\":\"qux\",\"foo\":\"changed-value\",\"new-data\":\"new-value\",\"new-data2\":\"new-value\",\"new-data3\":\"newivalue\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"cm1\",\"namespace\":\"myproject\"}}\n"
|
||||
}
|
||||
}
|
||||
}
|
21
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/4.response
vendored
Executable file
21
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/4.response
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"kind": "ConfigMap",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "cm1",
|
||||
"namespace": "myproject",
|
||||
"selfLink": "/api/v1/namespaces/myproject/configmaps/cm1",
|
||||
"uid": "cc08a131-3d6f-11e7-8ef0-c85b76034b7b",
|
||||
"resourceVersion": "3554",
|
||||
"creationTimestamp": "2017-05-20T15:20:03Z",
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"baz\":\"qux\",\"foo\":\"changed-value\",\"new-data\":\"new-value\",\"new-data2\":\"new-value\",\"new-data3\":\"newivalue\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"cm1\",\"namespace\":\"myproject\"}}\n"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
"baz": "qux",
|
||||
"foo": "changed-value",
|
||||
"new-data": "new-value",
|
||||
"new-data2": "new-value"
|
||||
}
|
||||
}
|
7
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/5.request
vendored
Executable file
7
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/5.request
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"svc1\",\"new-label\":\"foo\",\"new-label2\":\"foo2\"},\"name\":\"svc1\",\"namespace\":\"myproject\"},\"spec\":{\"ports\":[{\"name\":\"80\",\"port\":82,\"protocol\":\"TCP\",\"targetPort\":81}],\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"
|
||||
}
|
||||
}
|
||||
}
|
35
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/5.response
vendored
Executable file
35
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/5.response
vendored
Executable file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "svc1",
|
||||
"namespace": "myproject",
|
||||
"selfLink": "/api/v1/namespaces/myproject/services/svc1",
|
||||
"uid": "d8b96f0b-3d6f-11e7-8ef0-c85b76034b7b",
|
||||
"resourceVersion": "3555",
|
||||
"creationTimestamp": "2017-05-20T15:20:24Z",
|
||||
"labels": {
|
||||
"app": "svc1",
|
||||
"new-label": "foo"
|
||||
},
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"svc1\",\"new-label\":\"foo\",\"new-label2\":\"foo2\"},\"name\":\"svc1\",\"namespace\":\"myproject\"},\"spec\":{\"ports\":[{\"name\":\"80\",\"port\":82,\"protocol\":\"TCP\",\"targetPort\":81}],\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "80",
|
||||
"protocol": "TCP",
|
||||
"port": 81,
|
||||
"targetPort": 81
|
||||
}
|
||||
],
|
||||
"clusterIP": "172.30.32.183",
|
||||
"type": "ClusterIP",
|
||||
"sessionAffinity": "None"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
}
|
43
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/test.yaml
vendored
Executable file
43
pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied-list-fail/test.yaml
vendored
Executable file
@@ -0,0 +1,43 @@
|
||||
description: if the user omits an API version, edit will fail
|
||||
mode: edit-last-applied
|
||||
args:
|
||||
- configmaps/cm1
|
||||
- service/svc1
|
||||
namespace: "myproject"
|
||||
expectedStdout:
|
||||
- configmap "cm1" edited
|
||||
- service "svc1" edited
|
||||
expectedExitCode: 0
|
||||
steps:
|
||||
- type: request
|
||||
expectedMethod: GET
|
||||
expectedPath: /api/v1/namespaces/myproject/configmaps/cm1
|
||||
expectedInput: 0.request
|
||||
resultingStatusCode: 200
|
||||
resultingOutput: 0.response
|
||||
- type: request
|
||||
expectedMethod: GET
|
||||
expectedPath: /api/v1/namespaces/myproject/services/svc1
|
||||
expectedInput: 1.request
|
||||
resultingStatusCode: 200
|
||||
resultingOutput: 1.response
|
||||
- type: edit
|
||||
expectedInput: 2.original
|
||||
resultingOutput: 2.edited
|
||||
- type: edit
|
||||
expectedInput: 3.original
|
||||
resultingOutput: 3.edited
|
||||
- type: request
|
||||
expectedMethod: PATCH
|
||||
expectedPath: /api/v1/namespaces/myproject/configmaps/cm1
|
||||
expectedContentType: application/merge-patch+json
|
||||
expectedInput: 4.request
|
||||
resultingStatusCode: 200
|
||||
resultingOutput: 4.response
|
||||
- type: request
|
||||
expectedMethod: PATCH
|
||||
expectedPath: /api/v1/namespaces/myproject/services/svc1
|
||||
expectedContentType: application/merge-patch+json
|
||||
expectedInput: 5.request
|
||||
resultingStatusCode: 200
|
||||
resultingOutput: 5.response
|
@@ -16,6 +16,7 @@ items:
|
||||
name: cm1
|
||||
namespace: myproject
|
||||
- kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"svc1\",\"new-label\":\"foo\",\"new-label2\":\"foo2\"},\"name\":\"svc1\",\"namespace\":\"myproject\"},\"spec\":{\"ports\":[{\"name\":\"80\",\"port\":82,\"protocol\":\"TCP\",\"targetPort\":81}],\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"
|
||||
}
|
||||
}
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"svc1\",\"new-label\":\"foo\",\"new-label2\":\"foo2\"},\"name\":\"svc1\",\"namespace\":\"myproject\"},\"spec\":{\"ports\":[{\"name\":\"80\",\"port\":82,\"protocol\":\"TCP\",\"targetPort\":81}],\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user