mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-08-19 04:16:35 +00:00
✨ Send targetted pods to POST /pods/set-targetted HTTP endpoint of Hub
This commit is contained in:
+2
-2
@@ -174,8 +174,8 @@ func startWorkerSyncer(ctx context.Context, cancel context.CancelFunc, provider
|
||||
log.Debug().Msg("workerSyncer pod changes channel closed, ending listener loop")
|
||||
return
|
||||
}
|
||||
if err := connector.ReportTargettedPods(workerSyncer.CurrentlyTargettedPods); err != nil {
|
||||
log.Error().Err(err).Msg("failed update targetted pods.")
|
||||
if err := connector.PostTargettedPodsToHub(workerSyncer.CurrentlyTargettedPods); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to POST targetted pods to Hub.")
|
||||
}
|
||||
case pod, ok := <-workerSyncer.WorkerPodsChanges:
|
||||
if !ok {
|
||||
|
||||
+10
-10
@@ -65,28 +65,28 @@ func (connector *Connector) isReachable(path string) (bool, error) {
|
||||
func (connector *Connector) PostWorkerPodToHub(pod *v1.Pod) error {
|
||||
setWorkerUrl := fmt.Sprintf("%s/pods/set-worker", connector.url)
|
||||
|
||||
if jsonValue, err := json.Marshal(pod); err != nil {
|
||||
if podMarshalled, err := json.Marshal(pod); err != nil {
|
||||
return fmt.Errorf("Failed to marshal the Worker pod: %w", err)
|
||||
} else {
|
||||
if _, err := utils.Post(setWorkerUrl, "application/json", bytes.NewBuffer(jsonValue), connector.client); err != nil {
|
||||
if _, err := utils.Post(setWorkerUrl, "application/json", bytes.NewBuffer(podMarshalled), connector.client); err != nil {
|
||||
return fmt.Errorf("Failed sending the Worker pod to Hub: %w", err)
|
||||
} else {
|
||||
log.Debug().Interface("worker-pod", pod).Msg("Reported to Hub about Worker status:")
|
||||
log.Debug().Interface("worker-pod", pod).Msg("Reported worker pod to Hub:")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (connector *Connector) ReportTargettedPods(pods []core.Pod) error {
|
||||
targettedPodsUrl := fmt.Sprintf("%s/status/targettedPods", connector.url)
|
||||
func (connector *Connector) PostTargettedPodsToHub(pods []core.Pod) error {
|
||||
setTargettedUrl := fmt.Sprintf("%s/pods/set-targetted", connector.url)
|
||||
|
||||
if jsonValue, err := json.Marshal(pods); err != nil {
|
||||
return fmt.Errorf("Failed Marshal the targetted pods %w", err)
|
||||
if podsMarshalled, err := json.Marshal(pods); err != nil {
|
||||
return fmt.Errorf("Failed to marshal the targetted pods: %w", err)
|
||||
} else {
|
||||
if _, err := utils.Post(targettedPodsUrl, "application/json", bytes.NewBuffer(jsonValue), connector.client); err != nil {
|
||||
return fmt.Errorf("Failed sending to Hub the targetted pods %w", err)
|
||||
if _, err := utils.Post(setTargettedUrl, "application/json", bytes.NewBuffer(podsMarshalled), connector.client); err != nil {
|
||||
return fmt.Errorf("Failed sending the targetted pods to Hub: %w", err)
|
||||
} else {
|
||||
log.Debug().Int("pod-count", len(pods)).Msg("Reported to Hub about targetted pod count:")
|
||||
log.Debug().Int("pod-count", len(pods)).Msg("Reported targetted pods to Hub:")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user