0yukali0 commented on code in PR #474:
URL: https://github.com/apache/yunikorn-k8shim/pull/474#discussion_r1028121213
##########
pkg/common/utils/utils_test.go:
##########
@@ -736,6 +739,443 @@ func TestNeedRecovery(t *testing.T) {
}
}
+func TestGetTaskGroupFromPodSpec(t *testing.T) {
+ pod := &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ Annotations: map[string]string{
+ constants.AnnotationTaskGroupName:
"test-task-group",
+ },
+ },
+ }
+
+ assert.Equal(t, GetTaskGroupFromPodSpec(pod), "test-task-group")
+
+ pod = &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ },
+ }
+
+ assert.Equal(t, GetTaskGroupFromPodSpec(pod), "")
+}
+
+func TestGetPlaceholderFlagFromPodSpec(t *testing.T) {
+ testCases := []struct {
+ description string
+ pod *v1.Pod
+ expectedPlaceholderFlag bool
+ }{
+
+ {"Setting by annotation", &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ Annotations: map[string]string{
+ constants.AnnotationPlaceholderFlag:
"true",
+ },
+ },
+ }, true},
+ {"Setting by label", &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ Labels: map[string]string{
+ constants.LabelPlaceholderFlag: "true",
+ },
+ },
+ }, true},
+ {"Setting both annotation and label, annotation has higher
priority", &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ Annotations: map[string]string{
+ constants.AnnotationPlaceholderFlag:
"true",
+ constants.LabelPlaceholderFlag:
"false",
+ },
+ },
+ }, true},
+ {"No setting both annotation and label", &v1.Pod{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "pod-01",
+ UID: "UID-01",
+ },
+ }, false},
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.description, func(t *testing.T) {
+ placeHolderFlag := GetPlaceholderFlagFromPodSpec(tc.pod)
+ assert.Equal(t, placeHolderFlag,
tc.expectedPlaceholderFlag)
+ })
+ }
+}
+
+// nolint: funlen
+func TestGetTaskGroupFromAnnotation(t *testing.T) {
+ // correct json
+ testGroup := `
+ [
+ {
+ "name": "test-group-1",
+ "minMember": 10,
+ "minResource": {
+ "cpu": 1,
+ "memory": "2Gi"
+ },
+ "nodeSelector": {
+ "test": "testnode",
+ "locate": "west"
+ },
+ "tolerations": [
+ {
+ "key": "key",
+ "operator": "Equal",
+ "value": "value",
+ "effect": "NoSchedule"
+ }
+ ]
+ },
+ {
+ "name": "test-group-2",
+ "minMember": 5,
+ "minResource": {
+ "cpu": 2,
+ "memory": "4Gi"
+ }
+ }
+ ]`
+ testGroup2 := `
+ [
+ {
+ "name": "test-group-3",
+ "minMember": 3,
+ "minResource": {
+ "cpu": 2,
+ "memory": "1Gi"
+ }
+ }
+ ]`
+ // Error json
+ testGroupErr := `
+ [
+ {
+ "name": "test-group-err-1",
+ "minMember": "ERR",
+ "minResource": {
+ "cpu": "ERR",
+ "memory": "ERR"
+ },
+ }
+ ]`
+ // without name
+ testGroupErr2 := `
+ [
+ {
+ "minMember": 3,
+ "minResource": {
+ "cpu": 2,
+ "memory": "1Gi"
+ }
+ }
+ ]`
+ // without minMember
+ testGroupErr3 := `
+ [
+ {
+ "name": "test-group-err-2",
+ "minResource": {
+ "cpu": 2,
+ "memory": "1Gi"
+ }
+ }
+ ]`
+ // without minResource
+ testGroupErr4 := `
+ [
+ {
+ "name": "test-group-err-4",
+ "minMember": 3
+ }
+ ]`
+ // negative minMember without minResource
+ testGroupErr5 := `
+ [
+ {
+ "name": "test-group-err-5",
+ "minMember": -100
+ }
+ ]`
+ // negative minMember with minResource
+ testGroupErr6 := `
+ [
+ {
+ "name": "test-group-err-5",
+ "minMember": -100
Review Comment:
You can view the coverage of codes in web.
Run the "go tool cover -html coverage.txt" after running the "make test"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]