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

performance: optimize by protobuf context-type. #4282

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/infrastructure/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes"
"github.com/envoyproxy/gateway/internal/ir"
kube "github.com/envoyproxy/gateway/internal/kubernetes"
)

var _ Manager = (*kubernetes.Infra)(nil)
Expand All @@ -39,7 +40,7 @@

switch cfg.EnvoyGateway.Provider.Type {
case egv1a1.ProviderTypeKubernetes:
cli, err := client.New(clicfg.GetConfigOrDie(), client.Options{Scheme: envoygateway.GetScheme()})
cli, err := client.New(kube.ProtobufConfig(clicfg.GetConfigOrDie()), client.Options{Scheme: envoygateway.GetScheme()})

Check warning on line 43 in internal/infrastructure/manager.go

View check run for this annotation

Codecov / codecov/patch

internal/infrastructure/manager.go#L43

Added line #L43 was not covered by tests
if err != nil {
return nil, err
}
Expand Down
28 changes: 0 additions & 28 deletions internal/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
kubescheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/remotecommand"

"github.com/envoyproxy/gateway/internal/envoygateway"
)

type CLIClient interface {
Expand Down Expand Up @@ -84,30 +80,6 @@ func newClientInternal(restCfg *rest.Config) (*client, error) {
return &c, err
}

func setRestDefaults(config *rest.Config) *rest.Config {
if config.GroupVersion == nil || config.GroupVersion.Empty() {
config.GroupVersion = &corev1.SchemeGroupVersion
}
if len(config.APIPath) == 0 {
if len(config.GroupVersion.Group) == 0 {
config.APIPath = "/api"
} else {
config.APIPath = "/apis"
}
}
if len(config.ContentType) == 0 {
config.ContentType = runtime.ContentTypeJSON
}
if config.NegotiatedSerializer == nil {
// This codec factory ensures the resources are not converted. Therefore, resources
// will not be round-tripped through internal versions. Defaulting does not happen
// on the client.
config.NegotiatedSerializer = serializer.NewCodecFactory(envoygateway.GetScheme()).WithoutConversion()
}

return config
}

func (c *client) RESTConfig() *rest.Config {
if c.config == nil {
return nil
Expand Down
40 changes: 40 additions & 0 deletions internal/kubernetes/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package kubernetes

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/metadata"
"k8s.io/client-go/rest"

"github.com/envoyproxy/gateway/internal/envoygateway"
)

func ProtobufConfig(restCfg *rest.Config) *rest.Config {
return setRestDefaults(restCfg)

Check warning on line 18 in internal/kubernetes/config.go

View check run for this annotation

Codecov / codecov/patch

internal/kubernetes/config.go#L17-L18

Added lines #L17 - L18 were not covered by tests
}

func setRestDefaults(config *rest.Config) *rest.Config {
config = metadata.ConfigFor(config)
if config.GroupVersion == nil || config.GroupVersion.Empty() {
config.GroupVersion = &corev1.SchemeGroupVersion
}
if len(config.APIPath) == 0 {
if len(config.GroupVersion.Group) == 0 {
config.APIPath = "/api"
} else {
config.APIPath = "/apis"

Check warning on line 30 in internal/kubernetes/config.go

View check run for this annotation

Codecov / codecov/patch

internal/kubernetes/config.go#L30

Added line #L30 was not covered by tests
}
}

// This codec factory ensures the resources are not converted. Therefore, resources
// will not be round-tripped through internal versions. Defaulting does not happen
// on the client.
config.NegotiatedSerializer = serializer.NewCodecFactory(envoygateway.GetScheme()).WithoutConversion()

return config
}
3 changes: 2 additions & 1 deletion internal/provider/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
kube "github.com/envoyproxy/gateway/internal/kubernetes"
"github.com/envoyproxy/gateway/internal/message"
"github.com/envoyproxy/gateway/internal/provider"
"github.com/envoyproxy/gateway/internal/provider/file"
Expand Down Expand Up @@ -75,7 +76,7 @@
return nil, fmt.Errorf("failed to get kubeconfig: %w", err)
}

p, err := kubernetes.New(cfg, &r.Config.Server, r.ProviderResources)
p, err := kubernetes.New(kube.ProtobufConfig(cfg), &r.Config.Server, r.ProviderResources)

Check warning on line 79 in internal/provider/runner/runner.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/runner/runner.go#L79

Added line #L79 was not covered by tests
if err != nil {
return nil, fmt.Errorf("failed to create provider %s: %w", egv1a1.ProviderTypeKubernetes, err)
}
Expand Down
Loading