Skip to content

Commit

Permalink
Use gwapiv1.Duration instead of metav1.Duration in the API
Browse files Browse the repository at this point in the history
* Also rm `+kubebuilder:validation:Format=duration` and instead
rely on the CEL validation of gwapiv1.Duration

Fixes: envoyproxy#4746

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg committed Dec 14, 2024
1 parent e6a74f8 commit 58c92d7
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 156 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/cors_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

// Origin is defined by the scheme (protocol), hostname (domain), and port of
// the URL used to access it. The hostname can be "precise" which is just the
Expand Down Expand Up @@ -61,7 +61,7 @@ type CORS struct {
// It specifies the value in the Access-Control-Max-Age CORS response header..
//
// +optional
MaxAge *metav1.Duration `json:"maxAge,omitempty"`
MaxAge *gwapiv1.Duration `json:"maxAge,omitempty"`

// AllowCredentials indicates whether a request can include user credentials
// like cookies, authentication headers, or TLS client certificates.
Expand Down
8 changes: 6 additions & 2 deletions api/v1alpha1/dns_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

type DNS struct {
// DNSRefreshRate specifies the rate at which DNS records should be refreshed.
// Defaults to 30 seconds.
DNSRefreshRate *metav1.Duration `json:"dnsRefreshRate,omitempty"`
//
// +optional
DNSRefreshRate *gwapiv1.Duration `json:"dnsRefreshRate,omitempty"`
// RespectDNSTTL indicates whether the DNS Time-To-Live (TTL) should be respected.
// If the value is set to true, the DNS refresh rate will be set to the resource record’s TTL.
// Defaults to true.
//
// +optional
RespectDNSTTL *bool `json:"respectDnsTtl,omitempty"`
}
16 changes: 12 additions & 4 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ type EnvoyGatewaySpec struct {
// LeaderElection defines the desired leader election settings.
type LeaderElection struct {
// LeaseDuration defines the time non-leader contenders will wait before attempting to claim leadership.
// It's based on the timestamp of the last acknowledged signal. The default setting is 15 seconds.
// It's based on the timestamp of the last acknowledged signal.
// The default setting is 15 seconds.
//
// +optional
LeaseDuration *gwapiv1.Duration `json:"leaseDuration,omitempty"`
// RenewDeadline represents the time frame within which the current leader will attempt to renew its leadership
// status before relinquishing its position. The default setting is 10 seconds.
// status before relinquishing its position.
// The default setting is 10 seconds.
//
// +optional
RenewDeadline *gwapiv1.Duration `json:"renewDeadline,omitempty"`
// RetryPeriod denotes the interval at which LeaderElector clients should perform action retries.
// The default setting is 2 seconds.
//
// +optional
RetryPeriod *gwapiv1.Duration `json:"retryPeriod,omitempty"`
// Disable provides the option to turn off leader election, which is enabled by default.
Disable *bool `json:"disable,omitempty"`
Expand Down Expand Up @@ -346,9 +354,9 @@ type RateLimit struct {

// Timeout specifies the timeout period for the proxy to access the ratelimit server
// If not set, timeout is 20ms.
//
// +optional
// +kubebuilder:validation:Format=duration
Timeout *metav1.Duration `json:"timeout,omitempty"`
Timeout *gwapiv1.Duration `json:"timeout,omitempty"`

// FailClosed is a switch used to control the flow of traffic
// when the response from the ratelimit server cannot be obtained.
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ type ShutdownConfig struct {
// If unspecified, defaults to 60 seconds.
//
// +optional
DrainTimeout *metav1.Duration `json:"drainTimeout,omitempty"`
DrainTimeout *gwapiv1.Duration `json:"drainTimeout,omitempty"`
// MinDrainDuration defines the minimum drain duration allowing time for endpoint deprogramming to complete.
// If unspecified, defaults to 10 seconds.
//
// +optional
MinDrainDuration *metav1.Duration `json:"minDrainDuration,omitempty"`
MinDrainDuration *gwapiv1.Duration `json:"minDrainDuration,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="((has(self.envoyDeployment) && !has(self.envoyDaemonSet)) || (!has(self.envoyDeployment) && has(self.envoyDaemonSet))) || (!has(self.envoyDeployment) && !has(self.envoyDaemonSet))",message="only one of envoyDeployment or envoyDaemonSet can be specified"
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/fault_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

// FaultInjection defines the fault injection policy to be applied. This configuration can be used to
// inject delays and abort requests to mimic failure scenarios such as service failures and overloads
Expand All @@ -29,7 +29,7 @@ type FaultInjectionDelay struct {
// FixedDelay specifies the fixed delay duration
//
// +required
FixedDelay *metav1.Duration `json:"fixedDelay"`
FixedDelay *gwapiv1.Duration `json:"fixedDelay"`

// Percentage specifies the percentage of requests to be delayed. Default 100%, if set 0, no requests will be delayed. Accuracy to 0.0001%.
// +optional
Expand Down
14 changes: 5 additions & 9 deletions api/v1alpha1/healthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

// HealthCheck configuration to decide which endpoints
// are healthy and can be used for routing.
Expand All @@ -30,10 +30,9 @@ type PassiveHealthCheck struct {

// Interval defines the time between passive health checks.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="3s"
// +optional
Interval *metav1.Duration `json:"interval,omitempty"`
Interval *gwapiv1.Duration `json:"interval,omitempty"`

// ConsecutiveLocalOriginFailures sets the number of consecutive local origin failures triggering ejection.
// Parameter takes effect only when split_external_local_origin_errors is set to true.
Expand All @@ -56,10 +55,9 @@ type PassiveHealthCheck struct {

// BaseEjectionTime defines the base duration for which a host will be ejected on consecutive failures.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="30s"
// +optional
BaseEjectionTime *metav1.Duration `json:"baseEjectionTime,omitempty"`
BaseEjectionTime *gwapiv1.Duration `json:"baseEjectionTime,omitempty"`

// MaxEjectionPercent sets the maximum percentage of hosts in a cluster that can be ejected.
//
Expand All @@ -78,17 +76,15 @@ type PassiveHealthCheck struct {
type ActiveHealthCheck struct {
// Timeout defines the time to wait for a health check response.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="1s"
// +optional
Timeout *metav1.Duration `json:"timeout"`
Timeout *gwapiv1.Duration `json:"timeout"`

// Interval defines the time between active health checks.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="3s"
// +optional
Interval *metav1.Duration `json:"interval"`
Interval *gwapiv1.Duration `json:"interval"`

// UnhealthyThreshold defines the number of unhealthy health checks required before a backend host is marked unhealthy.
//
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

// LoadBalancer defines the load balancer policy to be applied.
// +union
Expand Down Expand Up @@ -105,7 +105,7 @@ type Cookie struct {
// Max-Age attribute value.
//
// +optional
TTL *metav1.Duration `json:"ttl,omitempty"`
TTL *gwapiv1.Duration `json:"ttl,omitempty"`
// Additional Attributes to set for the generated cookie.
//
// +optional
Expand All @@ -132,6 +132,6 @@ type SlowStart struct {
// Currently only supports linear growth of traffic. For additional details,
// see https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto#config-cluster-v3-cluster-slowstartconfig
// +kubebuilder:validation:Required
Window *metav1.Duration `json:"window"`
Window *gwapiv1.Duration `json:"window"`
// TODO: Add support for non-linear traffic increases based on user usage.
}
6 changes: 3 additions & 3 deletions api/v1alpha1/oidc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

Expand Down Expand Up @@ -83,7 +82,7 @@ type OIDC struct {
// OAuth flow will fail.
//
// +optional
DefaultTokenTTL *metav1.Duration `json:"defaultTokenTTL,omitempty"`
DefaultTokenTTL *gwapiv1.Duration `json:"defaultTokenTTL,omitempty"`

// RefreshToken indicates whether the Envoy should automatically refresh the
// id token and access token when they expire.
Expand All @@ -100,8 +99,9 @@ type OIDC struct {
//
// If not specified, defaults to 604800s (one week).
// Note: this field is only applicable when the "refreshToken" field is set to true.
//
// +optional
DefaultRefreshTokenTTL *metav1.Duration `json:"defaultRefreshTokenTTL,omitempty"`
DefaultRefreshTokenTTL *gwapiv1.Duration `json:"defaultRefreshTokenTTL,omitempty"`
}

// OIDCProvider defines the OIDC Provider configuration.
Expand Down
12 changes: 5 additions & 7 deletions api/v1alpha1/retry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// Retry defines the retry strategy to be applied.
Expand Down Expand Up @@ -87,8 +87,7 @@ type PerRetryPolicy struct {
// Timeout is the timeout per retry attempt.
//
// +optional
// +kubebuilder:validation:Format=duration
Timeout *metav1.Duration `json:"timeout,omitempty"`
Timeout *gwapiv1.Duration `json:"timeout,omitempty"`
// Backoff is the backoff policy to be applied per retry attempt. gateway uses a fully jittered exponential
// back-off algorithm for retries. For additional details,
// see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#config-http-filters-router-x-envoy-max-retries
Expand All @@ -100,13 +99,12 @@ type PerRetryPolicy struct {
type BackOffPolicy struct {
// BaseInterval is the base interval between retries.
//
// +kubebuilder:validation:Format=duration
BaseInterval *metav1.Duration `json:"baseInterval,omitempty"`
// +optional
BaseInterval *gwapiv1.Duration `json:"baseInterval,omitempty"`
// MaxInterval is the maximum interval between retries. This parameter is optional, but must be greater than or equal to the base_interval if set.
// The default is 10 times the base_interval
//
// +optional
// +kubebuilder:validation:Format=duration
MaxInterval *metav1.Duration `json:"maxInterval,omitempty"`
MaxInterval *gwapiv1.Duration `json:"maxInterval,omitempty"`
// we can add rate limited based backoff config here if we want to.
}
34 changes: 17 additions & 17 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 58c92d7

Please sign in to comment.