Skip to content
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
8 changes: 8 additions & 0 deletions api/v1alpha1/flavor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ type FlavorResourceSpec struct {
// +optional
Name *OpenStackName `json:"name,omitempty"`

// id will be the id of the created resource. If not specified, a random
// UUID will be generated by OpenStack.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=255
// +kubebuilder:validation:Pattern=^[a-zA-Z0-9._-]([a-zA-Z0-9. _-]*[a-zA-Z0-9._-])?$
// +optional
ID string `json:"id,omitempty"` //nolint:kubeapilinter // intentionally allow raw ID

// description contains a free form description of the flavor.
// +kubebuilder:validation:MinLength:=1
// +kubebuilder:validation:MaxLength:=65535
Expand Down
7 changes: 7 additions & 0 deletions cmd/models-schema/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/openstack.k-orc.cloud_flavors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ spec:
format: int32
minimum: 0
type: integer
id:
description: |-
id will be the id of the created resource. If not specified, a random
UUID will be generated by OpenStack.
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9._-]([a-zA-Z0-9. _-]*[a-zA-Z0-9._-])?$
type: string
isPublic:
description: isPublic flags a flavor as being available to all
projects or not.
Expand Down
1 change: 1 addition & 0 deletions internal/controllers/flavor/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (actuator flavorActuator) CreateResource(ctx context.Context, obj orcObject
IsPublic: resource.IsPublic,
Ephemeral: ptr.To(int(resource.Ephemeral)),
Description: ptr.Deref(resource.Description, ""),
ID: resource.ID,
}

osResource, err := actuator.osClient.CreateFlavor(ctx, createOpts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Flavor
metadata:
name: flavor-create-full
status:
id: testId-123
resource:
name: flavor-create-full-override
description: Flavor from "create full" test
Expand All @@ -12,4 +13,4 @@ status:
disk: 20
swap: 2
isPublic: false
ephemeral: 1
ephemeral: 1
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ spec:
swap: 2
isPublic: false
ephemeral: 1
id: testId-123

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/clients/applyconfiguration/internal/internal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion test/apivalidations/flavor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ var _ = Describe("ORC Flavor API validations", func() {
maxString := strings.Repeat("a", 65536)
patch.Spec.WithResource(applyconfigv1alpha1.FlavorResourceSpec().WithRAM(1).WithVcpus(1).WithDescription(maxString))
Expect(applyObj(ctx, flavor, patch)).To(MatchError(ContainSubstring("spec.resource.description: Too long")))

})

It("should reject import filter with value less than minimal", func(ctx context.Context) {
Expand All @@ -149,4 +148,20 @@ var _ = Describe("ORC Flavor API validations", func() {
WithFilter(applyconfigv1alpha1.FlavorFilter().WithRAM(0)))
Expect(applyObj(ctx, flavor, patch)).To(MatchError(ContainSubstring("spec.import.filter.ram in body should be greater than or equal to 1")))
})

It("should reject flavor IDs which are not according to the specified regex", func(ctx context.Context) {
flavor := flavorStub(namespace)
patch := baseFlavorPatch(flavor)
maxString := strings.Repeat("a", 256)
patch.Spec.WithResource(applyconfigv1alpha1.FlavorResourceSpec().WithID(" test").WithRAM(1).WithVcpus(1).WithDescription("test").WithDisk(1))
Expect(applyObj(ctx, flavor, patch)).To(MatchError(ContainSubstring("spec.resource.id: Invalid value")))
patch.Spec.WithResource(applyconfigv1alpha1.FlavorResourceSpec().WithID("test ").WithRAM(1).WithVcpus(1).WithDescription("test").WithDisk(1))
Expect(applyObj(ctx, flavor, patch)).To(MatchError(ContainSubstring("spec.resource.id: Invalid value")))
patch.Spec.WithResource(applyconfigv1alpha1.FlavorResourceSpec().WithID(maxString).WithRAM(1).WithVcpus(1).WithDescription("test").WithDisk(1))
Expect(applyObj(ctx, flavor, patch)).To(MatchError(ContainSubstring("spec.resource.id: Too long")))
patch.Spec.WithResource(applyconfigv1alpha1.FlavorResourceSpec().WithID("").WithRAM(1).WithVcpus(1).WithDescription("test").WithDisk(1))
Expect(applyObj(ctx, flavor, patch)).To(MatchError(ContainSubstring("spec.resource.id in body should be at least 1 chars long")))
patch.Spec.WithResource(applyconfigv1alpha1.FlavorResourceSpec().WithID("test.id -123_").WithRAM(1).WithVcpus(1).WithDescription("test").WithDisk(1))
Expect(applyObj(ctx, flavor, patch)).To(Succeed())
})
})
1 change: 1 addition & 0 deletions website/docs/crd-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `name` _[OpenStackName](#openstackname)_ | name will be the name of the created resource. If not specified, the<br />name of the ORC object will be used. | | MaxLength: 255 <br />MinLength: 1 <br />Pattern: `^[^,]+$` <br />Optional: \{\} <br /> |
| `id` _string_ | id will be the id of the created resource. If not specified, a random<br />UUID will be generated by OpenStack. | | MaxLength: 255 <br />MinLength: 1 <br />Pattern: `^[a-zA-Z0-9._-]([a-zA-Z0-9. _-]*[a-zA-Z0-9._-])?$` <br />Optional: \{\} <br /> |
| `description` _string_ | description contains a free form description of the flavor. | | MaxLength: 65535 <br />MinLength: 1 <br />Optional: \{\} <br /> |
| `ram` _integer_ | ram is the memory of the flavor, measured in MB. | | Minimum: 1 <br />Required: \{\} <br /> |
| `vcpus` _integer_ | vcpus is the number of vcpus for the flavor. | | Minimum: 1 <br />Required: \{\} <br /> |
Expand Down
Loading