Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-110 use CRD validation on DNSRecord #160

Merged
merged 1 commit into from
Jun 28, 2024
Merged

GH-110 use CRD validation on DNSRecord #160

merged 1 commit into from
Jun 28, 2024

Conversation

maksymvavilov
Copy link
Contributor

@maksymvavilov maksymvavilov commented Jun 13, 2024

Adding following validation rules on the DNS Record CRD:

Spec

  • RootHost limited to 255 characters and must consist of two groups of allowed for URLs characters separated by the .. This is the only check from the Validate() that is feasible to transfer to the CRD validations

HealthCheck Spec

  • Endpoint (aka Path) should start with ? or /, contain only allowed for the URLs symbols and end with alphanumeric character or /.
  • Port allowed to be set to 80, 443, and from 1024 to 49151 - the range of registered ports.
  • Protocol restricted to HTTP or HTTPS
  • FailureThreshold must be a positive integer

@maksymvavilov maksymvavilov marked this pull request as ready for review June 14, 2024 10:50
@maksymvavilov maksymvavilov changed the title [WIP] GH-110 use CRD validation on DNSRecord GH-110 use CRD validation on DNSRecord Jun 14, 2024
@maksymvavilov maksymvavilov linked an issue Jun 26, 2024 that may be closed by this pull request
Port *int `json:"port,omitempty"`

// +kubebuilder:validation:XValidation:rule="self in ['HTTP','HTTPS']",message="Only HTTP or HTTPS protocols are allowed"
Protocol *HealthProtocol `json:"protocol,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Enum would probably make more sense here, and for port see https://github.com/Kuadrant/kuadrant-operator/blob/main/api/v1alpha1/dnspolicy_types.go#L255

Also, all the validations should be the same as https://github.com/Kuadrant/kuadrant-operator/blob/main/api/v1alpha1/dnspolicy_types.go#L246-L261

@philbrookes Why is that duplicated? Would it not make more sense for the DNSPolicy to reference this HealthCheckSpec type?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot remember clearly, I suspect the Specs were different from each other at some point, but are aligned now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the validations in this PR are superior to the validations in Kuadrant-operator, it might be worth a PR to update kuadrant to use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the CEL validations - way nicer error message if things aren't right.

Hmm, would it be a good idea to remove duplication as part of this issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a PR to the kuadrant-operator as well

Copy link
Collaborator

@philbrookes philbrookes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes to the language used, the regexes look fine.

@philbrookes
Copy link
Collaborator

I see @mikenairn has added some tests to cover his validations, which is pretty neat, is that something we could also do here?

@maksymvavilov
Copy link
Contributor Author

Added test @philbrookes. It is a strange one, but, hopefully, is useful. At least it is cheep to check it.

@maksymvavilov maksymvavilov added this pull request to the merge queue Jun 28, 2024
Merged via the queue into main with commit b2b1f94 Jun 28, 2024
11 checks passed
@maksymvavilov maksymvavilov deleted the gh-110 branch June 28, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve validations on DNSRecord spec fields
3 participants