MCPcopy
hub / github.com/apecloud/kubeblocks / MockKBAgentClient4HScale

Function MockKBAgentClient4HScale

pkg/testutil/apps/kb_agent_util.go:56–86  ·  view source on GitHub ↗
(testCtx *testutil.TestContext, clusterKey types.NamespacedName, compName, podAnnotationKey4Test string, replicas int)

Source from the content-addressed store, hash-verified

54}
55
56func 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
88func MockKBAgentContainer() corev1.Container {
89 return corev1.Container{

Callers

nothing calls this directly

Calls 4

MockKBAgentClientFunction · 0.85
ActionMethod · 0.65
ListMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…