Skip to content

Commit

Permalink
refer to the DNSSpeck from dns-operator repo
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymvavilov committed Jul 24, 2024
1 parent a463595 commit 2adf7c4
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 113 deletions.
41 changes: 10 additions & 31 deletions api/v1alpha1/dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import (
"fmt"

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"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

"github.com/kuadrant/dns-operator/api/v1alpha1"

kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi"
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
Expand Down Expand Up @@ -53,7 +56,7 @@ type DNSPolicySpec struct {
TargetRef gatewayapiv1alpha2.PolicyTargetReference `json:"targetRef"`

// +optional
HealthCheck *HealthCheckSpec `json:"healthCheck,omitempty"`
HealthCheck *v1alpha1.HealthCheckSpec `json:"healthCheck,omitempty"`

// +optional
LoadBalancing *LoadBalancingSpec `json:"loadBalancing,omitempty"`
Expand Down Expand Up @@ -131,7 +134,7 @@ type DNSPolicyStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// +optional
HealthCheck *HealthCheckStatus `json:"healthCheck,omitempty"`
HealthCheck *v1alpha1.HealthCheckStatus `json:"healthCheck,omitempty"`

// +optional
RecordConditions map[string][]metav1.Condition `json:"recordConditions,omitempty"`
Expand Down Expand Up @@ -236,30 +239,6 @@ func (l *DNSPolicyList) GetItems() []kuadrant.Policy {
})
}

// HealthCheckSpec configures health checks in the DNS provider.
// By default, this health check will be applied to each unique DNS A Record for
// the listeners assigned to the target gateway
type HealthCheckSpec struct {
// Endpoint is the path to append to the host to reach the expected health check.
// For example "/" or "/healthz" are common
// +kubebuilder:example:=/
Endpoint string `json:"endpoint"`
// Port to connect to the host on
// +kubebuilder:validation:Minimum:=1
Port int `json:"port"`
// Protocol to use when connecting to the host, valid values are "HTTP" or "HTTPS"
// +kubebuilder:validation:Enum:=HTTP;HTTPS
Protocol string `json:"protocol"`
// FailureThreshold is a limit of consecutive failures that must occur for a host
// to be considered unhealthy
// +kubebuilder:validation:Minimum:=1
FailureThreshold int `json:"failureThreshold"`
}

type HealthCheckStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

func init() {
SchemeBuilder.Register(&DNSPolicy{}, &DNSPolicyList{})
}
Expand All @@ -285,7 +264,7 @@ func (p *DNSPolicy) WithTargetRef(targetRef gatewayapiv1alpha2.PolicyTargetRefer
return p
}

func (p *DNSPolicy) WithHealthCheck(healthCheck HealthCheckSpec) *DNSPolicy {
func (p *DNSPolicy) WithHealthCheck(healthCheck v1alpha1.HealthCheckSpec) *DNSPolicy {
p.Spec.HealthCheck = &healthCheck
return p
}
Expand Down Expand Up @@ -315,11 +294,11 @@ func (p *DNSPolicy) WithTargetGateway(gwName string) *DNSPolicy {
//HealthCheck

func (p *DNSPolicy) WithHealthCheckFor(endpoint string, port int, protocol string, failureThreshold int) *DNSPolicy {
return p.WithHealthCheck(HealthCheckSpec{
return p.WithHealthCheck(v1alpha1.HealthCheckSpec{
Endpoint: endpoint,
Port: port,
Protocol: protocol,
FailureThreshold: failureThreshold,
Port: &port,
Protocol: ptr.To(v1alpha1.HealthProtocol(protocol)),
FailureThreshold: &failureThreshold,
})
}

Expand Down
44 changes: 4 additions & 40 deletions api/v1alpha1/zz_generated.deepcopy.go

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

122 changes: 105 additions & 17 deletions bundle/manifests/kuadrant.io_dnspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,36 @@ spec:
healthCheck:
description: |-
HealthCheckSpec configures health checks in the DNS provider.
By default, this health check will be applied to each unique DNS A Record for
By default this health check will be applied to each unique DNS A Record for
the listeners assigned to the target gateway
properties:
endpoint:
description: |-
Endpoint is the path to append to the host to reach the expected health check.
For example "/" or "/healthz" are common
example: /
Must start with "?" or "/", contain only valid URL characters and end with alphanumeric char or "/". For example "/" or "/healthz" are common
pattern: ^(?:\?|\/)[\w\-.~:\/?#\[\]@!$&'()*+,;=]+(?:[a-zA-Z0-9]|\/){1}$
type: string
failureThreshold:
description: |-
FailureThreshold is a limit of consecutive failures that must occur for a host
to be considered unhealthy
minimum: 1
description: FailureThreshold is a limit of consecutive failures
that must occur for a host to be considered unhealthy
type: integer
x-kubernetes-validations:
- message: Failure threshold must be greater than 0
rule: self > 0
port:
description: Port to connect to the host on
minimum: 1
description: Port to connect to the host on. Must be either 80,
443 or 1024-49151
type: integer
x-kubernetes-validations:
- message: Only ports 80, 443, 1024-49151 are allowed
rule: self in [80, 443] || (self >= 1024 && self <= 49151)
protocol:
description: Protocol to use when connecting to the host, valid
values are "HTTP" or "HTTPS"
enum:
- HTTP
- HTTPS
type: string
required:
- endpoint
- failureThreshold
- port
- protocol
x-kubernetes-validations:
- message: Only HTTP or HTTPS protocols are allowed
rule: self in ['HTTP','HTTPS']
type: object
loadBalancing:
properties:
Expand Down Expand Up @@ -407,6 +406,95 @@ spec:
- type
type: object
type: array
probes:
items:
properties:
conditions:
items:
description: "Condition contains details for one aspect
of the current state of this API Resource.\n---\nThis
struct is intended for direct use as an array at the
field path .status.conditions. For example,\n\n\n\ttype
FooStatus struct{\n\t // Represents the observations
of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t
\ // +patchMergeKey=type\n\t // +patchStrategy=merge\n\t
\ // +listType=map\n\t // +listMapKey=type\n\t
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True,
False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
host:
type: string
id:
type: string
ipAddress:
type: string
synced:
type: boolean
required:
- host
- id
- ipAddress
type: object
type: array
type: object
observedGeneration:
description: |-
Expand Down
Loading

0 comments on commit 2adf7c4

Please sign in to comment.