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

Add Kubernetes CRD Annotations to Duration Type #708

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

Conversation

ibakshay
Copy link

@ibakshay ibakshay commented Oct 21, 2024

Description

This PR adds Kubernetes CRD kube builder annotations to the Duration type to improve compatibility with Kubernetes Custom Resource Definitions.

Background

The Duration type currently has a custom JSON serialisation that implicitly converts to a string:

Changes

Added annotations to type Duration time.Duration in model/time.go:

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
type Duration time.Duration

These annotations resolve serialization conflicts when Duration is used in Kubernetes CRDs, allowing for correct validation and serialisation in Kubernetes environments while maintaining the existing string serialisation behaviour.

Impact

  • Improves compatibility with Kubernetes CRDs
  • No change to existing behaviour in non-Kubernetes contexts
  • Backwards compatible

Testing

  • Verified annotations don't affect existing Duration behavior
  • Tested with a Kubernetes operator to ensure proper CRD validation

fixes perses/perses-operator#20

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.

model.Duration Serialization Incompatibility with Kubernetes API
1 participant