Skip to content

Commit

Permalink
refactor: make disk_space pattern case-insensitive (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored May 28, 2024
1 parent b3d28cf commit 52c43fe
Show file tree
Hide file tree
Showing 27 changed files with 55 additions and 29 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type ServiceCommonSpec struct {
BaseServiceFields `json:",inline"`
SecretFields `json:",inline"`

// +kubebuilder:validation:Pattern="^[1-9][0-9]*(GiB|G)?$"
// +kubebuilder:validation:Pattern="(?i)^[1-9][0-9]*(GiB|G)?$"
// The disk space of the service, possible values depend on the service type, the cloud provider and the project.
// Reducing will result in the service re-balancing.
// The removal of this field does not change the value.
Expand Down Expand Up @@ -213,7 +213,7 @@ type ResourceReferenceObject struct {
NamespacedName types.NamespacedName
}

func ConvertDiscSpace(v string) int {
func ConvertDiskSpace(v string) int {
if v == "" {
return 0
}
Expand Down
26 changes: 26 additions & 0 deletions api/v1alpha1/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestConvertDiskSpace(t *testing.T) {
cases := map[string]int{
"10GiB": 10240,
"10gib": 10240,
"10G": 10240,
"10g": 10240,
"1g": 1024,
"2g": 2048,
"": 0,
}

for k, v := range cases {
t.Run(k, func(t *testing.T) {
result := ConvertDiskSpace(k)
assert.Equal(t, v, result)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion charts/aiven-operator-crds/templates/aiven.io_kafkas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
karapace:
description:
Expand Down
2 changes: 1 addition & 1 deletion charts/aiven-operator-crds/templates/aiven.io_mysqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion charts/aiven-operator-crds/templates/aiven.io_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_cassandras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_clickhouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_grafanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_kafkas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
karapace:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_mysqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_opensearches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_postgresqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/aiven.io_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
on the service type, the cloud provider and the project. Reducing
will result in the service re-balancing. The removal of this field
does not change the value.
pattern: ^[1-9][0-9]*(GiB|G)?$
pattern: (?i)^[1-9][0-9]*(GiB|G)?$
type: string
maintenanceWindowDow:
description:
Expand Down
4 changes: 2 additions & 2 deletions controllers/generic_service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h *genericServiceHandler) createOrUpdate(ctx context.Context, avn *aiven.C

req := aiven.CreateServiceRequest{
Cloud: spec.CloudName,
DiskSpaceMB: v1alpha1.ConvertDiscSpace(o.getDiskSpace()),
DiskSpaceMB: v1alpha1.ConvertDiskSpace(o.getDiskSpace()),
MaintenanceWindow: getMaintenanceWindow(spec.MaintenanceWindowDow, spec.MaintenanceWindowTime),
Plan: spec.Plan,
ProjectVPCID: toOptionalStringPointer(projectVPCID),
Expand Down Expand Up @@ -104,7 +104,7 @@ func (h *genericServiceHandler) createOrUpdate(ctx context.Context, avn *aiven.C

req := aiven.UpdateServiceRequest{
Cloud: spec.CloudName,
DiskSpaceMB: v1alpha1.ConvertDiscSpace(o.getDiskSpace()),
DiskSpaceMB: v1alpha1.ConvertDiskSpace(o.getDiskSpace()),
MaintenanceWindow: getMaintenanceWindow(spec.MaintenanceWindowDow, spec.MaintenanceWindowTime),
Plan: spec.Plan,
Powered: true,
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api-reference/cassandra.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CassandraSpec defines the desired state of Cassandra.
- [`cloudName`](#spec.cloudName-property){: name='spec.cloudName-property'} (string, MaxLength: 256). Cloud the service runs in.
- [`connInfoSecretTarget`](#spec.connInfoSecretTarget-property){: name='spec.connInfoSecretTarget-property'} (object). Secret configuration. See below for [nested schema](#spec.connInfoSecretTarget).
- [`connInfoSecretTargetDisabled`](#spec.connInfoSecretTargetDisabled-property){: name='spec.connInfoSecretTargetDisabled-property'} (boolean, Immutable). When true, the secret containing connection information will not be created, defaults to false. This field cannot be changed after resource creation.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `(?i)^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`maintenanceWindowDow`](#spec.maintenanceWindowDow-property){: name='spec.maintenanceWindowDow-property'} (string, Enum: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`). Day of week when maintenance operations should be performed. One monday, tuesday, wednesday, etc.
- [`maintenanceWindowTime`](#spec.maintenanceWindowTime-property){: name='spec.maintenanceWindowTime-property'} (string, MaxLength: 8). Time of day when maintenance operations should be performed. UTC time in HH:mm:ss format.
- [`projectVPCRef`](#spec.projectVPCRef-property){: name='spec.projectVPCRef-property'} (object). ProjectVPCRef reference to ProjectVPC resource to use its ID as ProjectVPCID automatically. See below for [nested schema](#spec.projectVPCRef).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api-reference/clickhouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ClickhouseSpec defines the desired state of Clickhouse.
- [`cloudName`](#spec.cloudName-property){: name='spec.cloudName-property'} (string, MaxLength: 256). Cloud the service runs in.
- [`connInfoSecretTarget`](#spec.connInfoSecretTarget-property){: name='spec.connInfoSecretTarget-property'} (object). Secret configuration. See below for [nested schema](#spec.connInfoSecretTarget).
- [`connInfoSecretTargetDisabled`](#spec.connInfoSecretTargetDisabled-property){: name='spec.connInfoSecretTargetDisabled-property'} (boolean, Immutable). When true, the secret containing connection information will not be created, defaults to false. This field cannot be changed after resource creation.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `(?i)^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`maintenanceWindowDow`](#spec.maintenanceWindowDow-property){: name='spec.maintenanceWindowDow-property'} (string, Enum: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`). Day of week when maintenance operations should be performed. One monday, tuesday, wednesday, etc.
- [`maintenanceWindowTime`](#spec.maintenanceWindowTime-property){: name='spec.maintenanceWindowTime-property'} (string, MaxLength: 8). Time of day when maintenance operations should be performed. UTC time in HH:mm:ss format.
- [`projectVPCRef`](#spec.projectVPCRef-property){: name='spec.projectVPCRef-property'} (object). ProjectVPCRef reference to ProjectVPC resource to use its ID as ProjectVPCID automatically. See below for [nested schema](#spec.projectVPCRef).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api-reference/grafana.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GrafanaSpec defines the desired state of Grafana.
- [`cloudName`](#spec.cloudName-property){: name='spec.cloudName-property'} (string, MaxLength: 256). Cloud the service runs in.
- [`connInfoSecretTarget`](#spec.connInfoSecretTarget-property){: name='spec.connInfoSecretTarget-property'} (object). Secret configuration. See below for [nested schema](#spec.connInfoSecretTarget).
- [`connInfoSecretTargetDisabled`](#spec.connInfoSecretTargetDisabled-property){: name='spec.connInfoSecretTargetDisabled-property'} (boolean, Immutable). When true, the secret containing connection information will not be created, defaults to false. This field cannot be changed after resource creation.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `(?i)^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`maintenanceWindowDow`](#spec.maintenanceWindowDow-property){: name='spec.maintenanceWindowDow-property'} (string, Enum: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`). Day of week when maintenance operations should be performed. One monday, tuesday, wednesday, etc.
- [`maintenanceWindowTime`](#spec.maintenanceWindowTime-property){: name='spec.maintenanceWindowTime-property'} (string, MaxLength: 8). Time of day when maintenance operations should be performed. UTC time in HH:mm:ss format.
- [`projectVPCRef`](#spec.projectVPCRef-property){: name='spec.projectVPCRef-property'} (object). ProjectVPCRef reference to ProjectVPC resource to use its ID as ProjectVPCID automatically. See below for [nested schema](#spec.projectVPCRef).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api-reference/kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ KafkaSpec defines the desired state of Kafka.
- [`cloudName`](#spec.cloudName-property){: name='spec.cloudName-property'} (string, MaxLength: 256). Cloud the service runs in.
- [`connInfoSecretTarget`](#spec.connInfoSecretTarget-property){: name='spec.connInfoSecretTarget-property'} (object). Secret configuration. See below for [nested schema](#spec.connInfoSecretTarget).
- [`connInfoSecretTargetDisabled`](#spec.connInfoSecretTargetDisabled-property){: name='spec.connInfoSecretTargetDisabled-property'} (boolean, Immutable). When true, the secret containing connection information will not be created, defaults to false. This field cannot be changed after resource creation.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `(?i)^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`karapace`](#spec.karapace-property){: name='spec.karapace-property'} (boolean). Switch the service to use Karapace for schema registry and REST proxy.
- [`maintenanceWindowDow`](#spec.maintenanceWindowDow-property){: name='spec.maintenanceWindowDow-property'} (string, Enum: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`). Day of week when maintenance operations should be performed. One monday, tuesday, wednesday, etc.
- [`maintenanceWindowTime`](#spec.maintenanceWindowTime-property){: name='spec.maintenanceWindowTime-property'} (string, MaxLength: 8). Time of day when maintenance operations should be performed. UTC time in HH:mm:ss format.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api-reference/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MySQLSpec defines the desired state of MySQL.
- [`cloudName`](#spec.cloudName-property){: name='spec.cloudName-property'} (string, MaxLength: 256). Cloud the service runs in.
- [`connInfoSecretTarget`](#spec.connInfoSecretTarget-property){: name='spec.connInfoSecretTarget-property'} (object). Secret configuration. See below for [nested schema](#spec.connInfoSecretTarget).
- [`connInfoSecretTargetDisabled`](#spec.connInfoSecretTargetDisabled-property){: name='spec.connInfoSecretTargetDisabled-property'} (boolean, Immutable). When true, the secret containing connection information will not be created, defaults to false. This field cannot be changed after resource creation.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`disk_space`](#spec.disk_space-property){: name='spec.disk_space-property'} (string, Pattern: `(?i)^[1-9][0-9]*(GiB|G)?$`). The disk space of the service, possible values depend on the service type, the cloud provider and the project. Reducing will result in the service re-balancing. The removal of this field does not change the value.
- [`maintenanceWindowDow`](#spec.maintenanceWindowDow-property){: name='spec.maintenanceWindowDow-property'} (string, Enum: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`). Day of week when maintenance operations should be performed. One monday, tuesday, wednesday, etc.
- [`maintenanceWindowTime`](#spec.maintenanceWindowTime-property){: name='spec.maintenanceWindowTime-property'} (string, MaxLength: 8). Time of day when maintenance operations should be performed. UTC time in HH:mm:ss format.
- [`projectVPCRef`](#spec.projectVPCRef-property){: name='spec.projectVPCRef-property'} (object). ProjectVPCRef reference to ProjectVPC resource to use its ID as ProjectVPCID automatically. See below for [nested schema](#spec.projectVPCRef).
Expand Down
Loading

0 comments on commit 52c43fe

Please sign in to comment.