Skip to content

Commit bacd23b

Browse files
authored
fix: add JSON pointer escaping for pod counter annotation path (#141)
1 parent aa2d71d commit bacd23b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

internal/utils/jsonpatch.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package utils
2+
3+
import (
4+
"strings"
5+
)
6+
7+
// EscapeJSONPointer escapes a string according to the JSON Pointer spec (RFC 6901).
8+
// It escapes '~' as '~0' and '/' as '~1'.
9+
func EscapeJSONPointer(s string) string {
10+
// Order is important: we must escape ~ first so we don't double-escape
11+
s = strings.Replace(s, "~", "~0", -1)
12+
s = strings.Replace(s, "/", "~1", -1)
13+
return s
14+
}

internal/webhook/v1/pod_webhook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
tfv1 "github.com/NexusGPU/tensor-fusion/api/v1"
3737
"github.com/NexusGPU/tensor-fusion/internal/constants"
38+
"github.com/NexusGPU/tensor-fusion/internal/utils"
3839
"github.com/NexusGPU/tensor-fusion/internal/worker"
3940
"github.com/lithammer/shortuuid/v4"
4041
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -131,7 +132,7 @@ func (m *TensorFusionPodMutator) Handle(ctx context.Context, req admission.Reque
131132
// Patch annotation for pod counter
132133
patch := jsonpatch.JsonPatchOperation{
133134
Operation: "add",
134-
Path: "/metadata/annotations/" + constants.TensorFusionPodCounterKeyAnnotation,
135+
Path: "/metadata/annotations/" + utils.EscapeJSONPointer(constants.TensorFusionPodCounterKeyAnnotation),
135136
Value: podCounterAnnotationKey,
136137
}
137138
patches = append(patches, patch)

0 commit comments

Comments
 (0)