Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix server metadata length validation #1964

Merged
merged 1 commit into from
Mar 20, 2024
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
6 changes: 4 additions & 2 deletions api/v1beta1/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ type OpenStackMachineSpec struct {

type ServerMetadata struct {
// Key is the server metadata key
// kubebuilder:validation:MaxLength:=255
// +kubebuilder:validation:MaxLength:=255
// +kubebuilder:validation:Required
Key string `json:"key"`

// Value is the server metadata value
// kubebuilder:validation:MaxLength:=255
// +kubebuilder:validation:MaxLength:=255
// +kubebuilder:validation:Required
Value string `json:"value"`
}

Expand Down

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

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

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

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

6 changes: 2 additions & 4 deletions docs/book/src/api/v1beta1/api.md

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

31 changes: 31 additions & 0 deletions test/e2e/suites/apivalidations/openstackmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package apivalidations

import (
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -54,4 +56,33 @@ var _ = Describe("OpenStackMachine API validations", func() {
machine.Spec.ProviderID = pointer.String("bar")
Expect(k8sClient.Update(ctx, machine)).NotTo(Succeed(), "Updating providerID should fail")
})

It("should not allow server metadata to exceed 255 characters", func() {
By("Creating a machine with a metadata key that is too long")
machine.Spec.ServerMetadata = []infrav1.ServerMetadata{
{
Key: strings.Repeat("a", 256),
Value: "value",
},
}
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "Creating a machine with a long metadata key should fail")

By("Creating a machine with a metadata value that is too long")
machine.Spec.ServerMetadata = []infrav1.ServerMetadata{
{
Key: "key",
Value: strings.Repeat("a", 256),
},
}
Expect(k8sClient.Create(ctx, machine)).NotTo(Succeed(), "Creating a machine with a long metadata value should fail")

By("Creating a machine with a metadata key and value of 255 characters should succeed")
machine.Spec.ServerMetadata = []infrav1.ServerMetadata{
{
Key: strings.Repeat("a", 255),
Value: strings.Repeat("b", 255),
},
}
Expect(k8sClient.Create(ctx, machine)).To(Succeed(), "Creating a machine with max metadata key and value should succeed")
})
})