{
  "repo": "tidbcloud/autoscaler",
  "binary": "balancer",
  "binary_path": "balancer/main.go",
  "dependencies": {
    "BalancerLifecycle.LoadFlags": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.BuildKubeConfig": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "--kubeconfig is not empty"
          ],
          "operations": [
            {
              "operation": "READ",
              "trigger": "Load the kubeconfig referenced by the startup flags",
              "conditions": [
                "Only when --kubeconfig is provided"
              ],
              "implementation": "clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)"
            }
          ]
        }
      },
      "services": []
    },
    "BalancerLifecycle.InitKubernetesClients": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.InitInformerFactories": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.InitRESTMapper": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.StartRESTMapperResetLoop": {
      "infrastructure": {
        "scheduler": {
          "conditions": [
            "Process startup reached the mapper initialization path"
          ],
          "operations": [
            {
              "operation": "START_BACKGROUND_LOOP",
              "trigger": "Keep the deferred REST mapper fresh while the controller process is running",
              "conditions": [
                "Always after InitRESTMapper"
              ],
              "implementation": "go wait.Until(func() { restMapper.Reset() }, mapperResetPeriod, stopCh)"
            }
          ]
        }
      },
      "services": []
    },
    "BalancerLifecycle.BuildScaleClient": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.BuildCore": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.BuildController": {
      "infrastructure": {},
      "services": []
    },
    "BalancerLifecycle.StartInformerFactories": {
      "infrastructure": {
        "kubernetes_api": {
          "conditions": [
            "Always after the informer factories are created"
          ],
          "operations": [
            {
              "operation": "LIST_WATCH",
              "trigger": "Populate the Pod informer cache used by the balancing core",
              "conditions": [
                "Always after kubeInformerFactory.Start(stopCh)"
              ],
              "implementation": "kubeInformerFactory.Start(stopCh) -> Core().V1().Pods()"
            },
            {
              "operation": "LIST_WATCH",
              "trigger": "Populate the Balancer CRD informer cache used by the controller queue",
              "conditions": [
                "Always after balancerInformerFactory.Start(stopCh)"
              ],
              "implementation": "balancerInformerFactory.Start(stopCh) -> Balancer().V1alpha1().Balancers()"
            }
          ]
        }
      },
      "services": []
    },
    "BalancerLifecycle.RunController": {
      "infrastructure": {
        "scheduler": {
          "conditions": [
            "Controller construction completed"
          ],
          "operations": [
            {
              "operation": "START_WORKER_POOL",
              "trigger": "Run queue workers that keep reconciling Balancer items until stopCh closes",
              "conditions": [
                "Always after cache sync succeeds"
              ],
              "implementation": "controller.Run(concurrency, stopCh) -> go wait.Until(func() { for c.processNextWorkItem() {} }, time.Second, stopCh)"
            }
          ]
        }
      },
      "services": []
    },
    "BalancerController.ReconcileBalancer": {
      "infrastructure": {
        "kubernetes_api": {
          "conditions": [
            "A Balancer add, update, or resync event enqueued the object"
          ],
          "operations": [
            {
              "operation": "GET",
              "trigger": "Load the Balancer CR being reconciled",
              "conditions": [
                "Always for each queue item"
              ],
              "implementation": "c.balancerLister.Balancers(namespace).Get(name)"
            },
            {
              "operation": "GET",
              "trigger": "Read the scale subresource for each target referenced by the Balancer spec",
              "conditions": [
                "For each target in balancer.Spec.Targets"
              ],
              "implementation": "c.scaleClient.GetScale(balancer.Namespace, target.ScaleTargetRef)"
            },
            {
              "operation": "LIST",
              "trigger": "List pods for each target scale selector to compute replica summaries",
              "conditions": [
                "Only after the target scale selector parses successfully"
              ],
              "implementation": "c.podLister.Pods(balancer.Namespace).List(selector)"
            },
            {
              "operation": "UPDATE",
              "trigger": "Change target replica counts according to the balancing policy placement",
              "conditions": [
                "Only when the computed placement differs from the current scale"
              ],
              "implementation": "c.scaleClient.UpdateScale(scaleInfo.scale, scaleInfo.groupResource)"
            },
            {
              "operation": "UPDATE_STATUS",
              "trigger": "Persist Balancer status fields such as replicas, selector, and conditions",
              "conditions": [
                "Only when the newly computed status differs from the old status"
              ],
              "implementation": "c.balancerClientSet.BalancerV1alpha1().Balancers(new.Namespace).UpdateStatus(context.TODO(), new, metav1.UpdateOptions{})"
            },
            {
              "operation": "POST",
              "trigger": "Emit warning events for balancing failures or status update failures",
              "conditions": [
                "Only when ProcessBalancer fails or updateStatusIfNeeded returns an error"
              ],
              "implementation": "c.recorder.Event(balancer, corev1.EventTypeWarning, ...)"
            }
          ]
        }
      },
      "services": []
    }
  }
}
