Add path safety fixes (#3061)

* Add path safety fixes

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* minor changes

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* revert test_huge_response test

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2024-11-18 12:19:34 +05:30
committed by GitHub
parent 82c0fbaeda
commit 59267e3a6b
5 changed files with 57 additions and 12 deletions
+9 -7
View File
@@ -304,16 +304,18 @@ func (gp *GenericPool) choosePod(ctx context.Context, newLabels map[string]strin
// Relabel. If the pod already got picked and
// modified, this should fail; in that case just
// retry.
labelPatch, _ := json.Marshal(newLabels)
// Append executor instance id to pod annotations to
// indicate this pod is managed by this executor.
annotations := gp.getDeployAnnotations(gp.env)
annotationPatch, _ := json.Marshal(annotations)
patch := fmt.Sprintf(`{"metadata":{"annotations":%v, "labels":%v}}`, string(annotationPatch), string(labelPatch))
logger.Info("relabel pod", zap.String("pod", patch))
newPod, err := gp.kubernetesClient.CoreV1().Pods(chosenPod.Namespace).Patch(ctx, chosenPod.Name, k8sTypes.StrategicMergePatchType, []byte(patch), metav1.PatchOptions{})
patch := map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": annotations,
"labels": newLabels,
},
}
patchBytes, _ := json.Marshal(patch)
logger.Info("relabel pod", zap.String("pod", string((patchBytes))))
newPod, err := gp.kubernetesClient.CoreV1().Pods(chosenPod.Namespace).Patch(ctx, chosenPod.Name, k8sTypes.StrategicMergePatchType, patchBytes, metav1.PatchOptions{})
if err != nil && errors.Is(err, context.Canceled) {
// ending retry loop when the request canceled
gp.readyPodQueue.Done(key)