Skip to content

Commit

Permalink
add validations to crd with enums (#100)
Browse files Browse the repository at this point in the history
* add validations to crd with enums

* add validation to apiVersion
  • Loading branch information
Maanas-23 authored Feb 26, 2025
1 parent ce2c2f4 commit 689e0f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
11 changes: 11 additions & 0 deletions charts/elasti/templates/elastiservice-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ spec:
name:
type: string
type:
enum:
- hpa
- keda
type: string
required:
- name
Expand All @@ -62,8 +65,14 @@ spec:
Important: Run "make" to regenerate code after modifying this file
properties:
apiVersion:
enum:
- apps/v1
- argoproj.io/v1alpha1
type: string
kind:
enum:
- deployments
- rollouts
type: string
name:
type: string
Expand All @@ -76,6 +85,8 @@ spec:
metadata:
x-kubernetes-preserve-unknown-fields: true
type:
enum:
- prometheus
type: string
required:
- type
Expand Down
10 changes: 7 additions & 3 deletions operator/api/v1alpha1/elastiservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ type ElastiServiceSpec struct {
}

type ScaleTargetRef struct {
// +kubebuilder:validation:Enum=apps/v1;argoproj.io/v1alpha1
APIVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
// +kubebuilder:validation:Enum=deployments;rollouts
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
}

// ElastiServiceStatus defines the observed state of ElastiService
Expand Down Expand Up @@ -78,14 +80,16 @@ type ElastiServiceList struct {
}

type ScaleTrigger struct {
// +kubebuilder:validation:Enum=prometheus
Type string `json:"type"`
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Metadata json.RawMessage `json:"metadata,omitempty"`
}

type AutoscalerSpec struct {
Type string `json:"type"` // keda/hpa
// +kubebuilder:validation:Enum=hpa;keda
Type string `json:"type"`
Name string `json:"name"` // Name of the ScaledObject/HorizontalPodAutoscaler
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ spec:
name:
type: string
type:
enum:
- hpa
- keda
type: string
required:
- name
Expand All @@ -61,8 +64,14 @@ spec:
Important: Run "make" to regenerate code after modifying this file
properties:
apiVersion:
enum:
- apps/v1
- argoproj.io/v1alpha1
type: string
kind:
enum:
- deployments
- rollouts
type: string
name:
type: string
Expand All @@ -75,6 +84,8 @@ spec:
metadata:
x-kubernetes-preserve-unknown-fields: true
type:
enum:
- prometheus
type: string
required:
- type
Expand Down

0 comments on commit 689e0f7

Please sign in to comment.