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 validation of memStorage and fileStorage #64

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1alpha1/nats_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type NATSSpec struct {

// JetStream defines configurations that are specific to NATS JetStream.
// +kubebuilder:default:={fileStorage:{storageClassName:"default", size:"1Gi"},memStorage:{size:"20Mi",enabled:false}}
// +kubebuilder:validation:XValidation:rule="self.fileStorage == oldSelf.fileStorage",message="fileStorage is immutable once it was set"
JetStream `json:"jetStream,omitempty"`

// JetStream defines configurations that are specific to NATS logging in NATS.
Expand Down Expand Up @@ -128,10 +129,12 @@ type Cluster struct {
type JetStream struct {
// MemStorage defines configurations to memory storage in NATS JetStream.
// +kubebuilder:default:={size:"20Mi",enabled:false}
// +kubebuilder:validation:XValidation:rule="!self.enabled || self.size != 0", message="can only be enabled if size is not 0"
MemStorage `json:"memStorage,omitempty"`

// FileStorage defines configurations to file storage in NATS JetStream.
// +kubebuilder:default:={storageClassName:"default",size:"1Gi"}
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="fileStorage is immutable once it was set"
FileStorage `json:"fileStorage,omitempty"`
}

Expand All @@ -150,10 +153,12 @@ type MemStorage struct {
type FileStorage struct {
// StorageClassName defines the file storage class name.
// +kubebuilder:default:="default"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="fileStorage is immutable once it was set"
StorageClassName string `json:"storageClassName,omitempty"`

// Size defines the file storage size.
// +kubebuilder:default:="1Gi"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="fileStorage is immutable once it was set"
Size resource.Quantity `json:"size,omitempty"`
}

Expand Down
15 changes: 15 additions & 0 deletions config/crd/bases/operator.kyma-project.io_nats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,21 @@ spec:
description: Size defines the file storage size.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
x-kubernetes-validations:
- message: fileStorage is immutable once it was set
rule: self == oldSelf
storageClassName:
default: default
description: StorageClassName defines the file storage class
name.
type: string
x-kubernetes-validations:
- message: fileStorage is immutable once it was set
rule: self == oldSelf
type: object
x-kubernetes-validations:
- message: fileStorage is immutable once it was set
rule: self == oldSelf
memStorage:
default:
enabled: false
Expand All @@ -136,7 +145,13 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-validations:
- message: can only be enabled if size is not 0
rule: '!self.enabled || self.size != 0'
type: object
x-kubernetes-validations:
- message: fileStorage is immutable once it was set
rule: self.fileStorage == oldSelf.fileStorage
labels:
additionalProperties:
type: string
Expand Down
Loading