Skip to content

Commit

Permalink
feat(gcpNfsVolume): preventing reduction of capacity for BASIC tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
abalaie committed Dec 20, 2024
1 parent 7902bc2 commit 24cea7a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/cloud-resources/v1beta1/gcpnfsvolume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ const (
// +kubebuilder:validation:XValidation:rule=(self.tier != "ZONAL" || self.tier == "ZONAL" && size(self.fileShareName) <= 64), message="ZONAL tier fileShareName length must be 64 or less characters"
// +kubebuilder:validation:XValidation:rule=(self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && self.capacityGb >= 2560 && self.capacityGb <= 65400), message="BASIC_SSD tier capacityGb must be between 2560 and 65400"
// +kubebuilder:validation:XValidation:rule=(self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && size(self.fileShareName) <= 16), message="BASIC_SSD tier fileShareName length must be 16 or less characters"
// +kubebuilder:validation:XValidation:rule=(self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && self.capacityGb >= oldSelf.capacityGb), message="BASIC_SSD tier capacityGb cannot be reduced"
// +kubebuilder:validation:XValidation:rule=(self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && self.capacityGb >= 1024 && self.capacityGb <= 65400), message="BASIC_HDD tier capacityGb must be between 1024 and 65400"
// +kubebuilder:validation:XValidation:rule=(self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && size(self.fileShareName) <= 16), message="BASIC_HDD tier fileShareName length must be 16 or less characters"
// +kubebuilder:validation:XValidation:rule=(self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && self.capacityGb >= oldSelf.capacityGb), message="BASIC_HDD tier capacityGb cannot be reduced"
type GcpNfsVolumeSpec struct {
// +optional
// +kubebuilder:validation:XValidation:rule=(self == oldSelf), message="IpRange is immutable."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
cloud-resources.kyma-project.io/version: v0.0.7
cloud-resources.kyma-project.io/version: v0.0.8
name: gcpnfsvolumes.cloud-resources.kyma-project.io
spec:
group: cloud-resources.kyma-project.io
Expand Down Expand Up @@ -153,10 +153,14 @@ spec:
rule: (self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && self.capacityGb >= 2560 && self.capacityGb <= 65400)
- message: BASIC_SSD tier fileShareName length must be 16 or less characters
rule: (self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && size(self.fileShareName) <= 16)
- message: BASIC_SSD tier capacityGb cannot be reduced
rule: (self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && self.capacityGb >= oldSelf.capacityGb)
- message: BASIC_HDD tier capacityGb must be between 1024 and 65400
rule: (self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && self.capacityGb >= 1024 && self.capacityGb <= 65400)
- message: BASIC_HDD tier fileShareName length must be 16 or less characters
rule: (self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && size(self.fileShareName) <= 16)
- message: BASIC_HDD tier capacityGb cannot be reduced
rule: (self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && self.capacityGb >= oldSelf.capacityGb)
status:
description: GcpNfsVolumeStatus defines the observed state of GcpNfsVolume
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
cloud-resources.kyma-project.io/version: v0.0.7
cloud-resources.kyma-project.io/version: v0.0.8
name: gcpnfsvolumes.cloud-resources.kyma-project.io
spec:
group: cloud-resources.kyma-project.io
Expand Down Expand Up @@ -153,10 +153,14 @@ spec:
rule: (self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && self.capacityGb >= 2560 && self.capacityGb <= 65400)
- message: BASIC_SSD tier fileShareName length must be 16 or less characters
rule: (self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && size(self.fileShareName) <= 16)
- message: BASIC_SSD tier capacityGb cannot be reduced
rule: (self.tier != "BASIC_SSD" || self.tier == "BASIC_SSD" && self.capacityGb >= oldSelf.capacityGb)
- message: BASIC_HDD tier capacityGb must be between 1024 and 65400
rule: (self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && self.capacityGb >= 1024 && self.capacityGb <= 65400)
- message: BASIC_HDD tier fileShareName length must be 16 or less characters
rule: (self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && size(self.fileShareName) <= 16)
- message: BASIC_HDD tier capacityGb cannot be reduced
rule: (self.tier != "BASIC_HDD" || self.tier == "BASIC_HDD" && self.capacityGb >= oldSelf.capacityGb)
status:
description: GcpNfsVolumeStatus defines the observed state of GcpNfsVolume
properties:
Expand Down
2 changes: 1 addition & 1 deletion config/patchAfterMakeManifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.1.1
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.3"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_awsnfsvolumes.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.3"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_awsnfsvolumebackups.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.16"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_awsredisinstances.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.7"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_gcpnfsvolumes.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.8"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_gcpnfsvolumes.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.18"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_gcpredisinstances.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.2"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_azurevpcpeerings.yaml
yq -i '.metadata.annotations."cloud-resources.kyma-project.io/version" = "v0.0.54"' $SCRIPT_DIR/crd/bases/cloud-resources.kyma-project.io_azureredisinstances.yaml
Expand Down
44 changes: 44 additions & 0 deletions internal/api-tests/skr_gcpnfsvolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ var _ = Describe("Feature: SKR GcpNfsVolume", Ordered, func() {
newTestGcpNfsVolumeBuilder().WithTier(tier).WithCapacityGb(1024).WithFileShareName(fileShareName65char),
fmt.Sprintf("%s tier fileShareName length must be 64 or less characters", tier),
)
canChangeSkr(
fmt.Sprintf("GcpNfsVolume %s tier instance capacity can be increased", tier),
newTestGcpNfsVolumeBuilder().WithTier(tier).WithCapacityGb(1024).WithValidFileShareName(),
func(b Builder[*cloudresourcesv1beta1.GcpNfsVolume]) {
b.(*testGcpNfsVolumeBuilder).WithCapacityGb(1280)
},
)
canChangeSkr(
fmt.Sprintf("GcpNfsVolume %s tier instance capacity can be reduced", tier),
newTestGcpNfsVolumeBuilder().WithTier(tier).WithCapacityGb(1280).WithValidFileShareName(),
func(b Builder[*cloudresourcesv1beta1.GcpNfsVolume]) {
b.(*testGcpNfsVolumeBuilder).WithCapacityGb(1024)
},
)
}

for _, validCapacity := range []int{2560, 2561, 65399, 65400} {
Expand All @@ -97,6 +111,21 @@ var _ = Describe("Feature: SKR GcpNfsVolume", Ordered, func() {
newTestGcpNfsVolumeBuilder().WithTier(cloudresourcesv1beta1.BASIC_SSD).WithCapacityGb(1024).WithFileShareName(fileShareName17char),
"BASIC_SSD tier fileShareName length must be 16 or less characters",
)
canChangeSkr(
"GcpNfsVolume BASIC_SSD tier instance capacity can be increased",
newTestGcpNfsVolumeBuilder().WithTier(cloudresourcesv1beta1.BASIC_SSD).WithCapacityGb(2560).WithValidFileShareName(),
func(b Builder[*cloudresourcesv1beta1.GcpNfsVolume]) {
b.(*testGcpNfsVolumeBuilder).WithCapacityGb(2561)
},
)
canNotChangeSkr(
"GcpNfsVolume BASIC_SSD tier instance capacity can not be reduced",
newTestGcpNfsVolumeBuilder().WithTier(cloudresourcesv1beta1.BASIC_SSD).WithCapacityGb(2561).WithValidFileShareName(),
func(b Builder[*cloudresourcesv1beta1.GcpNfsVolume]) {
b.(*testGcpNfsVolumeBuilder).WithCapacityGb(2560)
},
"BASIC_SSD tier capacityGb cannot be reduced",
)

for _, validCapacity := range []int{1024, 1025, 65399, 65400} {
canCreateSkr(
Expand All @@ -116,6 +145,21 @@ var _ = Describe("Feature: SKR GcpNfsVolume", Ordered, func() {
newTestGcpNfsVolumeBuilder().WithTier(cloudresourcesv1beta1.BASIC_HDD).WithCapacityGb(1024).WithFileShareName(fileShareName17char),
"BASIC_HDD tier fileShareName length must be 16 or less characters",
)
canChangeSkr(
"GcpNfsVolume BASIC_HDD tier instance capacity can be increased",
newTestGcpNfsVolumeBuilder().WithTier(cloudresourcesv1beta1.BASIC_HDD).WithCapacityGb(1024).WithValidFileShareName(),
func(b Builder[*cloudresourcesv1beta1.GcpNfsVolume]) {
b.(*testGcpNfsVolumeBuilder).WithCapacityGb(1025)
},
)
canNotChangeSkr(
"GcpNfsVolume BASIC_HDD tier instance capacity can not be reduced",
newTestGcpNfsVolumeBuilder().WithTier(cloudresourcesv1beta1.BASIC_HDD).WithCapacityGb(1025).WithValidFileShareName(),
func(b Builder[*cloudresourcesv1beta1.GcpNfsVolume]) {
b.(*testGcpNfsVolumeBuilder).WithCapacityGb(1024)
},
"BASIC_HDD tier capacityGb cannot be reduced",
)

for _, removedTier := range []string{"STANDARD", "PREMIUM", "HIGH_SCALE_SSD", "ENTERPRISE"} {
canNotCreateSkr(
Expand Down

0 comments on commit 24cea7a

Please sign in to comment.