Skip to content

Commit

Permalink
chore: Simplify DNSPolicy API
Browse files Browse the repository at this point in the history
* Remove RoutingStrategy field. LoadBalanced vs Simple can be inferred
  from the value of the LoadBalancingSpec on the policy.
* Simplify LoadBalancingSpec:
  - No longer uses label selectors to get values for geo or weight from
    a metav1.Object, but the values themselves should be set directly in
the policy.
  - LoadBalancingSpec.DefaultGeo specifies if the current geo is the
    default one or not and signals to the endpoint generation whether to
create the wildcard catch all endpoint.

Signed-off-by: Michael Nairn <mnairn@redhat.com>
  • Loading branch information
mikenairn committed Sep 16, 2024
1 parent f51be7b commit 994148b
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 1,392 deletions.
79 changes: 21 additions & 58 deletions api/v1alpha1/dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,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 @@ -57,7 +52,6 @@ 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'"
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 @@ -70,45 +64,34 @@ 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
Weight int `json:"weight"`

// 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"`
}

type GeoCode string
Expand All @@ -121,17 +104,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 @@ -265,11 +237,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 @@ -306,15 +273,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-08-20T09:51:49Z"
createdAt: "2024-09-16T11:15:15Z"
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
124 changes: 23 additions & 101 deletions bundle/manifests/kuadrant.io_dnspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,104 +102,40 @@ spec:
type: object
loadBalancing:
properties:
defaultGeo:
description: defaultGeo specifies if this is the default geo for
providers that support setting a default catch all geo endpoint
such as Route53.
type: boolean
geo:
properties:
defaultGeo:
description: |-
defaultGeo is the country/continent/region code to use when no other can be determined for a dns target cluster.
description: |-
geo value to apply to geo endpoints.
The values accepted are determined by the target dns provider, please refer to the appropriate docs below.
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
minLength: 2
type: string
required:
- defaultGeo
type: object
weighted:
properties:
custom:
description: custom list of custom weight selectors.
items:
properties:
selector:
description: 'Label selector to match resource storing
custom weight attribute values e.g. kuadrant.io/lb-attribute-custom-weight:
AWS.'
properties:
matchExpressions:
description: matchExpressions is a list of label
selector requirements. The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the
selector applies to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
weight:
description: The weight value to apply when the selector
matches.
minimum: 0
type: integer
required:
- selector
- weight
type: object
type: array
defaultWeight:
description: |-
defaultWeight is the record weight to use when no other can be determined for a dns target cluster.
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
minLength: 2
type: string
weight:
description: |-
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.
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
minimum: 0
type: integer
required:
- defaultWeight
type: object
Route53: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-weighted.html
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
type: integer
required:
- defaultGeo
- geo
- weighted
- weight
type: object
providerRefs:
description: providerRefs is a list of references to provider secrets.
Expand All @@ -215,15 +151,6 @@ spec:
maxItems: 1
minItems: 1
type: array
routingStrategy:
default: loadbalanced
enum:
- simple
- loadbalanced
type: string
x-kubernetes-validations:
- message: RoutingStrategy is immutable
rule: self == oldSelf
targetRef:
description: targetRef identifies an API object to apply policy to.
properties:
Expand Down Expand Up @@ -255,13 +182,8 @@ spec:
rule: self.kind == 'Gateway'
required:
- providerRefs
- routingStrategy
- targetRef
type: object
x-kubernetes-validations:
- message: spec.loadBalancing is a required field when spec.routingStrategy
== 'loadbalanced'
rule: '!(self.routingStrategy == ''loadbalanced'' && !has(self.loadBalancing))'
status:
description: DNSPolicyStatus defines the observed state of DNSPolicy
properties:
Expand Down
Loading

0 comments on commit 994148b

Please sign in to comment.