diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b9782121..99f9703bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - (Bugfix) Fix AnyPB Parsing in Meta Service - (Feature) Add Arch Tolerations - (Bugfix) Enable Platform Operator on EE Chart +- (Feature) Improve GRPC JSON Handling ## [1.3.0](https://github.com/arangodb/kube-arangodb/tree/1.3.0) (2025-08-01) - (Feature) (Platform) Storage Debug diff --git a/integrations/inventory/v1/definition/inventory.go b/integrations/inventory/v1/definition/inventory.go index f19229f4e..684ed0946 100644 --- a/integrations/inventory/v1/definition/inventory.go +++ b/integrations/inventory/v1/definition/inventory.go @@ -37,7 +37,7 @@ func (s *Inventory) JSON() ([]byte, error) { return []byte("{}"), nil } - return ugrpc.Marshal(s) + return ugrpc.Marshal(s, ugrpc.WithUseProtoNames(true)) } func NewArangoDBConfiguration(spec api.DeploymentSpec, status api.DeploymentStatus) *ArangoDBConfiguration { diff --git a/integrations/inventory/v1/definition/inventory_test.go b/integrations/inventory/v1/definition/inventory_test.go index ce4f18932..60c4aec88 100644 --- a/integrations/inventory/v1/definition/inventory_test.go +++ b/integrations/inventory/v1/definition/inventory_test.go @@ -45,6 +45,7 @@ func Test_State_Marshal(t *testing.T) { data, err := ugrpc.Marshal(&s, func(in *protojson.MarshalOptions) { in.EmitDefaultValues = true + in.UseProtoNames = false }) require.NoError(t, err) diff --git a/pkg/deployment/resources/config_map_gateway.go b/pkg/deployment/resources/config_map_gateway.go index db35c7836..b33266adb 100644 --- a/pkg/deployment/resources/config_map_gateway.go +++ b/pkg/deployment/resources/config_map_gateway.go @@ -131,9 +131,8 @@ func (r *Resources) ensureGatewayConfig(ctx context.Context, cachedStatus inspec }, Marshaller: ugrpc.Marshal[*pbInventoryV1.Inventory], Options: []util.Mod[protojson.MarshalOptions]{ - func(in *protojson.MarshalOptions) { - in.EmitDefaultValues = true - }, + ugrpc.WithUseProtoNames(true), + ugrpc.WithEmitDefaultValues(true), }, }, } diff --git a/pkg/deployment/resources/gateway/dynamic.go b/pkg/deployment/resources/gateway/dynamic.go index 5b5ae2aef..6c17ca272 100644 --- a/pkg/deployment/resources/gateway/dynamic.go +++ b/pkg/deployment/resources/gateway/dynamic.go @@ -78,7 +78,7 @@ func NodeDynamicConfig(cluster, id string, cds, lds *DynamicConfig) ([]byte, str b.DynamicResources.LdsConfig = v.AsConfigSource() } - data, err := ugrpc.MarshalYAML(&b) + data, err := ugrpc.MarshalYAML(&b, ugrpc.WithUseProtoNames(true)) if err != nil { return nil, "", nil, err } diff --git a/pkg/deployment/resources/gateway/gateway_config.go b/pkg/deployment/resources/gateway/gateway_config.go index cdf955656..cc7d22936 100644 --- a/pkg/deployment/resources/gateway/gateway_config.go +++ b/pkg/deployment/resources/gateway/gateway_config.go @@ -77,7 +77,7 @@ func (c Config) RenderYAML() ([]byte, string, *pbEnvoyBootstrapV3.Bootstrap, err return nil, "", nil, err } - data, err := ugrpc.MarshalYAML(cfg) + data, err := ugrpc.MarshalYAML(cfg, ugrpc.WithUseProtoNames(true)) if err != nil { return nil, "", nil, err } @@ -90,7 +90,7 @@ func (c Config) RenderCDSYAML() ([]byte, string, *discoveryApi.DiscoveryResponse return nil, "", nil, err } - data, err := ugrpc.MarshalYAML(cfg) + data, err := ugrpc.MarshalYAML(cfg, ugrpc.WithUseProtoNames(true)) if err != nil { return nil, "", nil, err } @@ -103,7 +103,7 @@ func (c Config) RenderLDSYAML() ([]byte, string, *discoveryApi.DiscoveryResponse return nil, "", nil, err } - data, err := ugrpc.MarshalYAML(cfg) + data, err := ugrpc.MarshalYAML(cfg, ugrpc.WithUseProtoNames(true)) if err != nil { return nil, "", nil, err } diff --git a/pkg/util/grpc/http.go b/pkg/util/grpc/http.go index afa2373e4..98f6b5c23 100644 --- a/pkg/util/grpc/http.go +++ b/pkg/util/grpc/http.go @@ -105,7 +105,7 @@ func Get[T proto.Message](ctx context.Context, client operatorHTTP.HTTPClient, u } func Post[IN, T proto.Message](ctx context.Context, client operatorHTTP.HTTPClient, in IN, url string, mods ...util.Mod[goHttp.Request]) HTTPResponse[T] { - data, err := Marshal(in) + data, err := Marshal(in, WithUseProtoNames(true)) if err != nil { return httpErrorResponse[T]{err: err} } diff --git a/pkg/util/grpc/marshal.go b/pkg/util/grpc/marshal.go index b8abd3e68..0be0a59f1 100644 --- a/pkg/util/grpc/marshal.go +++ b/pkg/util/grpc/marshal.go @@ -28,10 +28,20 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util" ) -func Marshal[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) { - options := protojson.MarshalOptions{ - UseProtoNames: true, +func WithUseProtoNames(value bool) util.Mod[protojson.MarshalOptions] { + return func(in *protojson.MarshalOptions) { + in.UseProtoNames = value + } +} + +func WithEmitDefaultValues(value bool) util.Mod[protojson.MarshalOptions] { + return func(in *protojson.MarshalOptions) { + in.EmitDefaultValues = value } +} + +func Marshal[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) { + options := protojson.MarshalOptions{} util.ApplyMods(&options, opts...)