diff --git a/api/v1alpha1/dnspolicy_types.go b/api/v1alpha1/dnspolicy_types.go index a81def9a4..26db6149f 100644 --- a/api/v1alpha1/dnspolicy_types.go +++ b/api/v1alpha1/dnspolicy_types.go @@ -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 = "*" @@ -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" 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'" @@ -69,11 +64,6 @@ 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 @@ -81,33 +71,28 @@ type DNSPolicySpec struct { } 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"` - // 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 @@ -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 @@ -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 @@ -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, }) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index f4d71f01e..51b71361a 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -68,26 +68,6 @@ func (in *CertificateSpec) DeepCopy() *CertificateSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CustomWeight) DeepCopyInto(out *CustomWeight) { - *out = *in - if in.Selector != nil { - in, out := &in.Selector, &out.Selector - *out = new(v1.LabelSelector) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomWeight. -func (in *CustomWeight) DeepCopy() *CustomWeight { - if in == nil { - return nil - } - out := new(CustomWeight) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DNSPolicy) DeepCopyInto(out *DNSPolicy) { *out = *in @@ -159,7 +139,7 @@ func (in *DNSPolicySpec) DeepCopyInto(out *DNSPolicySpec) { if in.LoadBalancing != nil { in, out := &in.LoadBalancing, &out.LoadBalancing *out = new(LoadBalancingSpec) - (*in).DeepCopyInto(*out) + **out = **in } if in.ProviderRefs != nil { in, out := &in.ProviderRefs, &out.ProviderRefs @@ -223,26 +203,9 @@ func (in *DNSPolicyStatus) DeepCopy() *DNSPolicyStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancingGeo) DeepCopyInto(out *LoadBalancingGeo) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancingGeo. -func (in *LoadBalancingGeo) DeepCopy() *LoadBalancingGeo { - if in == nil { - return nil - } - out := new(LoadBalancingGeo) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LoadBalancingSpec) DeepCopyInto(out *LoadBalancingSpec) { *out = *in - in.Weighted.DeepCopyInto(&out.Weighted) - out.Geo = in.Geo } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancingSpec. @@ -255,32 +218,6 @@ func (in *LoadBalancingSpec) DeepCopy() *LoadBalancingSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancingWeighted) DeepCopyInto(out *LoadBalancingWeighted) { - *out = *in - if in.Custom != nil { - in, out := &in.Custom, &out.Custom - *out = make([]*CustomWeight, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(CustomWeight) - (*in).DeepCopyInto(*out) - } - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancingWeighted. -func (in *LoadBalancingWeighted) DeepCopy() *LoadBalancingWeighted { - if in == nil { - return nil - } - out := new(LoadBalancingWeighted) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TLSPolicy) DeepCopyInto(out *TLSPolicy) { *out = *in diff --git a/bundle/manifests/kuadrant-operator.clusterserviceversion.yaml b/bundle/manifests/kuadrant-operator.clusterserviceversion.yaml index d3f881a65..954a86b16 100644 --- a/bundle/manifests/kuadrant-operator.clusterserviceversion.yaml +++ b/bundle/manifests/kuadrant-operator.clusterserviceversion.yaml @@ -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 diff --git a/bundle/manifests/kuadrant.io_dnspolicies.yaml b/bundle/manifests/kuadrant.io_dnspolicies.yaml index 20043f024..3a2ddd777 100644 --- a/bundle/manifests/kuadrant.io_dnspolicies.yaml +++ b/bundle/manifests/kuadrant.io_dnspolicies.yaml @@ -102,104 +102,41 @@ 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: + default: 120 + 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. @@ -215,15 +152,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: @@ -255,13 +183,12 @@ 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))' + - message: loadBalancing is immutable + rule: (!has(oldSelf.loadBalancing) || has(self.loadBalancing)) && (has(oldSelf.loadBalancing) + || !has(self.loadBalancing)) status: description: DNSPolicyStatus defines the observed state of DNSPolicy properties: diff --git a/charts/kuadrant-operator/templates/manifests.yaml b/charts/kuadrant-operator/templates/manifests.yaml index 8050f13e3..148862d8f 100644 --- a/charts/kuadrant-operator/templates/manifests.yaml +++ b/charts/kuadrant-operator/templates/manifests.yaml @@ -605,10 +605,15 @@ spec: to the OAuth2 server. properties: name: + default: "" description: |- Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. TODO: Add other useful fields. apiVersion, kind, uid? + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896. type: string type: object x-kubernetes-map-type: atomic @@ -3096,10 +3101,15 @@ spec: to the resource registration API of the UMA server. properties: name: + default: "" description: |- Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. TODO: Add other useful fields. apiVersion, kind, uid? + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896. type: string type: object x-kubernetes-map-type: atomic @@ -4911,10 +4921,15 @@ spec: to the OAuth2 server. properties: name: + default: "" description: |- Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. TODO: Add other useful fields. apiVersion, kind, uid? + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896. type: string type: object x-kubernetes-map-type: atomic @@ -7402,10 +7417,15 @@ spec: to the resource registration API of the UMA server. properties: name: + default: "" description: |- Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. TODO: Add other useful fields. apiVersion, kind, uid? + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896. type: string type: object x-kubernetes-map-type: atomic @@ -9208,10 +9228,15 @@ spec: the OAuth2 server. properties: name: + default: "" description: |- Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. TODO: Add other useful fields. apiVersion, kind, uid? + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896. type: string type: object x-kubernetes-map-type: atomic @@ -11687,10 +11712,15 @@ spec: the resource registration API of the UMA server. properties: name: + default: "" description: |- Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. TODO: Add other useful fields. apiVersion, kind, uid? + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896. type: string type: object x-kubernetes-map-type: atomic @@ -13280,104 +13310,41 @@ 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: + default: 120 + 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. @@ -13393,15 +13360,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: @@ -13433,13 +13391,12 @@ 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))' + - message: loadBalancing is immutable + rule: (!has(oldSelf.loadBalancing) || has(self.loadBalancing)) && (has(oldSelf.loadBalancing) + || !has(self.loadBalancing)) status: description: DNSPolicyStatus defines the observed state of DNSPolicy properties: @@ -15834,6 +15791,13 @@ rules: - patch - update - watch +- apiGroups: + - gateway.networking.k8s.io + resources: + - gatewayclasses + verbs: + - list + - watch - apiGroups: - gateway.networking.k8s.io resources: @@ -16194,6 +16158,10 @@ spec: env: - name: RELATED_IMAGE_WASMSHIM value: oci://quay.io/kuadrant/wasm-shim:latest + - name: OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace image: quay.io/kuadrant/kuadrant-operator:latest livenessProbe: httpGet: diff --git a/config/crd/bases/kuadrant.io_dnspolicies.yaml b/config/crd/bases/kuadrant.io_dnspolicies.yaml index a5c25973e..32aaf6407 100644 --- a/config/crd/bases/kuadrant.io_dnspolicies.yaml +++ b/config/crd/bases/kuadrant.io_dnspolicies.yaml @@ -101,104 +101,41 @@ 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: + default: 120 + 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. @@ -214,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: @@ -254,13 +182,12 @@ 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))' + - message: loadBalancing is immutable + rule: (!has(oldSelf.loadBalancing) || has(self.loadBalancing)) && (has(oldSelf.loadBalancing) + || !has(self.loadBalancing)) status: description: DNSPolicyStatus defines the observed state of DNSPolicy properties: diff --git a/controllers/dns_helper.go b/controllers/dns_helper.go index 4a754dd82..ad9a63c12 100644 --- a/controllers/dns_helper.go +++ b/controllers/dns_helper.go @@ -27,10 +27,6 @@ const ( DefaultCnameTTL = 300 ) -var ( - ErrUnknownRoutingStrategy = fmt.Errorf("unknown routing strategy") -) - type dnsHelper struct { client.Client } @@ -60,7 +56,7 @@ func gatewayDNSRecordLabels(gwKey client.ObjectKey) map[string]string { } } -func (dh *dnsHelper) setEndpoints(mcgTarget *multicluster.GatewayTarget, dnsRecord *kuadrantdnsv1alpha1.DNSRecord, listener gatewayapiv1.Listener, strategy v1alpha1.RoutingStrategy) error { +func (dh *dnsHelper) setEndpoints(mcgTarget *multicluster.GatewayTarget, dnsRecord *kuadrantdnsv1alpha1.DNSRecord, listener gatewayapiv1.Listener, loadBalancing *v1alpha1.LoadBalancingSpec) { gwListenerHost := string(*listener.Hostname) var endpoints []*externaldns.Endpoint @@ -70,13 +66,10 @@ func (dh *dnsHelper) setEndpoints(mcgTarget *multicluster.GatewayTarget, dnsReco currentEndpoints[getSetID(endpoint)] = endpoint } - switch strategy { - case v1alpha1.SimpleRoutingStrategy: + if loadBalancing == nil { endpoints = dh.getSimpleEndpoints(mcgTarget, gwListenerHost, currentEndpoints) - case v1alpha1.LoadBalancedRoutingStrategy: + } else { endpoints = dh.getLoadBalancedEndpoints(mcgTarget, gwListenerHost, currentEndpoints) - default: - return fmt.Errorf("%w : %s", ErrUnknownRoutingStrategy, strategy) } sort.Slice(endpoints, func(i, j int) bool { @@ -84,8 +77,6 @@ func (dh *dnsHelper) setEndpoints(mcgTarget *multicluster.GatewayTarget, dnsReco }) dnsRecord.Spec.Endpoints = endpoints - - return nil } // getSimpleEndpoints returns the endpoints for the given GatewayTarget using the simple routing strategy @@ -207,8 +198,8 @@ func (dh *dnsHelper) getLoadBalancedEndpoints(mcgTarget *multicluster.GatewayTar endpoint.SetProviderSpecificProperty(kuadrantdnsv1alpha1.ProviderSpecificGeoCode, string(geoCode)) endpoints = append(endpoints, endpoint) - //Add a default geo (*) endpoint if the current geoCode is equal to the defaultGeo set in the policy spec - if geoCode == mcgTarget.GetDefaultGeo() { + //Add a default geo (*) endpoint if the current target is the default geo + if mcgTarget.IsDefaultGeo() { endpoint = createOrUpdateEndpoint(lbName, []string{geoLbName}, kuadrantdnsv1alpha1.CNAMERecordType, "default", DefaultCnameTTL, currentEndpoints) endpoint.SetProviderSpecificProperty(kuadrantdnsv1alpha1.ProviderSpecificGeoCode, string(v1alpha1.WildcardGeo)) endpoints = append(endpoints, endpoint) diff --git a/controllers/dnspolicy_dnsrecords.go b/controllers/dnspolicy_dnsrecords.go index 998568879..4b5193c76 100644 --- a/controllers/dnspolicy_dnsrecords.go +++ b/controllers/dnspolicy_dnsrecords.go @@ -141,9 +141,7 @@ func (r *DNSPolicyReconciler) desiredDNSRecord(gateway *multicluster.GatewayWrap return nil, fmt.Errorf("failed to create multi cluster gateway target for listener %s : %w", targetListener.Name, err) } - if err = r.dnsHelper.setEndpoints(mcgTarget, dnsRecord, targetListener, dnsPolicy.Spec.RoutingStrategy); err != nil { - return nil, fmt.Errorf("failed to add dns record dnsTargets %w %v", err, mcgTarget) - } + r.dnsHelper.setEndpoints(mcgTarget, dnsRecord, targetListener, dnsPolicy.Spec.LoadBalancing) return dnsRecord, nil } diff --git a/doc/dns.md b/doc/dns.md index 1b33a60e3..d784cb524 100644 --- a/doc/dns.md +++ b/doc/dns.md @@ -16,7 +16,6 @@ The needed dns names are gathered from the listener definitions and the IPAdress The `DNSPolicy` spec includes the following parts: * A reference to an existing Gateway API resource (`spec.targetRef`) -* DNS Routing Strategy (`spec.routingStrategy`) * LoadBalancing specification (`spec.loadBalancing`) * HealthCheck specification (`spec.healthCheck`) @@ -41,33 +40,15 @@ spec: providerRefs: - name: my-aws-credentials - # (optional) routing strategy to use when creating DNS records, defaults to `loadbalanced` - # determines what DNS records are created in the DNS provider - # check out Kuadrant RFC 0005 https://github.com/Kuadrant/architecture/blob/main/rfcs/0005-single-cluster-dnspolicy.md to learn more about the Routing Strategy field - # One-of: simple, loadbalanced. - routingStrategy: loadbalanced - # (optional) loadbalancing specification - # use it for providing the specification of how dns will be configured in order to provide balancing of load across multiple clusters when using the `loadbalanced` routing strategy - # Primary use of this is for multi cluster deployments - # check out Kuadrant RFC 0003 https://github.com/Kuadrant/architecture/blob/main/rfcs/0003-dns-policy.md to learn more about the options that can be used in this field + # use it for providing the specification of how dns will be configured in order to provide balancing of load across multiple clusters loadBalancing: - # (optional) weighted specification - # use it to control the weight value applied to records - weighted: - # use it to change the weight of a record based on labels applied to the target meta resource i.e. Gateway in a single cluster context or ManagedCluster in multi cluster with OCM - custom: - - weight: 200 - selector: - matchLabels: - kuadrant.io/lb-attribute-custom-weight: AWS - # (optional) weight value that will be applied to weighted dns records by default. Integer greater than 0 and no larger than the maximum value accepted by the target dns provider, defaults to `120` - defaultWeight: 100 - # (optional) geo specification - # use it to control the geo value applied to records - geo: - # (optional) default geo to be applied to records - defaultGeo: IE + # default geo to be applied to records + defaultGeo: true + # weighted specification + weight: 100 + # + geo: IE # (optional) health check specification # health check probes with the following specification will be created for each DNS target diff --git a/doc/dnshealthchecks.md b/doc/dnshealthchecks.md index 971a20227..48141c461 100644 --- a/doc/dnshealthchecks.md +++ b/doc/dnshealthchecks.md @@ -25,7 +25,6 @@ spec: name: prod-web group: gateway.networking.k8s.io kind: Gateway - loadBalancing: simple healthCheck: endpoint: "/health" port: 443 diff --git a/doc/reference/dnspolicy.md b/doc/reference/dnspolicy.md index 87902b856..742077023 100644 --- a/doc/reference/dnspolicy.md +++ b/doc/reference/dnspolicy.md @@ -20,13 +20,12 @@ ## DNSPolicySpec -| **Field** | **Type** | **Required** | **Description** | -|-------------------|-----------------------------------------------------------------------------------------------------------------------------------|:----------------------:|---------------------------------------------------------------------------| -| `targetRef` | [Gateway API LocalPolicyTargetReference](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1alpha2.LocalPolicyTargetReference) | Yes | Reference to a Kubernetes resource that the policy attaches to | -| `healthCheck` | [HealthCheckSpec](#healthcheckspec) | No | HealthCheck spec | -| `loadBalancing` | [LoadBalancingSpec](#loadbalancingspec) | Yes(loadbalanced only) | LoadBalancing Spec, required when routingStrategy is "loadbalanced" | -| `routingStrategy` | String (immutable) | Yes | **Immutable!** Routing Strategy to use, one of "simple" or "loadbalanced" | -| `providerRefs` | [ProviderRefs](#providerrefs) | Yes | array of references to providers. (currently limited to max 1) | +| **Field** | **Type** | **Required** | **Description** | +|------------------|-----------------------------------------------------------------------------------------------------------------------------------|:---------------------:|------------------------------------------------------------| +| `targetRef` | [Gateway API LocalPolicyTargetReference](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1alpha2.LocalPolicyTargetReference) | Yes | Reference to a Kubernetes resource that the policy attaches to | +| `healthCheck` | [HealthCheckSpec](#healthcheckspec) | No | HealthCheck spec | +| `loadBalancing` | [LoadBalancingSpec](#loadbalancingspec) | No | LoadBalancing Spec | +| `providerRefs` | [ProviderRefs](#providerrefs) | Yes | array of references to providers. (currently limited to max 1) | ## ProviderRefs @@ -52,30 +51,11 @@ ## LoadBalancingSpec -| **Field** | **Type** | **Required** | **Description** | -|------------|-------------------------------------------------|:-------------:|-------------------------| -| `weighted` | [LoadBalancingWeighted](#loadbalancingweighted) | Yes | Weighted routing spec | -| `geo` | [LoadBalancingGeo](#loadbalancinggeo) | Yes | Geo routing spec | - -## LoadBalancingWeighted - -| **Field** | **Type** | **Required** | **Description** | -|-----------------|---------------------------------|:------------:|-----------------------------------------------------------------------| -| `defaultWeight` | Number | Yes | Default weight to apply to created records | -| `custom` | [][CustomWeight](#customweight) | No | Custom weights to manipulate records weights based on label selectors | - -## CustomWeight - -| **Field** | **Type** | **Description** | -|------------|----------------------|--------------------------------------------------------------------------| -| `selector` | metav1.LabelSelector | Label Selector to specify resources that should have this weight applied | -| `weight` | Number | Weight value to apply for matching resources | - -## LoadBalancingGeo - -| **Field** | **Type** | **Required** | **Description** | -|-----------------|---------------------------------|:------------:|---------------------------------| -| `defaultGeo` | String | Yes | Default geo to apply to records | +| **Field** | **Type** | **Required** | **Description** | +|--------------|----------|:------------:|----------------------------------------------------------| +| `defaultGeo` | Boolean | Yes | Specifies if this is the default geo | +| `geo` | String | Yes | Geo value to apply to geo endpoints | +| `weight` | Number | No | Weight value to apply to weighted endpoints default: 120 | ## DNSPolicyStatus diff --git a/doc/user-guides/gateway-dns.md b/doc/user-guides/gateway-dns.md index 211366a4f..c4f592595 100644 --- a/doc/user-guides/gateway-dns.md +++ b/doc/user-guides/gateway-dns.md @@ -98,7 +98,6 @@ spec: name: prod-web group: gateway.networking.k8s.io kind: Gateway - routingStrategy: simple EOF ``` diff --git a/doc/user-guides/secure-protect-connect-single-multi-cluster.md b/doc/user-guides/secure-protect-connect-single-multi-cluster.md index c5118535f..8cc7b24c3 100644 --- a/doc/user-guides/secure-protect-connect-single-multi-cluster.md +++ b/doc/user-guides/secure-protect-connect-single-multi-cluster.md @@ -273,12 +273,10 @@ metadata: name: ${gatewayName}-dnspolicy namespace: ${gatewayNS} spec: - routingStrategy: loadbalanced loadBalancing: - geo: - defaultGeo: US - weighted: - defaultWeight: 120 + defaultGeo: true + geo: US + weight: 120 targetRef: name: ${gatewayName} group: gateway.networking.k8s.io diff --git a/doc/user-guides/secure-protect-connect.md b/doc/user-guides/secure-protect-connect.md index 9cad1f773..a96b0e280 100644 --- a/doc/user-guides/secure-protect-connect.md +++ b/doc/user-guides/secure-protect-connect.md @@ -292,7 +292,6 @@ metadata: name: simple-dnspolicy namespace: kuadrant-system spec: - routingStrategy: simple targetRef: name: api-gateway group: gateway.networking.k8s.io diff --git a/examples/dnspolicy/dnspolicy-bad-strategy.yaml b/examples/dnspolicy/dnspolicy-bad-strategy.yaml index 33e4606cc..345b4c7ee 100644 --- a/examples/dnspolicy/dnspolicy-bad-strategy.yaml +++ b/examples/dnspolicy/dnspolicy-bad-strategy.yaml @@ -10,4 +10,3 @@ spec: kind: Gateway providerRefs: - name: aws-credentials - routingStrategy: simple diff --git a/examples/dnspolicy/dnspolicy-healthchecks.yaml b/examples/dnspolicy/dnspolicy-healthchecks.yaml index 2682fb6ea..21f05bb95 100644 --- a/examples/dnspolicy/dnspolicy-healthchecks.yaml +++ b/examples/dnspolicy/dnspolicy-healthchecks.yaml @@ -10,12 +10,10 @@ spec: kind: Gateway providerRefs: - name: aws-credentials - routingStrategy: loadbalanced loadBalancing: - weighted: - defaultWeight: 120 - geo: - defaultGeo: EU + weight: 120 + geo: EU + defaultGeo: true healthCheck: endpoint: /healthz port: 1111111 diff --git a/examples/dnspolicy/dnspolicy.yaml b/examples/dnspolicy/dnspolicy.yaml index 8d8194385..47d8408bf 100644 --- a/examples/dnspolicy/dnspolicy.yaml +++ b/examples/dnspolicy/dnspolicy.yaml @@ -10,9 +10,7 @@ spec: kind: Gateway providerRefs: - name: aws-credentials - routingStrategy: loadbalanced loadBalancing: - weighted: - defaultWeight: 120 - geo: - defaultGeo: EU + weight: 120 + geo: EU + defaultGeo: true diff --git a/pkg/multicluster/target.go b/pkg/multicluster/target.go index 3de3f858b..6496fc1eb 100644 --- a/pkg/multicluster/target.go +++ b/pkg/multicluster/target.go @@ -3,8 +3,6 @@ package multicluster import ( "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" "github.com/kuadrant/kuadrant-operator/api/v1alpha1" @@ -12,10 +10,6 @@ import ( "github.com/kuadrant/kuadrant-operator/pkg/library/utils" ) -const ( - LabelLBAttributeGeoCode = "kuadrant.io/lb-attribute-geo-code" -) - // GatewayTarget represents a Gateway that is placed on multiple clusters (ClusterGateway). type GatewayTarget struct { Gateway *gatewayapiv1.Gateway @@ -46,28 +40,31 @@ func (t *GatewayTarget) GroupTargetsByGeo() map[v1alpha1.GeoCode][]ClusterGatewa return geoTargets } -func (t *GatewayTarget) GetDefaultGeo() v1alpha1.GeoCode { +func (t *GatewayTarget) GetGeo() v1alpha1.GeoCode { if t.LoadBalancing != nil { - return v1alpha1.GeoCode(t.LoadBalancing.Geo.DefaultGeo) + return v1alpha1.GeoCode(t.LoadBalancing.Geo) } return v1alpha1.DefaultGeo } -func (t *GatewayTarget) GetDefaultWeight() int { +func (t *GatewayTarget) IsDefaultGeo() bool { + if t.LoadBalancing != nil { + return t.LoadBalancing.DefaultGeo + } + return false +} + +func (t *GatewayTarget) GetWeight() int { if t.LoadBalancing != nil { - return int(t.LoadBalancing.Weighted.DefaultWeight) + return t.LoadBalancing.Weight } - return int(v1alpha1.DefaultWeight) + return v1alpha1.DefaultWeight } func (t *GatewayTarget) setClusterGatewayTargets(clusterGateways []ClusterGateway) error { cgTargets := []ClusterGatewayTarget{} for _, cg := range clusterGateways { - var customWeights []*v1alpha1.CustomWeight - if t.LoadBalancing != nil { - customWeights = t.LoadBalancing.Weighted.Custom - } - cgt, err := NewClusterGatewayTarget(cg, t.GetDefaultGeo(), t.GetDefaultWeight(), customWeights) + cgt, err := NewClusterGatewayTarget(cg, t.GetGeo(), t.GetWeight()) if err != nil { return err } @@ -80,28 +77,25 @@ func (t *GatewayTarget) setClusterGatewayTargets(clusterGateways []ClusterGatewa // ClusterGatewayTarget represents a cluster Gateway with geo and weighting info calculated type ClusterGatewayTarget struct { *ClusterGateway - Geo *v1alpha1.GeoCode - Weight *int + Geo v1alpha1.GeoCode + Weight int } -func NewClusterGatewayTarget(cg ClusterGateway, defaultGeoCode v1alpha1.GeoCode, defaultWeight int, customWeights []*v1alpha1.CustomWeight) (ClusterGatewayTarget, error) { +func NewClusterGatewayTarget(cg ClusterGateway, geoCode v1alpha1.GeoCode, weight int) (ClusterGatewayTarget, error) { target := ClusterGatewayTarget{ ClusterGateway: &cg, - } - target.setGeo(defaultGeoCode) - err := target.setWeight(defaultWeight, customWeights) - if err != nil { - return ClusterGatewayTarget{}, err + Geo: geoCode, + Weight: weight, } return target, nil } func (t *ClusterGatewayTarget) GetGeo() v1alpha1.GeoCode { - return *t.Geo + return t.Geo } func (t *ClusterGatewayTarget) GetWeight() int { - return *t.Weight + return t.Weight } func (t *ClusterGatewayTarget) GetName() string { @@ -111,33 +105,3 @@ func (t *ClusterGatewayTarget) GetName() string { func (t *ClusterGatewayTarget) GetShortCode() string { return common.ToBase36HashLen(t.GetName(), utils.ClusterIDLength) } - -func (t *ClusterGatewayTarget) setGeo(defaultGeo v1alpha1.GeoCode) { - geoCode := defaultGeo - if geoCode == v1alpha1.DefaultGeo { - t.Geo = &geoCode - return - } - if gc, ok := t.GetLabels()[LabelLBAttributeGeoCode]; ok { - geoCode = v1alpha1.GeoCode(gc) - } - t.Geo = &geoCode -} - -func (t *ClusterGatewayTarget) setWeight(defaultWeight int, customWeights []*v1alpha1.CustomWeight) error { - weight := defaultWeight - for k := range customWeights { - cw := customWeights[k] - selector, err := metav1.LabelSelectorAsSelector(cw.Selector) - if err != nil { - return err - } - if selector.Matches(labels.Set(t.GetLabels())) { - customWeight := int(cw.Weight) - weight = customWeight - break - } - } - t.Weight = &weight - return nil -} diff --git a/tests/common/dnspolicy/dnspolicy_controller_multi_cluster_test.go b/tests/common/dnspolicy/dnspolicy_controller_multi_cluster_test.go deleted file mode 100644 index 0ec7b8f67..000000000 --- a/tests/common/dnspolicy/dnspolicy_controller_multi_cluster_test.go +++ /dev/null @@ -1,714 +0,0 @@ -//go:build integration - -package dnspolicy - -import ( - "context" - "fmt" - "time" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gstruct" - "k8s.io/apimachinery/pkg/util/rand" - externaldns "sigs.k8s.io/external-dns/endpoint" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" - "sigs.k8s.io/controller-runtime/pkg/client" - gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - - kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1" - - "github.com/kuadrant/kuadrant-operator/api/v1alpha1" - "github.com/kuadrant/kuadrant-operator/pkg/common" - "github.com/kuadrant/kuadrant-operator/pkg/library/utils" - "github.com/kuadrant/kuadrant-operator/pkg/multicluster" - "github.com/kuadrant/kuadrant-operator/tests" -) - -var _ = Describe("DNSPolicy Multi Cluster", func() { - const ( - testTimeOut = SpecTimeout(1 * time.Minute) - afterEachTimeOut = NodeTimeout(2 * time.Minute) - ) - - var gatewayClass *gatewayapiv1.GatewayClass - var dnsProviderSecret *corev1.Secret - var testNamespace string - var gateway *gatewayapiv1.Gateway - var dnsPolicy *v1alpha1.DNSPolicy - var recordName, wildcardRecordName, clusterTwoIDHash, clusterOneIDHash, gwHash string - var domain = fmt.Sprintf("example-%s.com", rand.String(6)) - - BeforeEach(func(ctx SpecContext) { - testNamespace = tests.CreateNamespace(ctx, testClient()) - - var err error - Expect(err).To(BeNil()) - - gatewayClass = tests.BuildGatewayClass("gwc-"+testNamespace, "default", "kuadrant.io/bar") - Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed()) - - dnsProviderSecret = tests.BuildInMemoryCredentialsSecret("inmemory-credentials", testNamespace, domain) - Expect(k8sClient.Create(ctx, dnsProviderSecret)).To(Succeed()) - - gateway = tests.NewGatewayBuilder(tests.GatewayName, gatewayClass.Name, testNamespace). - WithHTTPListener(tests.ListenerNameOne, tests.HostOne(domain)). - WithHTTPListener(tests.ListenerNameWildcard, tests.HostWildcard(domain)). - Gateway - Expect(k8sClient.Create(ctx, gateway)).To(Succeed()) - - clusterOneIDHash = common.ToBase36HashLen(tests.ClusterNameOne, utils.ClusterIDLength) - clusterTwoIDHash = common.ToBase36HashLen(tests.ClusterNameTwo, utils.ClusterIDLength) - - gwHash = common.ToBase36HashLen(gateway.Name+"-"+gateway.Namespace, 6) - - //Set multi cluster gateway status - Eventually(func(g Gomega) { - g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), gateway)).To(Succeed()) - gateway.Status.Addresses = []gatewayapiv1.GatewayStatusAddress{ - { - Type: ptr.To(multicluster.MultiClusterIPAddressType), - Value: tests.ClusterNameOne + "/" + tests.IPAddressOne, - }, - { - Type: ptr.To(multicluster.MultiClusterIPAddressType), - Value: tests.ClusterNameTwo + "/" + tests.IPAddressTwo, - }, - } - gateway.Status.Listeners = []gatewayapiv1.ListenerStatus{ - { - Name: tests.ClusterNameOne + "." + tests.ListenerNameOne, - SupportedKinds: []gatewayapiv1.RouteGroupKind{}, - AttachedRoutes: 1, - Conditions: []metav1.Condition{}, - }, - { - Name: tests.ClusterNameTwo + "." + tests.ListenerNameOne, - SupportedKinds: []gatewayapiv1.RouteGroupKind{}, - AttachedRoutes: 1, - Conditions: []metav1.Condition{}, - }, - { - Name: tests.ClusterNameOne + "." + tests.ListenerNameWildcard, - SupportedKinds: []gatewayapiv1.RouteGroupKind{}, - AttachedRoutes: 1, - Conditions: []metav1.Condition{}, - }, - { - Name: tests.ClusterNameTwo + "." + tests.ListenerNameWildcard, - SupportedKinds: []gatewayapiv1.RouteGroupKind{}, - AttachedRoutes: 1, - Conditions: []metav1.Condition{}, - }, - } - g.Expect(k8sClient.Status().Update(ctx, gateway)).To(Succeed()) - }, tests.TimeoutMedium, tests.RetryIntervalMedium).ShouldNot(HaveOccurred()) - - recordName = fmt.Sprintf("%s-%s", tests.GatewayName, tests.ListenerNameOne) - wildcardRecordName = fmt.Sprintf("%s-%s", tests.GatewayName, tests.ListenerNameWildcard) - }) - - AfterEach(func(ctx SpecContext) { - if gateway != nil { - err := k8sClient.Delete(ctx, gateway) - Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - } - if dnsPolicy != nil { - err := k8sClient.Delete(ctx, dnsPolicy) - Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - // Wait until dns records are finished deleting since it can't finish deleting without the DNS provider secret - Eventually(func(g Gomega) { - dnsRecords := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, dnsRecords, client.InNamespace(testNamespace)) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(dnsRecords.Items).To(HaveLen(0)) - }).WithContext(ctx).Should(Succeed()) - } - if dnsProviderSecret != nil { - err := k8sClient.Delete(ctx, dnsProviderSecret) - Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - } - if gatewayClass != nil { - err := k8sClient.Delete(ctx, gatewayClass) - Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - } - tests.DeleteNamespace(ctx, testClient(), testNamespace) - }, afterEachTimeOut) - - Context("simple routing strategy", func() { - - BeforeEach(func(ctx SpecContext) { - dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) - Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - }) - - It("should create dns records", func(ctx SpecContext) { - Eventually(func(g Gomega, ctx context.Context) { - recordList := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(recordList.Items).To(HaveLen(2)) - - dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - g.Expect(dnsRecord.Name).To(Equal(recordName)) - g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostOne(domain)), - "Targets": ContainElements(tests.IPAddressOne, tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - )) - g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - - g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) - g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostWildcard(domain)), - "Targets": ContainElements(tests.IPAddressOne, tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - )) - g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) - }, testTimeOut) - - }) - - Context("loadbalanced routing strategy", func() { - - Context("geo+weighted with matching default geo", func() { - - BeforeEach(func(ctx SpecContext) { - dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(120, nil, "IE") - Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - }) - - It("should create dns records", func(ctx SpecContext) { - Eventually(func(g Gomega, ctx context.Context) { - recordList := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(recordList.Items).To(HaveLen(2)) - - dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - g.Expect(dnsRecord.Name).To(Equal(recordName)) - g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressOne), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb.test." + domain), - "Targets": ConsistOf(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb.test." + domain), - "Targets": ConsistOf(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("default"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostOne(domain)), - "Targets": ConsistOf("klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - )) - g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - - g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) - g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "Targets": ConsistOf(tests.IPAddressOne), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb." + domain), - "Targets": ConsistOf(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb." + domain), - "Targets": ConsistOf(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "Targets": ConsistOf(tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("default"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostWildcard(domain)), - "Targets": ConsistOf("klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - )) - g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) - }, testTimeOut) - }) - - Context("geo+weighted with custom weights", func() { - - BeforeEach(func(ctx SpecContext) { - - dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(120, []*v1alpha1.CustomWeight{ - { - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "kuadrant.io/my-custom-weight-attr": "FOO", - }, - }, - Weight: 100, - }, - { - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "kuadrant.io/my-custom-weight-attr": "BAR", - }, - }, - Weight: 160, - }, - }, "IE") - Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - - Eventually(func() error { - gateway.Labels = map[string]string{} - gateway.Labels["clusters.kuadrant.io/"+tests.ClusterNameOne+"_my-custom-weight-attr"] = "FOO" - gateway.Labels["clusters.kuadrant.io/"+tests.ClusterNameTwo+"_my-custom-weight-attr"] = "BAR" - gateway.Labels["clusters.kuadrant.io/"+tests.ClusterNameOne+"_lb-attribute-geo-code"] = "IE" - gateway.Labels["clusters.kuadrant.io/"+tests.ClusterNameTwo+"_lb-attribute-geo-code"] = "ES" - return k8sClient.Update(ctx, gateway) - }, tests.TimeoutMedium, tests.RetryIntervalMedium).ShouldNot(HaveOccurred()) - - Expect(gateway.Labels).To(HaveKeyWithValue("clusters.kuadrant.io/test-placed-control_my-custom-weight-attr", "FOO")) - Expect(gateway.Labels).To(HaveKeyWithValue("clusters.kuadrant.io/test-placed-control_lb-attribute-geo-code", "IE")) - Expect(gateway.Labels).To(HaveKeyWithValue("clusters.kuadrant.io/test-placed-workload-1_my-custom-weight-attr", "BAR")) - Expect(gateway.Labels).To(HaveKeyWithValue("clusters.kuadrant.io/test-placed-workload-1_lb-attribute-geo-code", "ES")) - }) - - It("should create dns records", func(ctx SpecContext) { - Eventually(func(g Gomega, ctx context.Context) { - recordList := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(recordList.Items).To(HaveLen(2)) - - dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - g.Expect(dnsRecord.Name).To(Equal(recordName)) - g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("es.klb.test." + domain), - "Targets": ConsistOf(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "160"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb.test." + domain), - "Targets": ConsistOf(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "100"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressOne), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("es.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("ES"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "ES"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("default"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostOne(domain)), - "Targets": ConsistOf("klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - )) - g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - - g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) - g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "Targets": ConsistOf(tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("es.klb." + domain), - "Targets": ConsistOf(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "160"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb." + domain), - "Targets": ConsistOf(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "100"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "Targets": ConsistOf(tests.IPAddressOne), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("es.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("ES"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "ES"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("default"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostWildcard(domain)), - "Targets": ConsistOf("klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - )) - g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) - }, testTimeOut) - - }) - - Context("geo+weighted with no matching default geo", func() { - - BeforeEach(func(ctx SpecContext) { - dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(120, nil, "cat") - Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - - Eventually(func() error { - gateway.Labels = map[string]string{} - gateway.Labels["clusters.kuadrant.io/"+tests.ClusterNameOne+"_lb-attribute-geo-code"] = "IE" - gateway.Labels["clusters.kuadrant.io/"+tests.ClusterNameTwo+"_lb-attribute-geo-code"] = "ES" - return k8sClient.Update(ctx, gateway) - }, tests.TimeoutMedium, tests.RetryIntervalMedium).ShouldNot(HaveOccurred()) - - Expect(gateway.Labels).To(HaveKeyWithValue("clusters.kuadrant.io/test-placed-control_lb-attribute-geo-code", "IE")) - Expect(gateway.Labels).To(HaveKeyWithValue("clusters.kuadrant.io/test-placed-workload-1_lb-attribute-geo-code", "ES")) - }) - - It("should create dns records", func(ctx SpecContext) { - Eventually(func(g Gomega, ctx context.Context) { - recordList := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(recordList.Items).To(HaveLen(2)) - - dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - g.Expect(dnsRecord.Name).To(Equal(recordName)) - g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressOne), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb.test." + domain), - "Targets": ConsistOf(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterOneIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("es.klb.test." + domain), - "Targets": ConsistOf(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterTwoIDHash + "-" + gwHash + ".klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostOne(domain)), - "Targets": ConsistOf("klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("es.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("ES"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "ES"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - )) - g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - - g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) - g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "Targets": ConsistOf(tests.IPAddressOne), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb." + domain), - "Targets": ConsistOf(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterOneIDHash + "-" + gwHash + ".klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("es.klb." + domain), - "Targets": ConsistOf(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterTwoIDHash + "-" + gwHash + ".klb." + domain), - "Targets": ConsistOf(tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostWildcard(domain)), - "Targets": ConsistOf("klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("es.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("ES"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "ES"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - )) - g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) - }, testTimeOut) - }) - }) -}) diff --git a/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go b/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go index dc37fa163..9f3d8717c 100644 --- a/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go +++ b/tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go @@ -140,8 +140,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() { BeforeEach(func(ctx SpecContext) { dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway(tests.GatewayName) Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) }) @@ -196,123 +195,228 @@ var _ = Describe("DNSPolicy Single Cluster", func() { Context("loadbalanced routing strategy", func() { - BeforeEach(func(ctx SpecContext) { - dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(120, nil, "IE") - Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - }) - - It("should create dns records", func(ctx SpecContext) { - Eventually(func(g Gomega, ctx context.Context) { - recordList := &kuadrantdnsv1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(recordList.Items).To(HaveLen(2)) - - dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) - g.Expect(err).NotTo(HaveOccurred()) - - wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} - err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) - g.Expect(err).NotTo(HaveOccurred()) + Context("with default geo", func() { + BeforeEach(func(ctx SpecContext) { + dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). + WithProviderSecret(*dnsProviderSecret). + WithTargetGateway(tests.GatewayName). + WithLoadBalancingFor(120, "IE", true) + Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) + }) + + It("should create dns records", func(ctx SpecContext) { + Eventually(func(g Gomega, ctx context.Context) { + recordList := &kuadrantdnsv1alpha1.DNSRecordList{} + err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(recordList.Items).To(HaveLen(2)) + + dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} + err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) + g.Expect(err).NotTo(HaveOccurred()) + + wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} + err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) + g.Expect(err).NotTo(HaveOccurred()) + + g.Expect(dnsRecord.Name).To(Equal(recordName)) + g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) + g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(clusterHash + "-" + gwHash + "." + "klb.test." + domain), + "Targets": ConsistOf(tests.IPAddressOne, tests.IPAddressTwo), + "RecordType": Equal("A"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(60)), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("ie.klb.test." + domain), + "Targets": ConsistOf(clusterHash + "-" + gwHash + "." + "klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(clusterHash + "-" + gwHash + "." + "klb.test." + domain), + "RecordTTL": Equal(externaldns.TTL(60)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("klb.test." + domain), + "Targets": ConsistOf("ie.klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal("IE"), + "RecordTTL": Equal(externaldns.TTL(300)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("klb.test." + domain), + "Targets": ConsistOf("ie.klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal("default"), + "RecordTTL": Equal(externaldns.TTL(300)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(tests.HostOne(domain)), + "Targets": ConsistOf("klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(300)), + })), + )) + g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) + g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) + g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) + + g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) + g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) + g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ContainElements( + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(clusterHash + "-" + gwHash + "." + "klb." + domain), + "Targets": ConsistOf(tests.IPAddressOne, tests.IPAddressTwo), + "RecordType": Equal("A"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(60)), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("ie.klb." + domain), + "Targets": ConsistOf(clusterHash + "-" + gwHash + "." + "klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(clusterHash + "-" + gwHash + "." + "klb." + domain), + "RecordTTL": Equal(externaldns.TTL(60)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("klb." + domain), + "Targets": ConsistOf("ie.klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal("default"), + "RecordTTL": Equal(externaldns.TTL(300)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("klb." + domain), + "Targets": ConsistOf("ie.klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal("IE"), + "RecordTTL": Equal(externaldns.TTL(300)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(tests.HostWildcard(domain)), + "Targets": ConsistOf("klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(300)), + })), + )) + g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) + g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) + g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) + }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) + }, testTimeOut) - g.Expect(dnsRecord.Name).To(Equal(recordName)) - g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterHash + "-" + gwHash + "." + "klb.test." + domain), - "Targets": ConsistOf(tests.IPAddressOne, tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb.test." + domain), - "Targets": ConsistOf(clusterHash + "-" + gwHash + "." + "klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterHash + "-" + gwHash + "." + "klb.test." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb.test." + domain), - "Targets": ConsistOf("ie.klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("default"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostOne(domain)), - "Targets": ConsistOf("klb.test." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - )) - g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) + }) - g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) - g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) - g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ContainElements( - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(clusterHash + "-" + gwHash + "." + "klb." + domain), - "Targets": ConsistOf(tests.IPAddressOne, tests.IPAddressTwo), - "RecordType": Equal("A"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(60)), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("ie.klb." + domain), - "Targets": ConsistOf(clusterHash + "-" + gwHash + "." + "klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(clusterHash + "-" + gwHash + "." + "klb." + domain), - "RecordTTL": Equal(externaldns.TTL(60)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("default"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "*"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal("klb." + domain), - "Targets": ConsistOf("ie.klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal("IE"), - "RecordTTL": Equal(externaldns.TTL(300)), - "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), - })), - PointTo(MatchFields(IgnoreExtras, Fields{ - "DNSName": Equal(tests.HostWildcard(domain)), - "Targets": ConsistOf("klb." + domain), - "RecordType": Equal("CNAME"), - "SetIdentifier": Equal(""), - "RecordTTL": Equal(externaldns.TTL(300)), - })), - )) - g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) - g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) - g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) - }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) - }, testTimeOut) + Context("without default geo", func() { + BeforeEach(func(ctx SpecContext) { + dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). + WithProviderSecret(*dnsProviderSecret). + WithTargetGateway(tests.GatewayName). + WithLoadBalancingFor(120, "IE", false) + Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) + }) + + It("should create dns records", func(ctx SpecContext) { + Eventually(func(g Gomega, ctx context.Context) { + recordList := &kuadrantdnsv1alpha1.DNSRecordList{} + err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace}) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(recordList.Items).To(HaveLen(2)) + + dnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} + err = k8sClient.Get(ctx, client.ObjectKey{Name: recordName, Namespace: testNamespace}, dnsRecord) + g.Expect(err).NotTo(HaveOccurred()) + + wildcardDnsRecord := &kuadrantdnsv1alpha1.DNSRecord{} + err = k8sClient.Get(ctx, client.ObjectKey{Name: wildcardRecordName, Namespace: testNamespace}, wildcardDnsRecord) + g.Expect(err).NotTo(HaveOccurred()) + + g.Expect(dnsRecord.Name).To(Equal(recordName)) + g.Expect(dnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) + g.Expect(dnsRecord.Spec.Endpoints).To(ConsistOf( + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(clusterHash + "-" + gwHash + "." + "klb.test." + domain), + "Targets": ConsistOf(tests.IPAddressOne, tests.IPAddressTwo), + "RecordType": Equal("A"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(60)), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("ie.klb.test." + domain), + "Targets": ConsistOf(clusterHash + "-" + gwHash + "." + "klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(clusterHash + "-" + gwHash + "." + "klb.test." + domain), + "RecordTTL": Equal(externaldns.TTL(60)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("klb.test." + domain), + "Targets": ConsistOf("ie.klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal("IE"), + "RecordTTL": Equal(externaldns.TTL(300)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(tests.HostOne(domain)), + "Targets": ConsistOf("klb.test." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(300)), + })), + )) + g.Expect(dnsRecord.Status.OwnerID).ToNot(BeEmpty()) + g.Expect(dnsRecord.Status.OwnerID).To(Equal(dnsRecord.GetUIDHash())) + g.Expect(tests.EndpointsTraversable(dnsRecord.Spec.Endpoints, tests.HostOne(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) + + g.Expect(wildcardDnsRecord.Name).To(Equal(wildcardRecordName)) + g.Expect(wildcardDnsRecord.Spec.ProviderRef.Name).To(Equal(dnsProviderSecret.Name)) + g.Expect(wildcardDnsRecord.Spec.Endpoints).To(ContainElements( + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(clusterHash + "-" + gwHash + "." + "klb." + domain), + "Targets": ConsistOf(tests.IPAddressOne, tests.IPAddressTwo), + "RecordType": Equal("A"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(60)), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("ie.klb." + domain), + "Targets": ConsistOf(clusterHash + "-" + gwHash + "." + "klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(clusterHash + "-" + gwHash + "." + "klb." + domain), + "RecordTTL": Equal(externaldns.TTL(60)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "weight", Value: "120"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal("klb." + domain), + "Targets": ConsistOf("ie.klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal("IE"), + "RecordTTL": Equal(externaldns.TTL(300)), + "ProviderSpecific": Equal(externaldns.ProviderSpecific{{Name: "geo-code", Value: "IE"}}), + })), + PointTo(MatchFields(IgnoreExtras, Fields{ + "DNSName": Equal(tests.HostWildcard(domain)), + "Targets": ConsistOf("klb." + domain), + "RecordType": Equal("CNAME"), + "SetIdentifier": Equal(""), + "RecordTTL": Equal(externaldns.TTL(300)), + })), + )) + g.Expect(wildcardDnsRecord.Status.OwnerID).ToNot(BeEmpty()) + g.Expect(wildcardDnsRecord.Status.OwnerID).To(Equal(wildcardDnsRecord.GetUIDHash())) + g.Expect(tests.EndpointsTraversable(wildcardDnsRecord.Spec.Endpoints, tests.HostWildcard(domain), []string{tests.IPAddressOne, tests.IPAddressTwo})).To(BeTrue()) + }, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed()) + }, testTimeOut) + }) }) }) diff --git a/tests/common/dnspolicy/dnspolicy_controller_test.go b/tests/common/dnspolicy/dnspolicy_controller_test.go index 09ee8dccb..5b8b688fa 100644 --- a/tests/common/dnspolicy/dnspolicy_controller_test.go +++ b/tests/common/dnspolicy/dnspolicy_controller_test.go @@ -24,7 +24,6 @@ import ( "github.com/kuadrant/kuadrant-operator/api/v1alpha1" "github.com/kuadrant/kuadrant-operator/controllers" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" - "github.com/kuadrant/kuadrant-operator/pkg/multicluster" "github.com/kuadrant/kuadrant-operator/tests" ) @@ -79,43 +78,63 @@ var _ = Describe("DNSPolicy controller", func() { tests.DeleteNamespace(ctx, testClient(), testNamespace) }, afterEachTimeOut) - It("should validate routing strategy field correctly", func(ctx SpecContext) { - + It("should validate loadBalancing field correctly", func(ctx SpecContext) { gateway = tests.NewGatewayBuilder("test-gateway", gatewayClass.Name, testNamespace). WithHTTPListener(tests.ListenerNameOne, tests.HostTwo(domain)).Gateway // simple should succeed dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("test-gateway"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("test-gateway") Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - // should not allow changing routing strategy + // should not allow adding loadBalancing field value after creation Eventually(func(g Gomega) { err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dnsPolicy), dnsPolicy) g.Expect(err).NotTo(HaveOccurred()) - dnsPolicy.Spec.RoutingStrategy = v1alpha1.LoadBalancedRoutingStrategy + dnsPolicy.Spec.LoadBalancing = &v1alpha1.LoadBalancingSpec{ + Weight: 100, + Geo: "foo", + DefaultGeo: false, + } err = k8sClient.Update(ctx, dnsPolicy) g.Expect(err).To(HaveOccurred()) - g.Expect(err).To(MatchError(ContainSubstring("RoutingStrategy is immutable"))) + g.Expect(err).To(MatchError(ContainSubstring("loadBalancing is immutable"))) }, tests.TimeoutMedium, time.Second).Should(Succeed()) Expect(k8sClient.Delete(ctx, dnsPolicy)).ToNot(HaveOccurred()) - // loadbalanced missing loadbalancing field - dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("test-gateway"). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy) - Expect(k8sClient.Create(ctx, dnsPolicy)).To(MatchError(ContainSubstring("spec.loadBalancing is a required field when spec.routingStrategy == 'loadbalanced'"))) - // loadbalanced should succeed dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). WithTargetGateway("test-gateway"). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(100, nil, "foo") + WithLoadBalancingFor(100, "foo", false) Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) + + // should allow loadBalancing struct fields to be updated + Eventually(func(g Gomega) { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dnsPolicy), dnsPolicy) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(dnsPolicy.Spec.LoadBalancing).ToNot(BeNil()) + g.Expect(dnsPolicy.Spec.LoadBalancing.Geo).To(Equal("foo")) + g.Expect(dnsPolicy.Spec.LoadBalancing.Weight).To(Equal(100)) + g.Expect(dnsPolicy.Spec.LoadBalancing.DefaultGeo).ToNot(BeTrue()) + dnsPolicy.Spec.LoadBalancing.Geo = "bar" + dnsPolicy.Spec.LoadBalancing.Weight = 200 + dnsPolicy.Spec.LoadBalancing.DefaultGeo = true + err = k8sClient.Update(ctx, dnsPolicy) + g.Expect(err).To(Succeed()) + }, tests.TimeoutMedium, time.Second).Should(Succeed()) + + // should not allow removing loadBalancing field value after creation + Eventually(func(g Gomega) { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dnsPolicy), dnsPolicy) + g.Expect(err).NotTo(HaveOccurred()) + dnsPolicy.Spec.LoadBalancing = nil + err = k8sClient.Update(ctx, dnsPolicy) + g.Expect(err).To(HaveOccurred()) + g.Expect(err).To(MatchError(ContainSubstring("loadBalancing is immutable"))) + }, tests.TimeoutMedium, time.Second).Should(Succeed()) + Expect(k8sClient.Delete(ctx, dnsPolicy)).ToNot(HaveOccurred()) }, testTimeOut) It("should validate provider ref field correctly", func(ctx SpecContext) { @@ -125,15 +144,13 @@ var _ = Describe("DNSPolicy controller", func() { // should not allow an empty providerRef list dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). - WithTargetGateway("test-gateway"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("test-gateway") Expect(k8sClient.Create(ctx, dnsPolicy)).To(MatchError(ContainSubstring("spec.providerRefs: Required value"))) // should create with a single providerRef dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("test-gateway"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("test-gateway") Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) // should not allow adding another providerRef @@ -200,8 +217,7 @@ var _ = Describe("DNSPolicy controller", func() { // Create policy1 targeting gateway1 with simple routing strategy dnsPolicy1 := v1alpha1.NewDNSPolicy("test-dns-policy1", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("test-gateway1"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("test-gateway1") Expect(k8sClient.Create(ctx, dnsPolicy1)).To(Succeed()) // the policy 1 should succeed @@ -250,8 +266,7 @@ var _ = Describe("DNSPolicy controller", func() { dnsPolicy2 := v1alpha1.NewDNSPolicy("test-dns-policy2", testNamespace). WithProviderSecret(*dnsProviderSecret). WithTargetGateway("test-gateway2"). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(100, nil, "foo") + WithLoadBalancingFor(100, "foo", false) Expect(k8sClient.Create(ctx, dnsPolicy2)).To(Succeed()) errorMessage := "The DNS provider failed to ensure the record: record type conflict, " + @@ -321,8 +336,7 @@ var _ = Describe("DNSPolicy controller", func() { It("should have accepted condition with status false and correct reason", func(ctx SpecContext) { dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("test-gateway"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("test-gateway") Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) Eventually(func(g Gomega) { @@ -397,16 +411,14 @@ var _ = Describe("DNSPolicy controller", func() { // Create policy1 targeting gateway1 with simple routing strategy dnsPolicy1 := v1alpha1.NewDNSPolicy("test-dns-policy1", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("test-gateway1"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("test-gateway1") Expect(k8sClient.Create(ctx, dnsPolicy1)).To(Succeed()) // create policy2 targeting gateway2 with the load-balanced strategy dnsPolicy2 := v1alpha1.NewDNSPolicy("test-dns-policy2", testNamespace). WithProviderSecret(*dnsProviderSecret). WithTargetGateway("test-gateway2"). - WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). - WithLoadBalancingFor(100, nil, "foo") + WithLoadBalancingFor(100, "foo", false) Expect(k8sClient.Create(ctx, dnsPolicy2)).To(Succeed()) // policy2 should fail: dns provider already has a record for this host from the gateway1+policy1 @@ -452,8 +464,7 @@ var _ = Describe("DNSPolicy controller", func() { Gateway dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(testGatewayName). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway(testGatewayName) Expect(k8sClient.Create(ctx, gateway)).To(Succeed()) Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) @@ -514,54 +525,39 @@ var _ = Describe("DNSPolicy controller", func() { Gateway dnsPolicy = v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway(tests.GatewayName). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway(tests.GatewayName) Expect(k8sClient.Create(ctx, gateway)).To(Succeed()) Expect(k8sClient.Create(ctx, dnsPolicy)).To(Succeed()) - Eventually(func() error { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), gateway) - Expect(err).ShouldNot(HaveOccurred()) - + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), gateway)).To(Succeed()) gateway.Status.Addresses = []gatewayapiv1.GatewayStatusAddress{ { - Type: ptr.To(multicluster.MultiClusterIPAddressType), - Value: tests.ClusterNameOne + "/" + tests.IPAddressOne, + Type: ptr.To(gatewayapiv1.IPAddressType), + Value: tests.IPAddressOne, }, { - Type: ptr.To(multicluster.MultiClusterIPAddressType), - Value: tests.ClusterNameTwo + "/" + tests.IPAddressTwo, + Type: ptr.To(gatewayapiv1.IPAddressType), + Value: tests.IPAddressTwo, }, } gateway.Status.Listeners = []gatewayapiv1.ListenerStatus{ { - Name: tests.ClusterNameOne + "." + tests.ListenerNameOne, - SupportedKinds: []gatewayapiv1.RouteGroupKind{}, - AttachedRoutes: 1, - Conditions: []metav1.Condition{}, - }, - { - Name: tests.ClusterNameTwo + "." + tests.ListenerNameOne, - SupportedKinds: []gatewayapiv1.RouteGroupKind{}, - AttachedRoutes: 1, - Conditions: []metav1.Condition{}, - }, - { - Name: tests.ClusterNameOne + "." + tests.ListenerNameWildcard, + Name: tests.ListenerNameOne, SupportedKinds: []gatewayapiv1.RouteGroupKind{}, AttachedRoutes: 1, Conditions: []metav1.Condition{}, }, { - Name: tests.ClusterNameTwo + "." + tests.ListenerNameWildcard, + Name: tests.ListenerNameWildcard, SupportedKinds: []gatewayapiv1.RouteGroupKind{}, AttachedRoutes: 1, Conditions: []metav1.Condition{}, }, } - return k8sClient.Status().Update(ctx, gateway) - }, tests.TimeoutMedium, tests.RetryIntervalMedium).ShouldNot(HaveOccurred()) + g.Expect(k8sClient.Status().Update(ctx, gateway)).To(Succeed()) + }, tests.TimeoutMedium, tests.RetryIntervalMedium).Should(Succeed()) recordName = fmt.Sprintf("%s-%s", tests.GatewayName, tests.ListenerNameOne) wildcardRecordName = fmt.Sprintf("%s-%s", tests.GatewayName, tests.ListenerNameWildcard) @@ -819,8 +815,7 @@ var _ = Describe("DNSPolicy controller", func() { It("should error targeting invalid group", func(ctx SpecContext) { p := v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("gateway"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("gateway") p.Spec.TargetRef.Group = "not-gateway.networking.k8s.io" err := k8sClient.Create(ctx, p) @@ -831,8 +826,7 @@ var _ = Describe("DNSPolicy controller", func() { It("should error targeting invalid kind", func(ctx SpecContext) { p := v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace). WithProviderSecret(*dnsProviderSecret). - WithTargetGateway("gateway"). - WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + WithTargetGateway("gateway") p.Spec.TargetRef.Kind = "TCPRoute" err := k8sClient.Create(ctx, p) diff --git a/tests/common/targetstatus/target_status_controller_test.go b/tests/common/targetstatus/target_status_controller_test.go index 8f36b739d..b8cb2f5d8 100644 --- a/tests/common/targetstatus/target_status_controller_test.go +++ b/tests/common/targetstatus/target_status_controller_test.go @@ -478,7 +478,7 @@ var _ = Describe("Target status reconciler", func() { // policyFactory builds a standards DNSPolicy object that targets the test gateway by default, with the given mutate functions applied policyFactory := func(mutateFns ...func(policy *v1alpha1.DNSPolicy)) *v1alpha1.DNSPolicy { - policy := v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace).WithTargetGateway(TestGatewayName).WithRoutingStrategy(v1alpha1.SimpleRoutingStrategy) + policy := v1alpha1.NewDNSPolicy("test-dns-policy", testNamespace).WithTargetGateway(TestGatewayName) for _, mutateFn := range mutateFns { mutateFn(policy) }