Skip to content

API cleanup #11606

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

API cleanup #11606

wants to merge 9 commits into from

Conversation

jenshu
Copy link
Contributor

@jenshu jenshu commented Jul 7, 2025

Description

Some cleanup in our APIs for consistency:

  • for optional fields, use pointers (unless it's a map/slice, or has a default value defined), and add omitempty if it wasn't already there
  • standardize on using +optional / +required rather than the kubebuilder markers
  • don't use pointers within slices
  • update API readme with these details

Change Type

/kind cleanup

Changelog

Update policy APIs to use pointer types for optional fields, and value types within slices.

Additional Notes

jenshu added 4 commits July 7, 2025 14:34
Signed-off-by: Jenny Shu <[email protected]>
Signed-off-by: Jenny Shu <[email protected]>
Signed-off-by: Jenny Shu <[email protected]>
@github-actions github-actions bot added do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 7, 2025
@jenshu jenshu changed the title [wip] Api cleanup API cleanup Jul 8, 2025
@github-actions github-actions bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note and removed do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 8, 2025
Signed-off-by: Jenny Shu <[email protected]>
Comment on lines +175 to +177
aggression := ptr.Deref(ir.aggression, "")
if aggression != "" {
aggressionValue, err := strconv.ParseFloat(aggression, 64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use nil checks and add MinLength validations to string values to prevent empty

Suggested change
aggression := ptr.Deref(ir.aggression, "")
if aggression != "" {
aggressionValue, err := strconv.ParseFloat(aggression, 64)
if ir.aggression != nil {
aggressionValue, err := strconv.ParseFloat(*ir.aggression, 64)

@@ -207,7 +207,7 @@ type TLS struct {

// The SNI domains that should be considered for TLS connection
// +optional
Sni string `json:"sni,omitempty"`
Sni *string `json:"sni,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs MinLength validation

Comment on lines +270 to +276
TLSCertificate *string `json:"tlsCertificate,omitempty"`

// +optional
TLSKey string `json:"tlsKey,omitempty"`
TLSKey *string `json:"tlsKey,omitempty"`

// +optional
RootCA string `json:"rootCA,omitempty"`
RootCA *string `json:"rootCA,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Add MinLength validation

@@ -181,7 +181,7 @@ type AwsLambda struct {
// (alphanumeric plus "-" or "_"), or the special literal "$LATEST".
// +optional
// +kubebuilder:validation:Pattern="^(\\$LATEST|[0-9]+|[A-Za-z0-9-_]{1,128})$"
Qualifier string `json:"qualifier,omitempty"`
Qualifier *string `json:"qualifier,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

We should default this to $LATEST

func buildLambdaARN(in *v1alpha1.AwsBackend, region string) (string, error) {
	qualifier := "$LATEST"
	if in.Lambda.Qualifier != "" {
		qualifier = in.Lambda.Qualifier
	}

@@ -42,7 +42,7 @@ type DirectResponseSpec struct {
//
// +kubebuilder:validation:MaxLength=4096
// +optional
Body string `json:"body,omitempty"`
Body *string `json:"body,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Add MinLength validation

@@ -124,13 +125,14 @@ func createRateLimitActions(descriptors []v1alpha1.RateLimitDescriptor) ([]*rout
},
}
case v1alpha1.RateLimitDescriptorEntryTypeHeader:
if entry.Header == "" {
header := ptr.Deref(entry.Header, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to nil check and prevent empty header value using MinLength validation

- RBAC roles are generated in [install/helm/kgateway/templates/role.yaml](/install/helm/kgateway/templates/role.yaml)
- Updates the [api/applyconfiguration](/api/applyconfiguration), [pkg/generated](/pkg/generated) and [pkg/client](/pkg/client) folders with kube clients. These are used in plugin initialization and the fake client is used in tests.

## API guidelines
Copy link
Member

Choose a reason for hiding this comment

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

Another potential line item: how to handle time related fields. The approach we've been taking is meta.Duration + CEL validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants