(testCtx *testutil.TestContext, clusterKey types.NamespacedName, compName, podAnnotationKey4Test string, replicas int)
| 54 | } |
| 55 | |
| 56 | func MockKBAgentClient4HScale(testCtx *testutil.TestContext, clusterKey types.NamespacedName, compName, podAnnotationKey4Test string, replicas int) { |
| 57 | MockKBAgentClient(func(recorder *kbacli.MockClientMockRecorder) { |
| 58 | recorder.Action(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, req kbagentproto.ActionRequest) (kbagentproto.ActionResponse, error) { |
| 59 | rsp := kbagentproto.ActionResponse{} |
| 60 | if req.Action != "memberLeave" { |
| 61 | return rsp, nil |
| 62 | } |
| 63 | var podList corev1.PodList |
| 64 | labels := client.MatchingLabels{ |
| 65 | constant.AppInstanceLabelKey: clusterKey.Name, |
| 66 | constant.KBAppComponentLabelKey: compName, |
| 67 | } |
| 68 | if err := testCtx.Cli.List(ctx, &podList, labels, client.InNamespace(clusterKey.Namespace)); err != nil { |
| 69 | return rsp, err |
| 70 | } |
| 71 | for _, pod := range podList.Items { |
| 72 | if pod.Annotations == nil { |
| 73 | panic(fmt.Sprintf("pod annotations is nil: %s", pod.Name)) |
| 74 | } |
| 75 | if pod.Annotations[podAnnotationKey4Test] == fmt.Sprintf("%d", replicas) { |
| 76 | continue |
| 77 | } |
| 78 | pod.Annotations[podAnnotationKey4Test] = fmt.Sprintf("%d", replicas) |
| 79 | if err := testCtx.Cli.Update(ctx, &pod); err != nil { |
| 80 | return rsp, err |
| 81 | } |
| 82 | } |
| 83 | return rsp, nil |
| 84 | }).AnyTimes() |
| 85 | }) |
| 86 | } |
| 87 | |
| 88 | func MockKBAgentContainer() corev1.Container { |
| 89 | return corev1.Container{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…