Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to google.golang.org/protobuf #35659

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/census-instrumentation/opencensus-proto v0.3.0
github.com/cheggaaa/pb/v3 v3.0.8
github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
//github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e // indirect
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.9.1
github.com/coreos/go-oidc v2.2.1+incompatible
Expand Down Expand Up @@ -86,7 +87,7 @@ require (
gomodules.xyz/jsonpatch/v3 v3.0.1
google.golang.org/api v0.57.0
google.golang.org/genproto v0.0.0-20210921142501-181ce0d877f6
google.golang.org/grpc v1.41.0
google.golang.org/grpc v1.42.0-dev.0.20211015201449-4757d0249e2d
google.golang.org/protobuf v1.27.1
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e h1:xjKi0OrdbKVCLWRoF2SGNnv9todhp+zQlvRHhsb14R4=
github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 h1:hzAQntlaYRkVSFEfj9OTWlVV1H155FMD8BTKktLv0QI=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158 h1:CevA8fI91PAnP8vpnXuB8ZYAZ5wqY86nAbxfgK8tWO4=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1 h1:zH8ljVhhq7yC0MIeUL/IviMtY8hx2mK8cN9wEYb8ggw=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
Expand Down Expand Up @@ -1794,8 +1796,8 @@ google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQ
google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.41.0 h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E=
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
google.golang.org/grpc v1.42.0-dev.0.20211015201449-4757d0249e2d h1:feg9d8XiqCDr+lhZly4rL5mxFotDEar0C5ZngpoS75k=
google.golang.org/grpc v1.42.0-dev.0.20211015201449-4757d0249e2d/go.mod h1:sn+iQXCsAt+4abOFPwaqlptD9wTLjn4HDXw+aU/Qfpk=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
2 changes: 1 addition & 1 deletion istioctl/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
rbac_http_filter "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/rbac/v3"
http_conn "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
structpb "github.com/golang/protobuf/ptypes/struct"
multierror "github.com/hashicorp/go-multierror"
"github.com/spf13/cobra"
structpb "google.golang.org/protobuf/types/known/structpb"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8s_labels "k8s.io/apimachinery/pkg/labels"
Expand Down
5 changes: 2 additions & 3 deletions istioctl/cmd/precheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package cmd

import (
"bytes"
"context"
"errors"
"fmt"
Expand All @@ -26,7 +25,6 @@ import (
adminapi "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
"github.com/fatih/color"
"github.com/golang/protobuf/jsonpb"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/semaphore"
Expand All @@ -49,6 +47,7 @@ import (
"istio.io/istio/pkg/config/schema/collections"
"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/url"
"istio.io/istio/pkg/util/protomarshal"
)

func preCheck() *cobra.Command {
Expand Down Expand Up @@ -398,7 +397,7 @@ func getColumn(line string, col int) string {
func extractInboundPorts(configdump []byte) (map[int]bindStatus, error) {
ports := map[int]bindStatus{}
cd := &adminapi.ConfigDump{}
if err := jsonpb.Unmarshal(bytes.NewReader(configdump), cd); err != nil {
if err := protomarshal.Unmarshal(configdump, cd); err != nil {
return nil, err
}
for _, cdump := range cd.Configs {
Expand Down
2 changes: 1 addition & 1 deletion istioctl/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (

envoy_corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
xdsapi "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
structpb "google.golang.org/protobuf/types/known/structpb"

"istio.io/istio/istioctl/pkg/clioptions"
"istio.io/istio/istioctl/pkg/multixds"
Expand Down
9 changes: 3 additions & 6 deletions istioctl/pkg/authz/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import (
hcm_filter "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
rbac_tcp_filter "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/rbac/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"google.golang.org/protobuf/proto"

"istio.io/pkg/log"
)
Expand All @@ -52,8 +51,7 @@ type parsedListener struct {
func getFilterConfig(filter *listener.Filter, out proto.Message) error {
switch c := filter.ConfigType.(type) {
case *listener.Filter_TypedConfig:
// nolint: staticcheck
if err := ptypes.UnmarshalAny(c.TypedConfig, out); err != nil {
if err := c.TypedConfig.UnmarshalTo(out); err != nil {
return err
}
}
Expand All @@ -72,8 +70,7 @@ func getHTTPConnectionManager(filter *listener.Filter) *hcm_filter.HttpConnectio
func getHTTPFilterConfig(filter *hcm_filter.HttpFilter, out proto.Message) error {
switch c := filter.ConfigType.(type) {
case *hcm_filter.HttpFilter_TypedConfig:
// nolint: staticcheck
if err := ptypes.UnmarshalAny(c.TypedConfig, out); err != nil {
if err := c.TypedConfig.UnmarshalTo(out); err != nil {
return err
}
}
Expand Down
17 changes: 4 additions & 13 deletions istioctl/pkg/util/clusters/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
package clusters

import (
"bytes"

adminapi "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
"github.com/golang/protobuf/jsonpb"

"istio.io/istio/pkg/util/protomarshal"
)

// Wrapper is a wrapper around the Envoy Clusters
Expand All @@ -29,21 +28,13 @@ type Wrapper struct {

// MarshalJSON is a custom marshaller to handle protobuf pain
func (w *Wrapper) MarshalJSON() ([]byte, error) {
buffer := &bytes.Buffer{}
jsonm := &jsonpb.Marshaler{}
err := jsonm.Marshal(buffer, w)
if err != nil {
return nil, err
}
return buffer.Bytes(), nil
return protomarshal.Marshal(w)
}

// UnmarshalJSON is a custom unmarshaller to handle protobuf pain
func (w *Wrapper) UnmarshalJSON(b []byte) error {
buf := bytes.NewBuffer(b)
jsonum := &jsonpb.Unmarshaler{AllowUnknownFields: true}
cd := &adminapi.Clusters{}
err := jsonum.Unmarshal(buf, cd)
err := protomarshal.UnmarshalAllowUnknown(b, cd)
*w = Wrapper{cd}
return err
}
2 changes: 1 addition & 1 deletion istioctl/pkg/util/configdump/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

adminapi "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
extapi "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
any "github.com/golang/protobuf/ptypes/any"
any "google.golang.org/protobuf/types/known/anypb"
)

// GetSecretsConfigDump retrieves a secret dump from a config dump wrapper
Expand Down
2 changes: 1 addition & 1 deletion istioctl/pkg/util/configdump/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package configdump
import (
"fmt"

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

type configTypeURL string
Expand Down
10 changes: 6 additions & 4 deletions istioctl/pkg/util/proto/messageslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package proto
import (
"bytes"

"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/jsonpb"
"google.golang.org/protobuf/proto"

"istio.io/istio/pkg/util/protomarshal"
)

// MessageSlice allows us to marshal slices of protobuf messages like clusters/listeners/routes/endpoints correctly
Expand All @@ -28,11 +29,12 @@ type MessageSlice []proto.Message
func (pSlice MessageSlice) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString("[")
sliceLength := len(pSlice)
jsonm := &jsonpb.Marshaler{}
for index, msg := range pSlice {
if err := jsonm.Marshal(buffer, msg); err != nil {
b, err := protomarshal.Marshal(msg)
if err != nil {
return nil, err
}
buffer.Write(b)
if index < sliceLength-1 {
buffer.WriteString(",")
}
Expand Down
20 changes: 14 additions & 6 deletions istioctl/pkg/writer/compare/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,33 @@ import (
"bytes"
"fmt"

"github.com/golang/protobuf/jsonpb"
"github.com/pmezard/go-difflib/difflib"

"istio.io/istio/pkg/util/protomarshal"
)

// ClusterDiff prints a diff between Istiod and Envoy clusters to the passed writer
func (c *Comparator) ClusterDiff() error {
jsonm := &jsonpb.Marshaler{Indent: " "}
envoyBytes, istiodBytes := &bytes.Buffer{}, &bytes.Buffer{}
envoyClusterDump, err := c.envoy.GetDynamicClusterDump(true)
if err != nil {
envoyBytes.WriteString(err.Error())
} else if err := jsonm.Marshal(envoyBytes, envoyClusterDump); err != nil {
return err
} else {
envoy, err := protomarshal.ToJSONWithIndent(envoyClusterDump, " ")
if err != nil {
return err
}
envoyBytes.WriteString(envoy)
}
istiodClusterDump, err := c.istiod.GetDynamicClusterDump(true)
if err != nil {
istiodBytes.WriteString(err.Error())
} else if err := jsonm.Marshal(istiodBytes, istiodClusterDump); err != nil {
return err
} else {
istiod, err := protomarshal.ToJSONWithIndent(istiodClusterDump, " ")
if err != nil {
return err
}
istiodBytes.WriteString(istiod)
}
diff := difflib.UnifiedDiff{
FromFile: "Istiod Clusters",
Expand Down
20 changes: 14 additions & 6 deletions istioctl/pkg/writer/compare/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,33 @@ import (
"bytes"
"fmt"

"github.com/golang/protobuf/jsonpb"
"github.com/pmezard/go-difflib/difflib"

"istio.io/istio/pkg/util/protomarshal"
)

// ListenerDiff prints a diff between Istiod and Envoy listeners to the passed writer
func (c *Comparator) ListenerDiff() error {
jsonm := &jsonpb.Marshaler{Indent: " "}
envoyBytes, istiodBytes := &bytes.Buffer{}, &bytes.Buffer{}
envoyListenerDump, err := c.envoy.GetDynamicListenerDump(true)
if err != nil {
envoyBytes.WriteString(err.Error())
} else if err := jsonm.Marshal(envoyBytes, envoyListenerDump); err != nil {
return err
} else {
envoy, err := protomarshal.ToJSONWithIndent(envoyListenerDump, " ")
if err != nil {
return err
}
envoyBytes.WriteString(envoy)
}
istiodListenerDump, err := c.istiod.GetDynamicListenerDump(true)
if err != nil {
istiodBytes.WriteString(err.Error())
} else if err := jsonm.Marshal(istiodBytes, istiodListenerDump); err != nil {
return err
} else {
istiod, err := protomarshal.ToJSONWithIndent(istiodListenerDump, " ")
if err != nil {
return err
}
istiodBytes.WriteString(istiod)
}
diff := difflib.UnifiedDiff{
FromFile: "Istiod Listeners",
Expand Down
20 changes: 14 additions & 6 deletions istioctl/pkg/writer/compare/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,33 @@ import (
"fmt"
"time"

"github.com/golang/protobuf/jsonpb"
"github.com/pmezard/go-difflib/difflib"

"istio.io/istio/pkg/util/protomarshal"
)

// RouteDiff prints a diff between Istiod and Envoy routes to the passed writer
func (c *Comparator) RouteDiff() error {
jsonm := &jsonpb.Marshaler{Indent: " "}
envoyBytes, istiodBytes := &bytes.Buffer{}, &bytes.Buffer{}
envoyRouteDump, err := c.envoy.GetDynamicRouteDump(true)
if err != nil {
envoyBytes.WriteString(err.Error())
} else if err := jsonm.Marshal(envoyBytes, envoyRouteDump); err != nil {
return err
} else {
envoy, err := protomarshal.ToJSONWithIndent(envoyRouteDump, " ")
if err != nil {
return err
}
envoyBytes.WriteString(envoy)
}
istiodRouteDump, err := c.istiod.GetDynamicRouteDump(true)
if err != nil {
istiodBytes.WriteString(err.Error())
} else if err := jsonm.Marshal(istiodBytes, istiodRouteDump); err != nil {
return err
} else {
istiod, err := protomarshal.ToJSONWithIndent(istiodRouteDump, " ")
if err != nil {
return err
}
istiodBytes.WriteString(istiod)
}
diff := difflib.UnifiedDiff{
FromFile: "Istiod Routes",
Expand Down
8 changes: 3 additions & 5 deletions istioctl/pkg/writer/envoy/configdump/configdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"text/tabwriter"

envoy_admin_v3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
"github.com/golang/protobuf/jsonpb"
"sigs.k8s.io/yaml"

"istio.io/istio/istioctl/pkg/util/configdump"
sdscompare "istio.io/istio/istioctl/pkg/writer/compare/sds"
"istio.io/istio/pkg/util/protomarshal"
)

// ConfigWriter is a writer for processing responses from the Envoy Admin config_dump endpoint
Expand Down Expand Up @@ -57,8 +57,7 @@ func (c *ConfigWriter) PrintBootstrapDump(outputFormat string) error {
if err != nil {
return err
}
jsonm := &jsonpb.Marshaler{Indent: " "}
out, err := jsonm.MarshalToString(bootstrapDump)
out, err := protomarshal.ToJSONWithIndent(bootstrapDump, " ")
if err != nil {
return fmt.Errorf("unable to marshal bootstrap in Envoy config dump")
}
Expand All @@ -82,8 +81,7 @@ func (c *ConfigWriter) PrintSecretDump(outputFormat string) error {
if err != nil {
return fmt.Errorf("sidecar doesn't support secrets: %v", err)
}
jsonm := &jsonpb.Marshaler{Indent: " "}
out, err := jsonm.MarshalToString(secretDump)
out, err := protomarshal.ToJSONWithIndent(secretDump, " ")
if err != nil {
return fmt.Errorf("unable to marshal secrets in Envoy config dump")
}
Expand Down
2 changes: 1 addition & 1 deletion istioctl/pkg/writer/pilot/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
envoycorev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
xdsapi "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
status "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
"github.com/golang/protobuf/ptypes/any"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
any "google.golang.org/protobuf/types/known/anypb"

networkingutil "istio.io/istio/pilot/pkg/networking/util"
"istio.io/istio/pilot/pkg/xds"
Expand Down