api changes of forgiveness phase1

This commit is contained in:
Kevin
2017-01-04 19:45:50 +08:00
parent 68f123dfa0
commit 72a19819a6
5 changed files with 174 additions and 43 deletions

View File

@@ -3378,6 +3378,40 @@ func TestValidatePod(t *testing.T) {
},
}),
},
{ // populate forgiveness tolerations with exists operator in annotations.
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
Annotations: map[string]string{
api.TolerationsAnnotationKey: `
[{
"key": "foo",
"operator": "Exists",
"value": "",
"effect": "NoExecute",
"tolerationSeconds": 60
}]`,
},
},
Spec: validPodSpec(nil),
},
{ // populate forgiveness tolerations with equal operator in annotations.
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
Annotations: map[string]string{
api.TolerationsAnnotationKey: `
[{
"key": "foo",
"operator": "Equal",
"value": "bar",
"effect": "NoExecute",
"tolerationSeconds": 60
}]`,
},
},
Spec: validPodSpec(nil),
},
{ // populate tolerations equal operator in annotations.
ObjectMeta: metav1.ObjectMeta{
Name: "123",
@@ -3409,7 +3443,21 @@ func TestValidatePod(t *testing.T) {
},
Spec: validPodSpec(nil),
},
{ // empty operator is ok for toleration
{ // empty key with Exists operator is OK for toleration, empty toleration key means match all taint keys.
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
Annotations: map[string]string{
api.TolerationsAnnotationKey: `
[{
"operator": "Exists",
"effect": "NoSchedule"
}]`,
},
},
Spec: validPodSpec(nil),
},
{ // empty operator is OK for toleration, defaults to Equal.
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
@@ -3424,7 +3472,7 @@ func TestValidatePod(t *testing.T) {
},
Spec: validPodSpec(nil),
},
{ // empty efffect is ok for toleration
{ // empty effect is OK for toleration, empty toleration effect means match all taint effects.
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
@@ -3439,6 +3487,22 @@ func TestValidatePod(t *testing.T) {
},
Spec: validPodSpec(nil),
},
{ // negative tolerationSeconds is OK for toleration.
ObjectMeta: metav1.ObjectMeta{
Name: "pod-forgiveness-invalid",
Namespace: "ns",
Annotations: map[string]string{
api.TolerationsAnnotationKey: `
[{
"key": "node.alpha.kubernetes.io/notReady",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": -2
}]`,
},
},
Spec: validPodSpec(nil),
},
{ // docker default seccomp profile
ObjectMeta: metav1.ObjectMeta{
Name: "123",
@@ -3898,6 +3962,38 @@ func TestValidatePod(t *testing.T) {
},
Spec: validPodSpec(nil),
},
"operator must be 'Exists' when `key` is empty": {
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
Annotations: map[string]string{
api.TolerationsAnnotationKey: `
[{
"operator": "Equal",
"value": "bar",
"effect": "NoSchedule"
}]`,
},
},
Spec: validPodSpec(nil),
},
"effect must be 'NoExecute' when `TolerationSeconds` is set": {
ObjectMeta: metav1.ObjectMeta{
Name: "pod-forgiveness-invalid",
Namespace: "ns",
Annotations: map[string]string{
api.TolerationsAnnotationKey: `
[{
"key": "node.alpha.kubernetes.io/notReady",
"operator": "Exists",
"effect": "NoSchedule",
"tolerationSeconds": 20
}]`,
},
},
Spec: validPodSpec(nil),
},
"must be a valid pod seccomp profile": {
ObjectMeta: metav1.ObjectMeta{
Name: "123",
@@ -5927,7 +6023,7 @@ func TestValidateNode(t *testing.T) {
ExternalID: "external",
},
},
"invalide-taint-effect": {
"invalid-taint-effect": {
ObjectMeta: metav1.ObjectMeta{
Name: "dedicated-node3",
// Add a taint with an empty effect to a node
@@ -5936,7 +6032,7 @@ func TestValidateNode(t *testing.T) {
[{
"key": "dedicated",
"value": "special-user-3",
"effect": "NoExecute"
"effect": "NoScheduleNoAdmit"
}]`,
},
},