Skip to content

Commit e0be45e

Browse files
authored
Merge pull request #163 from Liujingfang1/master
Enhancement on sample projects for validation annotation
2 parents 0724374 + 9ca2f7a commit e0be45e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

samples/memcached-api-server/pkg/apis/myapps/v1alpha1/memcached_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
// MemcachedSpec defines the desired state of Memcached
1313
type MemcachedSpec struct {
1414
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
15+
// +kubebuilder:validation:Maximum=100
16+
// +kubebuilder:validation:Minimum=5
1517
Size int32 `json:"size"`
1618
}
1719

samples/memcached-api-server/pkg/apis/myapps/v1alpha1/memcached_types_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var _ = Describe("Memcached", func() {
2121
BeforeEach(func() {
2222
instance = Memcached{}
2323
instance.Name = "instance-1"
24+
instance.Spec.Size = 50
2425

2526
expected = instance
2627
})

samples/memcached-api-server/pkg/controller/memcached/controller_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,19 @@ var _ = Describe("Memcached controller", func() {
4848

4949
// Create the instance
5050
client = cs.MyappsV1alpha1().Memcacheds("default")
51+
52+
instance.Spec.Size = 1
5153
_, err := client.Create(&instance)
54+
Expect(err).Should(HaveOccurred())
55+
Expect(err.Error()).Should(MatchRegexp(".*spec.size in body should be greater than or equal to 5.*"))
56+
57+
instance.Spec.Size = 101
58+
_, err = client.Create(&instance)
59+
Expect(err).Should(HaveOccurred())
60+
Expect(err.Error()).Should(MatchRegexp(".*spec.size in body should be less than or equal to 100.*"))
61+
62+
instance.Spec.Size = 50
63+
_, err = client.Create(&instance)
5264
Expect(err).ShouldNot(HaveOccurred())
5365

5466
// Wait for reconcile to happen

0 commit comments

Comments
 (0)