Skip to content

Commit

Permalink
get rid of deprecated proto so we dont need GOLANG_PROTOBUF_REGISTRAT…
Browse files Browse the repository at this point in the history
…ION_CONFLICT (#10533)
  • Loading branch information
yuval-k authored Jan 28, 2025
1 parent 64a8b22 commit 60a2d91
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 104 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pr-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
shell: bash
env:
TEST_PKG: "./projects/gateway2/..."
# TODO: remove this once we delete gloo
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: "ignore"
run: make go-test-with-coverage
- name: Validate Test Coverage
shell: bash
Expand Down
1 change: 0 additions & 1 deletion docs/content/static/content/osa_provided.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Name|Version|License
[ghodss/yaml](https://github.com/ghodss/yaml)|v1.0.1-0.20190212211648-25d852aebe32|MIT License
[go-logr/logr](https://github.com/go-logr/logr)|v1.4.2|Apache License 2.0
[go-logr/zapr](https://github.com/go-logr/zapr)|v1.3.0|Apache License 2.0
[golang/protobuf](https://github.com/golang/protobuf)|v1.5.4|BSD 3-clause "New" or "Revised" License
[google/go-cmp](https://github.com/google/go-cmp)|v0.6.0|BSD 3-clause "New" or "Revised" License
[go-github/v32](https://github.com/google/go-github)|v32.0.0|BSD 3-clause "New" or "Revised" License
[grpc-ecosystem/go-grpc-middleware](https://github.com/grpc-ecosystem/go-grpc-middleware)|v1.4.0|Apache License 2.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-github/v32 v32.0.0
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
Expand Down
2 changes: 0 additions & 2 deletions install/helm/gloo/templates/1-gloo-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ spec:
- name: HEADER_SECRET_REF_NS_MATCHES_US
value: "true"
{{- end}}
- name: GOLANG_PROTOBUF_REGISTRATION_CONFLICT
value: ignore
{{- if not .Values.global.glooMtls.enabled }}
readinessProbe:
tcpSocket:
Expand Down
3 changes: 0 additions & 3 deletions install/helm/kgateway/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# TODO: Remove this once the cleanup is done.
- name: GOLANG_PROTOBUF_REGISTRATION_CONFLICT
value: ignore
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/envoyutils/admincli/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package admincli
import (
adminv3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
anypb "github.com/golang/protobuf/ptypes/any"
anypb "google.golang.org/protobuf/types/known/anypb"
)

// GetStaticClustersByName returns a map of static clusters, indexed by their name
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/envoyutils/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
envoy_extensions_filters_network_http_connection_manager_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
anypb "github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
40 changes: 17 additions & 23 deletions pkg/utils/protoutils/utils.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package protoutils

import (
"bytes"
"io"

"github.com/ghodss/yaml"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/rotisserie/eris"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
structpb "google.golang.org/protobuf/types/known/structpb"
)

var (
jsonpbMarshaler = &jsonpb.Marshaler{OrigName: false}
jsonpbMarshalerEmitZeroValues = &jsonpb.Marshaler{OrigName: false, EmitDefaults: true}
jsonpbMarshalerIndented = &jsonpb.Marshaler{OrigName: false, Indent: " "}
jsonpbUnmarshalerAllowUnknown = &jsonpb.Unmarshaler{AllowUnknownFields: true}
jsonpbMarshaler = &protojson.MarshalOptions{UseProtoNames: false}
jsonpbMarshalerEmitZeroValues = &protojson.MarshalOptions{UseProtoNames: false, EmitUnpopulated: true}
jsonpbMarshalerIndented = &protojson.MarshalOptions{UseProtoNames: false, Indent: " "}
jsonpbUnmarshalerAllowUnknown = &protojson.UnmarshalOptions{DiscardUnknown: true}

NilStructError = eris.New("cannot unmarshal nil struct")
)
Expand All @@ -28,7 +27,7 @@ func MarshalStruct(m proto.Message) (*structpb.Struct, error) {
return nil, err
}
var pb structpb.Struct
err = jsonpb.UnmarshalString(string(data), &pb)
err = protojson.Unmarshal(data, &pb)
return &pb, err
}

Expand All @@ -38,38 +37,33 @@ func MarshalStructEmitZeroValues(m proto.Message) (*structpb.Struct, error) {
return nil, err
}
var pb structpb.Struct
err = jsonpb.UnmarshalString(string(data), &pb)
err = protojson.Unmarshal(data, &pb)
return &pb, err
}

func MarshalBytes(pb proto.Message) ([]byte, error) {
buf := &bytes.Buffer{}
err := jsonpbMarshaler.Marshal(buf, pb)
return buf.Bytes(), err
return jsonpbMarshaler.Marshal(pb)
}

func MarshalBytesIndented(pb proto.Message) ([]byte, error) {
buf := &bytes.Buffer{}
err := jsonpbMarshalerIndented.Marshal(buf, pb)
return buf.Bytes(), err
return jsonpbMarshalerIndented.Marshal(pb)
}

func MarshalBytesEmitZeroValues(pb proto.Message) ([]byte, error) {
buf := &bytes.Buffer{}
err := jsonpbMarshalerEmitZeroValues.Marshal(buf, pb)
return buf.Bytes(), err
return jsonpbMarshalerEmitZeroValues.Marshal(pb)
}

func UnmarshalBytes(data []byte, into proto.Message) error {
return jsonpb.Unmarshal(bytes.NewBuffer(data), into)
return protojson.Unmarshal(data, into)
}

func UnmarshalBytesAllowUnknown(data []byte, into proto.Message) error {
return UnmarshalAllowUnknown(bytes.NewBuffer(data), into)
return jsonpbUnmarshalerAllowUnknown.Unmarshal(data, into)
}

func UnmarshalAllowUnknown(r io.Reader, into proto.Message) error {
return jsonpbUnmarshalerAllowUnknown.Unmarshal(r, into)
data, _ := io.ReadAll(r)
return UnmarshalBytesAllowUnknown(data, into)
}

func UnmarshalYaml(data []byte, into proto.Message) error {
Expand All @@ -78,5 +72,5 @@ func UnmarshalYaml(data []byte, into proto.Message) error {
return err
}

return jsonpb.Unmarshal(bytes.NewBuffer(jsn), into)
return protojson.Unmarshal(jsn, into)
}
2 changes: 1 addition & 1 deletion pkg/utils/regexutils/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"regexp"

envoy_type_matcher_v3 "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3"
wrappers "github.com/golang/protobuf/ptypes/wrappers"
wrappers "google.golang.org/protobuf/types/known/wrapperspb"
)

// TODO: [gloo cleanup] keeping this around as it may be needed, but the previous function call chain relied on
Expand Down
2 changes: 1 addition & 1 deletion projects/envoyinit/pkg/downward/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"

envoy_config_bootstrap "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/protobuf/types/known/structpb"

// register all top level types used in the bootstrap config
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
Expand Down
2 changes: 1 addition & 1 deletion projects/envoyinit/pkg/downward/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
envoy_config_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_config_endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
structpb "github.com/golang/protobuf/ptypes/struct"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"google.golang.org/protobuf/types/known/structpb"

. "github.com/kgateway-dev/kgateway/projects/envoyinit/pkg/downward"
)
Expand Down
6 changes: 3 additions & 3 deletions projects/gateway2/endpoints/prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_config_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
"github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/protobuf/types/known/wrapperspb"
)

func PrioritizeEndpoints(logger *zap.Logger, priorityInfo *PriorityInfo, ep ir.EndpointsForUpstream, ucc ir.UniqlyConnectedClient) *envoy_config_endpoint_v3.ClusterLoadAssignment {
Expand Down Expand Up @@ -155,7 +155,7 @@ func getEndpoints(eps []ir.EndpointWithMd, lbinfo LoadBalancingInfo) []*envoy_co
}
// reset weight
if weight > 0 {
epsOut[0].LoadBalancingWeight = &wrappers.UInt32Value{
epsOut[0].LoadBalancingWeight = &wrapperspb.UInt32Value{
Value: weight,
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func applyFailoverPriorityPerLocality(
}
// reset weight
if weight > 0 {
out[i].LoadBalancingWeight = &wrappers.UInt32Value{
out[i].LoadBalancingWeight = &wrapperspb.UInt32Value{
Value: weight,
}
}
Expand Down
2 changes: 1 addition & 1 deletion projects/gateway2/extensions2/plugins/istio/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strconv"
"time"

structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/structpb"
"istio.io/istio/pkg/kube/krt"
"k8s.io/apimachinery/pkg/runtime/schema"

Expand Down
4 changes: 2 additions & 2 deletions projects/gateway2/extensions2/pluginutils/pluginutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_config_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
"github.com/golang/protobuf/proto"
anypb "github.com/golang/protobuf/ptypes/any"
"github.com/kgateway-dev/kgateway/projects/gateway2/utils"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

func EnvoySingleEndpointLoadAssignment(out *envoy_config_cluster_v3.Cluster, address string, port uint32) {
Expand Down
2 changes: 1 addition & 1 deletion projects/gateway2/plugins/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

envoy_config_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
envoyhttp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
"github.com/golang/protobuf/proto"
"github.com/kgateway-dev/kgateway/projects/gateway2/filters"
"github.com/kgateway-dev/kgateway/projects/gateway2/utils"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

"github.com/kgateway-dev/kgateway/pkg/schemes"

"github.com/golang/protobuf/proto"
"github.com/kgateway-dev/kgateway/pkg/utils/protoutils"
"github.com/kgateway-dev/kgateway/projects/gateway2/api/v1alpha1"
"github.com/kgateway-dev/kgateway/projects/gateway2/translator/irtranslator"
"github.com/rotisserie/eris"
"google.golang.org/protobuf/proto"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
Expand Down
65 changes: 6 additions & 59 deletions projects/gateway2/utils/any.go
Original file line number Diff line number Diff line change
@@ -1,70 +1,17 @@
package utils

import (
"errors"
"fmt"

"github.com/golang/protobuf/proto"
gogoproto "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
pany "github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

// MessageToAny takes any given proto message msg and returns the marshalled bytes of the proto, and a url to the type
// definition for the proto in the form of a *pany.Any, errors if nil or if the proto type doesnt exist or if there is
// a marshalling error
func MessageToAny(msg proto.Message) (*pany.Any, error) {
if msg == nil {
return nil, errors.New("MessageToAny: message cannot be nil")
}
name, err := protoToMessageName(msg)
if err != nil {
return nil, err
}
// Marshalls the message into bytes using the proto library, or gogoproto if proto errors
buf, err := protoToMessageBytes(msg)
if err != nil {
return nil, err
}
return &pany.Any{
TypeUrl: name,
Value: buf,
}, nil
}

func AnyToMessage(a *pany.Any) (proto.Message, error) {
var x ptypes.DynamicAny
err := ptypes.UnmarshalAny(a, &x)
return x.Message, err
}

func protoToMessageName(msg proto.Message) (string, error) {
typeUrlPrefix := "type.googleapis.com/"

potentialName := gogoproto.MessageName(msg)
if potentialName != "" {
return typeUrlPrefix + potentialName, nil
}
return "", fmt.Errorf("can't determine message name")
}

func protoToMessageBytes(msg proto.Message) ([]byte, error) {
if b, err := protoToMessageBytesGolang(msg); err == nil {
return b, nil
}
return protoToMessageBytesGogo(msg)
}

func protoToMessageBytesGogo(msg proto.Message) ([]byte, error) {
b := gogoproto.NewBuffer(nil)
b.SetDeterministic(true)
err := b.Marshal(msg)
return b.Bytes(), err
func MessageToAny(msg proto.Message) (*anypb.Any, error) {
return anypb.New(msg)
}

func protoToMessageBytesGolang(msg proto.Message) ([]byte, error) {
b := proto.NewBuffer(nil)
b.SetDeterministic(true)
err := b.Marshal(msg)
return b.Bytes(), err
func AnyToMessage(a *anypb.Any) (proto.Message, error) {
return anypb.UnmarshalNew(a, proto.UnmarshalOptions{})
}

0 comments on commit 60a2d91

Please sign in to comment.