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

chore: Simplify DNSPolicy API #858

Merged
merged 1 commit into from
Sep 18, 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
81 changes: 23 additions & 58 deletions api/v1alpha1/dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ var (
}
)

type RoutingStrategy string

const (
SimpleRoutingStrategy RoutingStrategy = "simple"
LoadBalancedRoutingStrategy RoutingStrategy = "loadbalanced"

DefaultWeight Weight = 120
DefaultWeight int = 120
DefaultGeo GeoCode = "default"
WildcardGeo GeoCode = "*"

Expand All @@ -56,7 +51,7 @@ const (
)

// DNSPolicySpec defines the desired state of DNSPolicy
// +kubebuilder:validation:XValidation:rule="!(self.routingStrategy == 'loadbalanced' && !has(self.loadBalancing))",message="spec.loadBalancing is a required field when spec.routingStrategy == 'loadbalanced'"
// +kubebuilder:validation:XValidation:rule="(!has(oldSelf.loadBalancing) || has(self.loadBalancing)) && (has(oldSelf.loadBalancing) || !has(self.loadBalancing))", message="loadBalancing is immutable"
mikenairn marked this conversation as resolved.
Show resolved Hide resolved
type DNSPolicySpec struct {
// targetRef identifies an API object to apply policy to.
// +kubebuilder:validation:XValidation:rule="self.group == 'gateway.networking.k8s.io'",message="Invalid targetRef.group. The only supported value is 'gateway.networking.k8s.io'"
Expand All @@ -69,45 +64,35 @@ type DNSPolicySpec struct {
// +optional
LoadBalancing *LoadBalancingSpec `json:"loadBalancing,omitempty"`

// +kubebuilder:validation:Enum=simple;loadbalanced
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="RoutingStrategy is immutable"
// +kubebuilder:default=loadbalanced
RoutingStrategy RoutingStrategy `json:"routingStrategy"`

// providerRefs is a list of references to provider secrets. Max is one but intention is to allow this to be more in the future
// +kubebuilder:validation:MaxItems=1
// +kubebuilder:validation:MinItems=1
ProviderRefs []dnsv1alpha1.ProviderRef `json:"providerRefs"`
}

type LoadBalancingSpec struct {
Weighted LoadBalancingWeighted `json:"weighted"`

Geo LoadBalancingGeo `json:"geo"`
}

// +kubebuilder:validation:Minimum=0
type Weight int

type CustomWeight struct {
// Label selector to match resource storing custom weight attribute values e.g. kuadrant.io/lb-attribute-custom-weight: AWS.
Selector *metav1.LabelSelector `json:"selector"`

// The weight value to apply when the selector matches.
Weight Weight `json:"weight"`
}

type LoadBalancingWeighted struct {
// defaultWeight is the record weight to use when no other can be determined for a dns target cluster.
// weight value to apply to weighted endpoints.
//
// The maximum value accepted is determined by the target dns provider, please refer to the appropriate docs below.
//
// Route53: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-weighted.html
DefaultWeight Weight `json:"defaultWeight"`
// Google: https://cloud.google.com/dns/docs/overview/
// Azure: https://learn.microsoft.com/en-us/azure/traffic-manager/traffic-manager-routing-methods#weighted-traffic-routing-method
// +kubebuilder:default=120
Weight int `json:"weight"`
mikenairn marked this conversation as resolved.
Show resolved Hide resolved

// custom list of custom weight selectors.
// +optional
Custom []*CustomWeight `json:"custom,omitempty"`
// geo value to apply to geo endpoints.
//
// The values accepted are determined by the target dns provider, please refer to the appropriate docs below.
//
// Route53: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-geo.html
// Google: https://cloud.google.com/compute/docs/regions-zones
// Azure: https://learn.microsoft.com/en-us/azure/traffic-manager/traffic-manager-geographic-regions
// +kubebuilder:validation:MinLength=2
Geo string `json:"geo"`

// defaultGeo specifies if this is the default geo for providers that support setting a default catch all geo endpoint such as Route53.
DefaultGeo bool `json:"defaultGeo"`
mikenairn marked this conversation as resolved.
Show resolved Hide resolved
}

type GeoCode string
Expand All @@ -120,17 +105,6 @@ func (gc GeoCode) IsWildcard() bool {
return gc == WildcardGeo
}

type LoadBalancingGeo struct {
// defaultGeo is the country/continent/region code to use when no other can be determined for a dns target cluster.
//
// The values accepted are determined by the target dns provider, please refer to the appropriate docs below.
//
// Route53: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-geo.html
// Google: https://cloud.google.com/compute/docs/regions-zones
// +kubebuilder:validation:MinLength=2
DefaultGeo string `json:"defaultGeo"`
}

// DNSPolicyStatus defines the observed state of DNSPolicy
type DNSPolicyStatus struct {
// conditions are any conditions associated with the policy
Expand Down Expand Up @@ -264,11 +238,6 @@ func (p *DNSPolicy) WithLoadBalancing(loadBalancing LoadBalancingSpec) *DNSPolic
return p
}

func (p *DNSPolicy) WithRoutingStrategy(strategy RoutingStrategy) *DNSPolicy {
p.Spec.RoutingStrategy = strategy
return p
}

func (p *DNSPolicy) WithProviderRef(providerRef dnsv1alpha1.ProviderRef) *DNSPolicy {
p.Spec.ProviderRefs = append(p.Spec.ProviderRefs, providerRef)
return p
Expand Down Expand Up @@ -305,15 +274,11 @@ func (p *DNSPolicy) WithHealthCheckFor(endpoint string, port int, protocol strin

//LoadBalancing

func (p *DNSPolicy) WithLoadBalancingFor(defaultWeight Weight, custom []*CustomWeight, defaultGeo string) *DNSPolicy {
func (p *DNSPolicy) WithLoadBalancingFor(weight int, geo string, isDefaultGeo bool) *DNSPolicy {
return p.WithLoadBalancing(LoadBalancingSpec{
Weighted: LoadBalancingWeighted{
DefaultWeight: defaultWeight,
Custom: custom,
},
Geo: LoadBalancingGeo{
DefaultGeo: defaultGeo,
},
Weight: weight,
Geo: geo,
DefaultGeo: isDefaultGeo,
})
}

Expand Down
65 changes: 1 addition & 64 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/kuadrant/kuadrant-operator:latest
createdAt: "2024-09-12T15:37:42Z"
createdAt: "2024-09-17T13:54:51Z"
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/Kuadrant/kuadrant-operator
Expand Down
Loading
Loading