Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain committed Sep 11, 2023
1 parent 1f89d5e commit 9d357c5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/xds/translator/jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const (
EmptyPath = ""
)

var unescaper = strings.NewReplacer(`\u00a0`, ` `)

// processJSONPatches applies each JSONPatch to the Xds Resources for a specific type.
func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*ir.EnvoyPatchPolicy) error {
var errs error
Expand Down Expand Up @@ -71,7 +69,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.ListenerType):
temp := &listenerv3.Listener{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
msg := unmarshalErrorMessage(err, p.Operation.Value)
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand All @@ -84,7 +82,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.RouteType):
temp := &routev3.RouteConfiguration{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
msg := unmarshalErrorMessage(err, p.Operation.Value)
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand All @@ -97,7 +95,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.ClusterType):
temp := &clusterv3.Cluster{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
msg := unmarshalErrorMessage(err, p.Operation.Value)
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand All @@ -110,7 +108,7 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
case string(resourcev3.EndpointType):
temp := &endpointv3.ClusterLoadAssignment{}
if err = protojson.Unmarshal(jsonBytes, temp); err != nil {
msg := fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", p.Operation.Value, unescaper.Replace(err.Error()))
msg := unmarshalErrorMessage(err, p.Operation.Value)
status.SetEnvoyPatchPolicyInvalid(e.Status, msg)
continue
}
Expand Down Expand Up @@ -294,3 +292,9 @@ func processJSONPatches(tCtx *types.ResourceVersionTable, envoyPatchPolicies []*
}
return errs
}

var unescaper = strings.NewReplacer(`\u00a0`, ` `)

func unmarshalErrorMessage(err error, xdsResource any) string {
return fmt.Sprintf("unable to unmarshal xds resource %+v, err:%s", xdsResource, unescaper.Replace(err.Error()))
}

0 comments on commit 9d357c5

Please sign in to comment.