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

lint: enable gofumpt #3291

Merged
merged 2 commits into from
Apr 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions api/v1alpha1/clienttrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ type CustomHeaderExtensionSettings struct {
}

// HTTP3Settings provides HTTP/3 configuration on the listener.
type HTTP3Settings struct {
}
type HTTP3Settings struct{}

// HTTP1Settings provides HTTP/1 configuration on the listener.
type HTTP1Settings struct {
Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/compression_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type CompressorType string
// GzipCompressor defines the config for the Gzip compressor.
// The default values can be found here:
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/compression/gzip/compressor/v3/gzip.proto#extension-envoy-compression-gzip-compressor
type GzipCompressor struct {
}
type GzipCompressor struct{}

// Compression defines the config of enabling compression.
// This can help reduce the bandwidth at the expense of higher CPU.
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ type ExtensionTLS struct {

// EnvoyGatewayAdmin defines the Envoy Gateway Admin configuration.
type EnvoyGatewayAdmin struct {

// Address defines the address of Envoy Gateway Admin Server.
//
// +optional
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/fault_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
//
// +kubebuilder:validation:XValidation:rule=" has(self.delay) || has(self.abort) ",message="Delay and abort faults are set at least one."
type FaultInjection struct {

// If specified, a delay will be injected into the request.
//
// +optional
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/healthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type HealthCheck struct {
// PassiveHealthCheck defines the configuration for passive health checks in the context of Envoy's Outlier Detection,
// see https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/outlier
type PassiveHealthCheck struct {

// SplitExternalLocalOriginErrors enables splitting of errors between external and local origin.
//
// +kubebuilder:default=false
Expand Down
2 changes: 0 additions & 2 deletions api/v1alpha1/jwt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package v1alpha1

// JWT defines the configuration for JSON Web Token (JWT) authentication.
type JWT struct {

// Optional determines whether a missing JWT is acceptable, defaulting to false if not specified.
// Note: Even if optional is set to true, JWT authentication will still fail if an invalid JWT is presented.
Optional *bool `json:"optional,omitempty"`
Expand Down Expand Up @@ -91,7 +90,6 @@ type RemoteJWKS struct {

// ClaimToHeader defines a configuration to convert JWT claims into HTTP headers
type ClaimToHeader struct {

// Header defines the name of the HTTP request header that the JWT Claim will be saved into.
Header string `json:"header"`

Expand Down
6 changes: 4 additions & 2 deletions api/v1alpha1/validation/envoygateway_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ func TestEnvoyGatewayProvider(t *testing.T) {
Replicas: nil,
Pod: nil,
Container: nil,
}}
},
}
assert.Nil(t, envoyGatewayProvider.Kubernetes.RateLimitDeployment.Replicas)
assert.Nil(t, envoyGatewayProvider.Kubernetes.RateLimitDeployment.Pod)
assert.Nil(t, envoyGatewayProvider.Kubernetes.RateLimitDeployment.Container)
Expand All @@ -674,7 +675,8 @@ func TestEnvoyGatewayProvider(t *testing.T) {
SecurityContext: nil,
Image: nil,
},
}}
},
}
assert.Nil(t, envoyGatewayProvider.Kubernetes.RateLimitDeployment.Container.Resources)
envoyGatewayProvider.GetEnvoyGatewayKubeProvider()

Expand Down
6 changes: 2 additions & 4 deletions api/v1alpha1/validation/envoyproxy_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ func validateService(spec *egv1a1.EnvoyProxySpec) []error {
errs = append(errs, fmt.Errorf("unsupported envoy service type %v", serviceType))
}
}
if serviceType, serviceAllocateLoadBalancerNodePorts :=
spec.Provider.Kubernetes.EnvoyService.Type, spec.Provider.Kubernetes.EnvoyService.AllocateLoadBalancerNodePorts; serviceType != nil && serviceAllocateLoadBalancerNodePorts != nil {
if serviceType, serviceAllocateLoadBalancerNodePorts := spec.Provider.Kubernetes.EnvoyService.Type, spec.Provider.Kubernetes.EnvoyService.AllocateLoadBalancerNodePorts; serviceType != nil && serviceAllocateLoadBalancerNodePorts != nil {
if *serviceType != egv1a1.ServiceTypeLoadBalancer {
errs = append(errs, fmt.Errorf("allocateLoadBalancerNodePorts can only be set for %v type", egv1a1.ServiceTypeLoadBalancer))
}
}
if serviceType, serviceLoadBalancerSourceRanges :=
spec.Provider.Kubernetes.EnvoyService.Type, spec.Provider.Kubernetes.EnvoyService.LoadBalancerSourceRanges; serviceType != nil && serviceLoadBalancerSourceRanges != nil {
if serviceType, serviceLoadBalancerSourceRanges := spec.Provider.Kubernetes.EnvoyService.Type, spec.Provider.Kubernetes.EnvoyService.LoadBalancerSourceRanges; serviceType != nil && serviceLoadBalancerSourceRanges != nil {
if *serviceType != egv1a1.ServiceTypeLoadBalancer {
errs = append(errs, fmt.Errorf("loadBalancerSourceRanges can only be set for %v type", egv1a1.ServiceTypeLoadBalancer))
}
Expand Down
21 changes: 14 additions & 7 deletions api/v1alpha1/validation/envoyproxy_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: false,
}, {
},
{
name: "should invalid when metrics type is OpenTelemetry, but `OpenTelemetry` field being empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -467,7 +468,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: false,
}, {
},
{
name: "should valid when metrics type is OpenTelemetry and `OpenTelemetry` field being not empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -491,7 +493,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: true,
}, {
},
{
name: "should be invalid when service patch type is empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -514,7 +517,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: true,
}, {
},
{
name: "should be invalid when deployment patch type is empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -537,7 +541,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: true,
}, {
},
{
name: "should invalid when patch object is empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -558,7 +563,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: false,
}, {
},
{
name: "should valid when patch type and object are both not empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -582,7 +588,8 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
},
expected: true,
}, {
},
{
name: "should valid when patch type is empty and object is not empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Expand Down
4 changes: 1 addition & 3 deletions internal/admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
"github.com/envoyproxy/gateway/internal/logging"
)

var (
adminLogger = logging.DefaultLogger(v1alpha1.LogLevelInfo).WithName("admin")
)
var adminLogger = logging.DefaultLogger(v1alpha1.LogLevelInfo).WithName("admin")

func Init(cfg *config.Server) error {
if cfg.EnvoyGateway.GetEnvoyGatewayAdmin().EnableDumpConfig {
Expand Down
11 changes: 1 addition & 10 deletions internal/cmd/egctl/config_ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ var (
)

func ratelimitConfigCommand() *cobra.Command {

var (
namespace string
)
var namespace string

rlConfigCmd := &cobra.Command{
Use: "envoy-ratelimit",
Expand All @@ -57,7 +54,6 @@ func ratelimitConfigCommand() *cobra.Command {
}

func runRateLimitConfig(c *cobra.Command, ns string) error {

cli, err := getCLIClient()
if err != nil {
return err
Expand All @@ -73,7 +69,6 @@ func runRateLimitConfig(c *cobra.Command, ns string) error {
}

func retrieveRateLimitConfig(cli kubernetes.CLIClient, ns string) ([]byte, error) {

// Before retrieving the rate limit configuration
// we make sure that the global rate limit feature is enabled
if enable, err := checkEnableGlobalRateLimit(cli); !enable {
Expand Down Expand Up @@ -103,7 +98,6 @@ func retrieveRateLimitConfig(cli kubernetes.CLIClient, ns string) ([]byte, error
// fetchRunningRateLimitPods gets the rate limit Pods, based on the labelSelectors.
// It further filters out only those rate limit Pods that are in "Running" state.
func fetchRunningRateLimitPods(cli kubernetes.CLIClient, namespace string, labelSelector []string) ([]types.NamespacedName, error) {

// Since multiple replicas of the rate limit are configured to be equal,
// we do not need to use the pod name to obtain the specified pod.
rlPods, err := cli.PodsForSelector(namespace, labelSelector...)
Expand Down Expand Up @@ -134,7 +128,6 @@ func fetchRunningRateLimitPods(cli kubernetes.CLIClient, namespace string, label

// checkRateLimitPodStatusReady Check that the rate limit pod is ready
func checkRateLimitPodStatusReady(status corev1.PodStatus) bool {

if status.Phase != corev1.PodRunning {
return false
}
Expand All @@ -152,7 +145,6 @@ func checkRateLimitPodStatusReady(status corev1.PodStatus) bool {
// extractRateLimitConfig After turning on port forwarding through PortForwarder,
// construct a request and send it to the rate limit Pod to obtain relevant configuration information.
func extractRateLimitConfig(fw kubernetes.PortForwarder, rlPod types.NamespacedName) ([]byte, error) {

if err := fw.Start(); err != nil {
return nil, fmt.Errorf("failed to start port forwarding for pod %s/%s: %w", rlPod.Namespace, rlPod.Name, err)
}
Expand All @@ -168,7 +160,6 @@ func extractRateLimitConfig(fw kubernetes.PortForwarder, rlPod types.NamespacedN

// checkEnableGlobalRateLimit Check whether the Global Rate Limit function is enabled
func checkEnableGlobalRateLimit(cli kubernetes.CLIClient) (bool, error) {

kubeCli := cli.Kube()
cm, err := kubeCli.CoreV1().
ConfigMaps(defaultRateLimitNamespace).
Expand Down
26 changes: 6 additions & 20 deletions internal/cmd/egctl/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func TestExtractSubResourcesConfigDump(t *testing.T) {
output: "yaml",
resourceType: BootstrapEnvoyConfigType,
expected: "out.bootstrap.yaml",
}, {
},
{
output: "json",
resourceType: ClusterEnvoyConfigType,
expected: "out.cluster.json",
Expand All @@ -165,7 +166,8 @@ func TestExtractSubResourcesConfigDump(t *testing.T) {
output: "yaml",
resourceType: ClusterEnvoyConfigType,
expected: "out.cluster.yaml",
}, {
},
{
output: "json",
resourceType: ListenerEnvoyConfigType,
expected: "out.listener.json",
Expand All @@ -174,7 +176,8 @@ func TestExtractSubResourcesConfigDump(t *testing.T) {
output: "yaml",
resourceType: ListenerEnvoyConfigType,
expected: "out.listener.yaml",
}, {
},
{
output: "json",
resourceType: RouteEnvoyConfigType,
expected: "out.route.json",
Expand Down Expand Up @@ -303,7 +306,6 @@ func (f *fakeCLIClient) Kube() kubernetes.Interface {
}

func TestFetchRunningRateLimitPods(t *testing.T) {

cases := []struct {
caseName string
rlPods []corev1.Pod
Expand Down Expand Up @@ -363,23 +365,18 @@ func TestFetchRunningRateLimitPods(t *testing.T) {
}

for _, tc := range cases {

t.Run(tc.caseName, func(t *testing.T) {

fakeCli := &fakeCLIClient{
pods: tc.rlPods,
}

_, err := fetchRunningRateLimitPods(fakeCli, tc.namespace, tc.labelSelector)
require.Equal(t, tc.expectErr, err)

})

}
}

func TestCheckEnableGlobalRateLimit(t *testing.T) {

cases := []struct {
caseName string
egConfigMap *corev1.ConfigMap
Expand Down Expand Up @@ -433,24 +430,19 @@ gateway:
}

for _, tc := range cases {

t.Run(tc.caseName, func(t *testing.T) {

fakeCli := &fakeCLIClient{
cm: tc.egConfigMap,
}

actual, err := checkEnableGlobalRateLimit(fakeCli)
require.Equal(t, tc.expect, actual)
require.NoError(t, err)

})

}
}

func TestExtractRateLimitConfig(t *testing.T) {

cases := []struct {
caseName string
responseBody []byte
Expand All @@ -467,23 +459,18 @@ func TestExtractRateLimitConfig(t *testing.T) {
}

for _, tc := range cases {

t.Run(tc.caseName, func(t *testing.T) {

fw, err := newFakePortForwarder(tc.responseBody)
require.NoError(t, err)

out, err := extractRateLimitConfig(fw, tc.rlPod)
require.NoError(t, err)
require.NotEmpty(t, out)

})

}
}

func TestCheckRateLimitPodStatusReady(t *testing.T) {

cases := []struct {
caseName string
status corev1.PodStatus
Expand Down Expand Up @@ -538,5 +525,4 @@ func TestCheckRateLimitPodStatusReady(t *testing.T) {
require.Equal(t, tc.expect, actual)
})
}

}
4 changes: 1 addition & 3 deletions internal/cmd/egctl/envoy_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ const (
prometheusOutput = "prom"
)

var (
statsType, outputFormat string
)
var statsType, outputFormat string

func newEnvoyStatsCmd() *cobra.Command {
var podName, podNamespace string
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/egctl/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func newInstallCommand() *cobra.Command {

packageFlags := &helm.PackageOptions{}
pt := helm.NewPackageTool()

Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/egctl/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ func getValidOutputTypesStr() string {
}

func validResourceTypes() []envoyConfigType {
return []envoyConfigType{BootstrapEnvoyConfigType,
return []envoyConfigType{
BootstrapEnvoyConfigType,
EndpointEnvoyConfigType,
ClusterEnvoyConfigType,
ListenerEnvoyConfigType,
RouteEnvoyConfigType,
AllEnvoyConfigType}
AllEnvoyConfigType,
}
}

func isValidResourceType(outType envoyConfigType) bool {
Expand Down
Loading
Loading