Skip to content

Commit 689e0f7

Browse files
authored
add validations to crd with enums (#100)
* add validations to crd with enums * add validation to apiVersion
1 parent ce2c2f4 commit 689e0f7

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

charts/elasti/templates/elastiservice-crd.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ spec:
4545
name:
4646
type: string
4747
type:
48+
enum:
49+
- hpa
50+
- keda
4851
type: string
4952
required:
5053
- name
@@ -62,8 +65,14 @@ spec:
6265
Important: Run "make" to regenerate code after modifying this file
6366
properties:
6467
apiVersion:
68+
enum:
69+
- apps/v1
70+
- argoproj.io/v1alpha1
6571
type: string
6672
kind:
73+
enum:
74+
- deployments
75+
- rollouts
6776
type: string
6877
name:
6978
type: string
@@ -76,6 +85,8 @@ spec:
7685
metadata:
7786
x-kubernetes-preserve-unknown-fields: true
7887
type:
88+
enum:
89+
- prometheus
7990
type: string
8091
required:
8192
- type

operator/api/v1alpha1/elastiservice_types.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ type ElastiServiceSpec struct {
4242
}
4343

4444
type ScaleTargetRef struct {
45+
// +kubebuilder:validation:Enum=apps/v1;argoproj.io/v1alpha1
4546
APIVersion string `json:"apiVersion,omitempty"`
46-
Kind string `json:"kind,omitempty"`
47-
Name string `json:"name,omitempty"`
47+
// +kubebuilder:validation:Enum=deployments;rollouts
48+
Kind string `json:"kind,omitempty"`
49+
Name string `json:"name,omitempty"`
4850
}
4951

5052
// ElastiServiceStatus defines the observed state of ElastiService
@@ -78,14 +80,16 @@ type ElastiServiceList struct {
7880
}
7981

8082
type ScaleTrigger struct {
83+
// +kubebuilder:validation:Enum=prometheus
8184
Type string `json:"type"`
8285
// +kubebuilder:pruning:PreserveUnknownFields
8386
// +kubebuilder:validation:Schemaless
8487
Metadata json.RawMessage `json:"metadata,omitempty"`
8588
}
8689

8790
type AutoscalerSpec struct {
88-
Type string `json:"type"` // keda/hpa
91+
// +kubebuilder:validation:Enum=hpa;keda
92+
Type string `json:"type"`
8993
Name string `json:"name"` // Name of the ScaledObject/HorizontalPodAutoscaler
9094
}
9195

operator/config/crd/bases/elasti.truefoundry.com_elastiservices.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ spec:
4444
name:
4545
type: string
4646
type:
47+
enum:
48+
- hpa
49+
- keda
4750
type: string
4851
required:
4952
- name
@@ -61,8 +64,14 @@ spec:
6164
Important: Run "make" to regenerate code after modifying this file
6265
properties:
6366
apiVersion:
67+
enum:
68+
- apps/v1
69+
- argoproj.io/v1alpha1
6470
type: string
6571
kind:
72+
enum:
73+
- deployments
74+
- rollouts
6675
type: string
6776
name:
6877
type: string
@@ -75,6 +84,8 @@ spec:
7584
metadata:
7685
x-kubernetes-preserve-unknown-fields: true
7786
type:
87+
enum:
88+
- prometheus
7889
type: string
7990
required:
8091
- type

0 commit comments

Comments
 (0)