Skip to content

Commit

Permalink
chore: enable importas for lint (#3603)
Browse files Browse the repository at this point in the history
* enable lint-importas check for gateway and k8s api

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* fix lint

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

---------

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 authored Jun 14, 2024
1 parent 59614bd commit 28e1a48
Show file tree
Hide file tree
Showing 92 changed files with 1,279 additions and 1,252 deletions.
6 changes: 3 additions & 3 deletions api/v1alpha1/envoygateway_metrics_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package v1alpha1

import gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

// EnvoyGatewayMetrics defines control plane push/pull metrics configurations.
type EnvoyGatewayMetrics struct {
Expand Down Expand Up @@ -45,13 +45,13 @@ type EnvoyGatewayOpenTelemetrySink struct {
// OTEL_METRIC_EXPORT_INTERVAL environment variable.
// If ExportInterval is less than or equal to zero, 60 seconds
// is used as the default.
ExportInterval *gatewayv1.Duration `json:"exportInterval,omitempty"`
ExportInterval *gwapiv1.Duration `json:"exportInterval,omitempty"`
// ExportTimeout configures the time a Sink waits for an export to
// complete before canceling it. This option overrides any value set for the
// OTEL_METRIC_EXPORT_TIMEOUT environment variable.
// If ExportTimeout is less than or equal to zero, 30 seconds
// is used as the default.
ExportTimeout *gatewayv1.Duration `json:"exportTimeout,omitempty"`
ExportTimeout *gwapiv1.Duration `json:"exportTimeout,omitempty"`
}

// EnvoyGatewayPrometheusProvider will expose prometheus endpoint in pull mode.
Expand Down
14 changes: 7 additions & 7 deletions api/v1alpha1/envoyproxy_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"

autoscalingv2 "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"
)
Expand Down Expand Up @@ -46,7 +46,7 @@ func DefaultEnvoyProxyHpaMetrics() []autoscalingv2.MetricSpec {
return []autoscalingv2.MetricSpec{
{
Resource: &autoscalingv2.ResourceMetricSource{
Name: v1.ResourceCPU,
Name: corev1.ResourceCPU,
Target: autoscalingv2.MetricTarget{
Type: autoscalingv2.UtilizationMetricType,
AverageUtilization: ptr.To[int32](80),
Expand Down Expand Up @@ -149,11 +149,11 @@ func (logging *ProxyLogging) GetEnvoyProxyComponentLevel() string {
}

// DefaultShutdownManagerContainerResourceRequirements returns a new ResourceRequirements with default settings.
func DefaultShutdownManagerContainerResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse(DefaultShutdownManagerCPUResourceRequests),
v1.ResourceMemory: resource.MustParse(DefaultShutdownManagerMemoryResourceRequests),
func DefaultShutdownManagerContainerResourceRequirements() *corev1.ResourceRequirements {
return &corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(DefaultShutdownManagerCPUResourceRequests),
corev1.ResourceMemory: resource.MustParse(DefaultShutdownManagerMemoryResourceRequests),
},
}
}
26 changes: 13 additions & 13 deletions api/v1alpha1/kubernetes_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
"fmt"

jsonpatch "github.com/evanphx/json-patch"
appv1 "k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/utils/ptr"
)

// DefaultKubernetesDeploymentStrategy returns the default deployment strategy settings.
func DefaultKubernetesDeploymentStrategy() *appv1.DeploymentStrategy {
return &appv1.DeploymentStrategy{
Type: appv1.RollingUpdateDeploymentStrategyType,
func DefaultKubernetesDeploymentStrategy() *appsv1.DeploymentStrategy {
return &appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
}
}

// DefaultKubernetesDaemonSetStrategy returns the default daemonset strategy settings.
func DefaultKubernetesDaemonSetStrategy() *appv1.DaemonSetUpdateStrategy {
return &appv1.DaemonSetUpdateStrategy{
Type: appv1.RollingUpdateDaemonSetStrategyType,
func DefaultKubernetesDaemonSetStrategy() *appsv1.DaemonSetUpdateStrategy {
return &appsv1.DaemonSetUpdateStrategy{
Type: appsv1.RollingUpdateDaemonSetStrategyType,
}
}

Expand Down Expand Up @@ -157,7 +157,7 @@ func (hpa *KubernetesHorizontalPodAutoscalerSpec) setDefault() {
}

// ApplyMergePatch applies a merge patch to a deployment based on the merge type
func (deployment *KubernetesDeploymentSpec) ApplyMergePatch(old *appv1.Deployment) (*appv1.Deployment, error) {
func (deployment *KubernetesDeploymentSpec) ApplyMergePatch(old *appsv1.Deployment) (*appsv1.Deployment, error) {
if deployment.Patch == nil {
return old, nil
}
Expand All @@ -173,7 +173,7 @@ func (deployment *KubernetesDeploymentSpec) ApplyMergePatch(old *appv1.Deploymen

switch {
case deployment.Patch.Type == nil || *deployment.Patch.Type == StrategicMerge:
patchedJSON, err = strategicpatch.StrategicMergePatch(originalJSON, deployment.Patch.Value.Raw, appv1.Deployment{})
patchedJSON, err = strategicpatch.StrategicMergePatch(originalJSON, deployment.Patch.Value.Raw, appsv1.Deployment{})
case *deployment.Patch.Type == JSONMerge:
patchedJSON, err = jsonpatch.MergePatch(originalJSON, deployment.Patch.Value.Raw)
default:
Expand All @@ -184,7 +184,7 @@ func (deployment *KubernetesDeploymentSpec) ApplyMergePatch(old *appv1.Deploymen
}

// Deserialize the patched JSON into a new deployment object
var patchedDeployment appv1.Deployment
var patchedDeployment appsv1.Deployment
if err := json.Unmarshal(patchedJSON, &patchedDeployment); err != nil {
return nil, fmt.Errorf("error unmarshaling patched deployment: %w", err)
}
Expand All @@ -193,7 +193,7 @@ func (deployment *KubernetesDeploymentSpec) ApplyMergePatch(old *appv1.Deploymen
}

// ApplyMergePatch applies a merge patch to a daemonset based on the merge type
func (daemonset *KubernetesDaemonSetSpec) ApplyMergePatch(old *appv1.DaemonSet) (*appv1.DaemonSet, error) {
func (daemonset *KubernetesDaemonSetSpec) ApplyMergePatch(old *appsv1.DaemonSet) (*appsv1.DaemonSet, error) {
if daemonset.Patch == nil {
return old, nil
}
Expand All @@ -209,7 +209,7 @@ func (daemonset *KubernetesDaemonSetSpec) ApplyMergePatch(old *appv1.DaemonSet)

switch {
case daemonset.Patch.Type == nil || *daemonset.Patch.Type == StrategicMerge:
patchedJSON, err = strategicpatch.StrategicMergePatch(originalJSON, daemonset.Patch.Value.Raw, appv1.DaemonSet{})
patchedJSON, err = strategicpatch.StrategicMergePatch(originalJSON, daemonset.Patch.Value.Raw, appsv1.DaemonSet{})
case *daemonset.Patch.Type == JSONMerge:
patchedJSON, err = jsonpatch.MergePatch(originalJSON, daemonset.Patch.Value.Raw)
default:
Expand All @@ -220,7 +220,7 @@ func (daemonset *KubernetesDaemonSetSpec) ApplyMergePatch(old *appv1.DaemonSet)
}

// Deserialize the patched JSON into a new daemonset object
var patchedDaemonSet appv1.DaemonSet
var patchedDaemonSet appsv1.DaemonSet
if err := json.Unmarshal(patchedJSON, &patchedDaemonSet); err != nil {
return nil, fmt.Errorf("error unmarshaling patched daemonset: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package v1alpha1

import (
appv1 "k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -72,7 +72,7 @@ type KubernetesDeploymentSpec struct {

// The deployment strategy to use to replace existing pods with new ones.
// +optional
Strategy *appv1.DeploymentStrategy `json:"strategy,omitempty"`
Strategy *appsv1.DeploymentStrategy `json:"strategy,omitempty"`

// Pod defines the desired specification of pod.
//
Expand Down Expand Up @@ -107,7 +107,7 @@ type KubernetesDaemonSetSpec struct {

// The daemonset strategy to use to replace existing pods with new ones.
// +optional
Strategy *appv1.DaemonSetUpdateStrategy `json:"strategy,omitempty"`
Strategy *appsv1.DaemonSetUpdateStrategy `json:"strategy,omitempty"`

// Pod defines the desired specification of pod.
//
Expand Down
30 changes: 15 additions & 15 deletions api/v1alpha1/validation/envoygateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/envoyproxy/gateway/api/v1alpha1"
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
)

// ValidateEnvoyGateway validates the provided EnvoyGateway.
func ValidateEnvoyGateway(eg *v1alpha1.EnvoyGateway) error {
func ValidateEnvoyGateway(eg *egv1a1.EnvoyGateway) error {
switch {
case eg == nil:
return errors.New("envoy gateway config is unspecified")
Expand All @@ -26,16 +26,16 @@ func ValidateEnvoyGateway(eg *v1alpha1.EnvoyGateway) error {
return errors.New("gateway controllerName is unspecified")
case eg.Provider == nil:
return errors.New("provider is unspecified")
case eg.Provider.Type != v1alpha1.ProviderTypeKubernetes:
case eg.Provider.Type != egv1a1.ProviderTypeKubernetes:
return fmt.Errorf("unsupported provider %v", eg.Provider.Type)
case eg.Provider.Kubernetes != nil && eg.Provider.Kubernetes.Watch != nil:
watch := eg.Provider.Kubernetes.Watch
switch watch.Type {
case v1alpha1.KubernetesWatchModeTypeNamespaces:
case egv1a1.KubernetesWatchModeTypeNamespaces:
if len(watch.Namespaces) == 0 {
return errors.New("namespaces should be specified when envoy gateway watch mode is 'Namespaces'")
}
case v1alpha1.KubernetesWatchModeTypeNamespaceSelector:
case egv1a1.KubernetesWatchModeTypeNamespaceSelector:
if watch.NamespaceSelector == nil {
return errors.New("namespaceSelector should be specified when envoy gateway watch mode is 'NamespaceSelector'")
}
Expand All @@ -46,15 +46,15 @@ func ValidateEnvoyGateway(eg *v1alpha1.EnvoyGateway) error {
level := eg.Logging.Level
for component, logLevel := range level {
switch component {
case v1alpha1.LogComponentGatewayDefault,
v1alpha1.LogComponentProviderRunner,
v1alpha1.LogComponentGatewayAPIRunner,
v1alpha1.LogComponentXdsTranslatorRunner,
v1alpha1.LogComponentXdsServerRunner,
v1alpha1.LogComponentInfrastructureRunner,
v1alpha1.LogComponentGlobalRateLimitRunner:
case egv1a1.LogComponentGatewayDefault,
egv1a1.LogComponentProviderRunner,
egv1a1.LogComponentGatewayAPIRunner,
egv1a1.LogComponentXdsTranslatorRunner,
egv1a1.LogComponentXdsServerRunner,
egv1a1.LogComponentInfrastructureRunner,
egv1a1.LogComponentGlobalRateLimitRunner:
switch logLevel {
case v1alpha1.LogLevelDebug, v1alpha1.LogLevelError, v1alpha1.LogLevelWarn, v1alpha1.LogLevelInfo:
case egv1a1.LogLevelDebug, egv1a1.LogLevelError, egv1a1.LogLevelWarn, egv1a1.LogLevelInfo:
default:
return errors.New("envoy gateway logging level invalid. valid options: info/debug/warn/error")
}
Expand All @@ -63,7 +63,7 @@ func ValidateEnvoyGateway(eg *v1alpha1.EnvoyGateway) error {
}
}
case eg.RateLimit != nil:
if eg.RateLimit.Backend.Type != v1alpha1.RedisBackendType {
if eg.RateLimit.Backend.Type != egv1a1.RedisBackendType {
return fmt.Errorf("unsupported ratelimit backend %v", eg.RateLimit.Backend.Type)
}
if eg.RateLimit.Backend.Redis == nil || eg.RateLimit.Backend.Redis.URL == "" {
Expand Down Expand Up @@ -111,7 +111,7 @@ func ValidateEnvoyGateway(eg *v1alpha1.EnvoyGateway) error {
case eg.Telemetry != nil:
if eg.Telemetry.Metrics != nil {
for _, sink := range eg.Telemetry.Metrics.Sinks {
if sink.Type == v1alpha1.MetricSinkTypeOpenTelemetry {
if sink.Type == egv1a1.MetricSinkTypeOpenTelemetry {
if sink.OpenTelemetry == nil {
return fmt.Errorf("OpenTelemetry is required when sink Type is OpenTelemetry")
}
Expand Down
Loading

0 comments on commit 28e1a48

Please sign in to comment.