-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Implement alpha version of PreferAvoidPods #20699
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,3 +295,99 @@ func TestGetAffinityFromPod(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestGetAvoidPodsFromNode(t *testing.T) { | ||
controllerFlag := true | ||
testCases := []struct { | ||
node *Node | ||
expectValue AvoidPods | ||
expectErr bool | ||
}{ | ||
{ | ||
node: &Node{}, | ||
expectValue: AvoidPods{}, | ||
expectErr: false, | ||
}, | ||
{ | ||
node: &Node{ | ||
ObjectMeta: ObjectMeta{ | ||
Annotations: map[string]string{ | ||
PreferAvoidPodsAnnotationKey: ` | ||
{ | ||
"preferAvoidPods": [ | ||
{ | ||
"podSignature": { | ||
"podController": { | ||
"apiVersion": "v1", | ||
"kind": "ReplicationController", | ||
"name": "foo", | ||
"uid": "abcdef123456", | ||
"controller": true | ||
} | ||
}, | ||
"reason": "some reason", | ||
"message": "some message" | ||
} | ||
] | ||
}`, | ||
}, | ||
}, | ||
}, | ||
expectValue: AvoidPods{ | ||
PreferAvoidPods: []PreferAvoidPodsEntry{ | ||
{ | ||
PodSignature: PodSignature{ | ||
PodController: &OwnerReference{ | ||
APIVersion: "v1", | ||
Kind: "ReplicationController", | ||
Name: "foo", | ||
UID: "abcdef123456", | ||
Controller: &controllerFlag, | ||
}, | ||
}, | ||
Reason: "some reason", | ||
Message: "some message", | ||
}, | ||
}, | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
node: &Node{ | ||
// Missing end symbol of "podController" and "podSignature" | ||
ObjectMeta: ObjectMeta{ | ||
Annotations: map[string]string{ | ||
PreferAvoidPodsAnnotationKey: ` | ||
{ | ||
"preferAvoidPods": [ | ||
{ | ||
"podSignature": { | ||
"podController": { | ||
"kind": "ReplicationController", | ||
"apiVersion": "v1" | ||
"reason": "some reason", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation problem here |
||
"message": "some message" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation problem here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case test a incorrect Json format with no end symbol of struct "podController" and "podSignature". The indentation of "reason" and "message" is correct. |
||
} | ||
] | ||
}`, | ||
}, | ||
}, | ||
}, | ||
expectValue: AvoidPods{}, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
v, err := GetAvoidPodsFromNodeAnnotations(tc.node.Annotations) | ||
if err == nil && tc.expectErr { | ||
t.Errorf("[%v]expected error but got none.", i) | ||
} | ||
if err != nil && !tc.expectErr { | ||
t.Errorf("[%v]did not expect error but got: %v", i, err) | ||
} | ||
if !reflect.DeepEqual(tc.expectValue, v) { | ||
t.Errorf("[%v]expect value %v but got %v with %v", i, tc.expectValue, v, v.PreferAvoidPods[0].PodSignature.PodController.Controller) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment why you expect this to fail