Skip to content

Commit 434d010

Browse files
committed
address Bucket API review changes
Address API review recommended changes for Bucket resource. Signed-off-by: Blaine Gardner <blaine.gardner@ibm.com>
1 parent f3bf0f5 commit 434d010

File tree

12 files changed

+277
-43
lines changed

12 files changed

+277
-43
lines changed

client/apis/objectstorage/v1alpha2/bucket_types.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ const (
4242
// +kubebuilder:validation:XValidation:message="existingBucketID cannot be added or removed after creation",rule="has(oldSelf.existingBucketID) == has(self.existingBucketID)"
4343
type BucketSpec struct {
4444
// driverName is the name of the driver that fulfills requests for this Bucket.
45+
// Must be 63 characters or less, beginning and ending with an alphanumeric character
46+
// ([a-z0-9A-Z]) with dashes (-), dots (.), and alphanumerics between.
4547
// +required
46-
// +kubebuilder:validation:MinLength=1
4748
// +kubebuilder:validation:XValidation:message="driverName is immutable",rule="self == oldSelf"
48-
DriverName string `json:"driverName,omitempty"`
49+
DriverName DriverName `json:"driverName,omitempty"`
4950

5051
// deletionPolicy determines whether a Bucket should be deleted when its bound BucketClaim is
5152
// deleted. This is mutable to allow Admins to change the policy after creation.
@@ -58,52 +59,68 @@ type BucketSpec struct {
5859
// parameters is an opaque map of driver-specific configuration items passed to the driver that
5960
// fulfills requests for this Bucket.
6061
// +optional
62+
// +kubebuilder:validation:MinProperties=1
6163
// +kubebuilder:validation:XValidation:message="parameters map is immutable",rule="self == oldSelf"
6264
Parameters map[string]string `json:"parameters,omitempty"`
6365

6466
// protocols lists object store protocols that the provisioned Bucket must support.
6567
// If specified, COSI will verify that each item is advertised as supported by the driver.
68+
// Possible values: 'S3', 'Azure', 'GCS'.
6669
// +optional
6770
// +listType=set
6871
// +kubebuilder:validation:XValidation:message="protocols list is immutable",rule="self == oldSelf"
6972
Protocols []ObjectProtocol `json:"protocols,omitempty"`
7073

71-
// bucketClaim references the BucketClaim that resulted in the creation of this Bucket.
74+
// bucketClaimRef references the BucketClaim that resulted in the creation of this Bucket.
7275
// For statically-provisioned buckets, set the namespace and name of the BucketClaim that is
7376
// allowed to bind to this Bucket.
7477
// +required
75-
BucketClaimRef BucketClaimReference `json:"bucketClaim,omitzero"`
78+
BucketClaimRef BucketClaimReference `json:"bucketClaimRef,omitzero"`
7679

7780
// existingBucketID is the unique identifier for an existing backend bucket known to the driver.
7881
// Use driver documentation to determine how to set this value.
79-
// This field is used only for Bucket static provisioning.
82+
// This field is used only for static Bucket provisioning.
8083
// This field will be empty when the Bucket is dynamically provisioned from a BucketClaim.
84+
// Must be at most 2048 characters and consist only of alphanumeric characters ([a-z0-9A-Z]),
85+
// dashes (-), dots (.), and underscores (_).
8186
// +optional
82-
// +kubebuilder:validation:MinLength=1
8387
// +kubebuilder:validation:XValidation:message="existingBucketID is immutable",rule="self == oldSelf"
84-
ExistingBucketID string `json:"existingBucketID,omitempty"`
88+
ExistingBucketID DriverResourceID `json:"existingBucketID,omitempty"`
8589
}
8690

8791
// BucketClaimReference is a reference to a BucketClaim object.
8892
// +kubebuilder:validation:XValidation:message="namespace cannot be removed once set",rule="!has(oldSelf.namespace) || has(self.namespace)"
8993
// +kubebuilder:validation:XValidation:message="uid cannot be removed once set",rule="!has(oldSelf.uid) || has(self.uid)"
9094
type BucketClaimReference struct {
9195
// name is the name of the BucketClaim being referenced.
96+
// Must be a valid Kubernetes resource name: at most 253 characters, consisting only of
97+
// lower-case alphanumeric characters, hyphens, and periods, starting and ending with an
98+
// alphanumeric character.
9299
// +required
93100
// +kubebuilder:validation:MinLength=1
94101
// +kubebuilder:validation:MaxLength=253
102+
// +kubebuilder:validation:XValidation:message="name must be a valid resource name",rule="!format.dns1123Subdomain().validate(self).hasValue()"
95103
// +kubebuilder:validation:XValidation:message="name is immutable",rule="self == oldSelf"
96104
Name string `json:"name,omitempty"`
97105

98106
// namespace is the namespace of the BucketClaim being referenced.
107+
// Must be a valid Kubernetes Namespace name: at most 63 characters, consisting only of
108+
// lower-case alphanumeric characters and hyphens, starting and ending with alphanumerics.
99109
// +required
100110
// +kubebuilder:validation:MinLength=1
101-
// +kubebuilder:validation:MaxLength=253
111+
// +kubebuilder:validation:MaxLength=63
112+
// +kubebuilder:validation:XValidation:message="namespace must be a valid namespace name",rule="!format.dns1123Label().validate(self).hasValue()"
102113
// +kubebuilder:validation:XValidation:message="namespace is immutable",rule="self == oldSelf"
103114
Namespace string `json:"namespace,omitempty"`
104115

105116
// uid is the UID of the BucketClaim being referenced.
117+
// Must be a valid Kubernetes UID: RFC 4122 form with lowercase hexadecimal characters
118+
// (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
106119
// +optional
120+
// +kubebuilder:validation:MinLength=36
121+
// +kubebuilder:validation:MaxLength=36
122+
// +kubebuilder:validation:Type=string
123+
// +kubebuilder:validation:Pattern=`^[0-9a-f]{8}-([0-9a-f]{4}\-){3}[0-9a-f]{12}$`
107124
// +kubebuilder:validation:XValidation:message="uid is immutable once set",rule="oldSelf == '' || self == oldSelf"
108125
UID types.UID `json:"uid,omitempty"`
109126
}
@@ -117,13 +134,15 @@ type BucketStatus struct {
117134
ReadyToUse *bool `json:"readyToUse,omitempty"`
118135

119136
// bucketID is the unique identifier for the backend bucket known to the driver.
137+
// Must be at most 2048 characters and consist only of alphanumeric characters ([a-z0-9A-Z]),
138+
// dashes (-), dots (.), and underscores (_).
120139
// +optional
121-
// +kubebuilder:validation:MinLength=1
122140
// +kubebuilder:validation:XValidation:message="boundBucketName is immutable once set",rule="self == oldSelf"
123-
BucketID string `json:"bucketID,omitempty"`
141+
BucketID DriverResourceID `json:"bucketID,omitempty"`
124142

125143
// protocols is the set of protocols the Bucket reports to support. BucketAccesses can request
126144
// access to this BucketClaim using any of the protocols reported here.
145+
// Possible values: 'S3', 'Azure', 'GCS'.
127146
// +optional
128147
// +listType=set
129148
Protocols []ObjectProtocol `json:"protocols,omitempty"`

client/apis/objectstorage/v1alpha2/shared_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ import (
2727
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
)
2929

30+
// DriverName represents the name of a driver.
31+
// Must be 63 characters or less, beginning and ending with an alphanumeric character
32+
// ([a-z0-9A-Z]) with dashes (-), dots (.), and alphanumerics between.
33+
// +kubebuilder:validation:MinLength=1
34+
// +kubebuilder:validation:MaxLength=63
35+
// +kubebuilder:validation:Pattern=`^[a-zA-Z0-9]([a-zA-Z0-9\-\.]{0,61}[a-zA-Z0-9])?$`
36+
type DriverName string
37+
38+
// DriverResourceID represents a unique identifier for a driver bucket or access resource.
39+
// To prevent misuse, a driver resource ID must be at most 2048 characters and consist only of
40+
// alphanumeric characters ([a-z0-9A-Z]), dashes (-), dots (.), and underscores (_).
41+
// +kubebuilder:validation:MinLength=1
42+
// +kubebuilder:validation:MaxLength=2048
43+
// +kubebuilder:validation:Pattern=`^[a-zA-Z0-9._-]+$`
44+
type DriverResourceID string
45+
3046
// TimestampedError contains an error message with timestamp.
3147
type TimestampedError struct {
3248
// time is the timestamp when the error was encountered.

client/config/crd/objectstorage.k8s.io_buckets.yaml

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,47 @@ spec:
4040
spec:
4141
description: spec defines the desired state of Bucket
4242
properties:
43-
bucketClaim:
43+
bucketClaimRef:
4444
description: |-
45-
bucketClaim references the BucketClaim that resulted in the creation of this Bucket.
45+
bucketClaimRef references the BucketClaim that resulted in the creation of this Bucket.
4646
For statically-provisioned buckets, set the namespace and name of the BucketClaim that is
4747
allowed to bind to this Bucket.
4848
properties:
4949
name:
50-
description: name is the name of the BucketClaim being referenced.
50+
description: |-
51+
name is the name of the BucketClaim being referenced.
52+
Must be a valid Kubernetes resource name: at most 253 characters, consisting only of
53+
lower-case alphanumeric characters, hyphens, and periods, starting and ending with an
54+
alphanumeric character.
5155
maxLength: 253
5256
minLength: 1
5357
type: string
5458
x-kubernetes-validations:
59+
- message: name must be a valid resource name
60+
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
5561
- message: name is immutable
5662
rule: self == oldSelf
5763
namespace:
58-
description: namespace is the namespace of the BucketClaim being
59-
referenced.
60-
maxLength: 253
64+
description: |-
65+
namespace is the namespace of the BucketClaim being referenced.
66+
Must be a valid Kubernetes Namespace name: at most 63 characters, consisting only of
67+
lower-case alphanumeric characters and hyphens, starting and ending with alphanumerics.
68+
maxLength: 63
6169
minLength: 1
6270
type: string
6371
x-kubernetes-validations:
72+
- message: namespace must be a valid namespace name
73+
rule: '!format.dns1123Label().validate(self).hasValue()'
6474
- message: namespace is immutable
6575
rule: self == oldSelf
6676
uid:
67-
description: uid is the UID of the BucketClaim being referenced.
77+
description: |-
78+
uid is the UID of the BucketClaim being referenced.
79+
Must be a valid Kubernetes UID: RFC 4122 form with lowercase hexadecimal characters
80+
(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
81+
maxLength: 36
82+
minLength: 36
83+
pattern: ^[0-9a-f]{8}-([0-9a-f]{4}\-){3}[0-9a-f]{12}$
6884
type: string
6985
x-kubernetes-validations:
7086
- message: uid is immutable once set
@@ -90,9 +106,13 @@ spec:
90106
- Delete
91107
type: string
92108
driverName:
93-
description: driverName is the name of the driver that fulfills requests
94-
for this Bucket.
109+
description: |-
110+
driverName is the name of the driver that fulfills requests for this Bucket.
111+
Must be 63 characters or less, beginning and ending with an alphanumeric character
112+
([a-z0-9A-Z]) with dashes (-), dots (.), and alphanumerics between.
113+
maxLength: 63
95114
minLength: 1
115+
pattern: ^[a-zA-Z0-9]([a-zA-Z0-9\-\.]{0,61}[a-zA-Z0-9])?$
96116
type: string
97117
x-kubernetes-validations:
98118
- message: driverName is immutable
@@ -101,9 +121,13 @@ spec:
101121
description: |-
102122
existingBucketID is the unique identifier for an existing backend bucket known to the driver.
103123
Use driver documentation to determine how to set this value.
104-
This field is used only for Bucket static provisioning.
124+
This field is used only for static Bucket provisioning.
105125
This field will be empty when the Bucket is dynamically provisioned from a BucketClaim.
126+
Must be at most 2048 characters and consist only of alphanumeric characters ([a-z0-9A-Z]),
127+
dashes (-), dots (.), and underscores (_).
128+
maxLength: 2048
106129
minLength: 1
130+
pattern: ^[a-zA-Z0-9._-]+$
107131
type: string
108132
x-kubernetes-validations:
109133
- message: existingBucketID is immutable
@@ -114,6 +138,7 @@ spec:
114138
description: |-
115139
parameters is an opaque map of driver-specific configuration items passed to the driver that
116140
fulfills requests for this Bucket.
141+
minProperties: 1
117142
type: object
118143
x-kubernetes-validations:
119144
- message: parameters map is immutable
@@ -122,6 +147,7 @@ spec:
122147
description: |-
123148
protocols lists object store protocols that the provisioned Bucket must support.
124149
If specified, COSI will verify that each item is advertised as supported by the driver.
150+
Possible values: 'S3', 'Azure', 'GCS'.
125151
items:
126152
description: ObjectProtocol represents an object protocol type.
127153
enum:
@@ -135,7 +161,7 @@ spec:
135161
- message: protocols list is immutable
136162
rule: self == oldSelf
137163
required:
138-
- bucketClaim
164+
- bucketClaimRef
139165
- deletionPolicy
140166
- driverName
141167
type: object
@@ -150,9 +176,13 @@ spec:
150176
description: status defines the observed state of Bucket
151177
properties:
152178
bucketID:
153-
description: bucketID is the unique identifier for the backend bucket
154-
known to the driver.
179+
description: |-
180+
bucketID is the unique identifier for the backend bucket known to the driver.
181+
Must be at most 2048 characters and consist only of alphanumeric characters ([a-z0-9A-Z]),
182+
dashes (-), dots (.), and underscores (_).
183+
maxLength: 2048
155184
minLength: 1
185+
pattern: ^[a-zA-Z0-9._-]+$
156186
type: string
157187
x-kubernetes-validations:
158188
- message: boundBucketName is immutable once set
@@ -185,6 +215,7 @@ spec:
185215
description: |-
186216
protocols is the set of protocols the Bucket reports to support. BucketAccesses can request
187217
access to this BucketClaim using any of the protocols reported here.
218+
Possible values: 'S3', 'Azure', 'GCS'.
188219
items:
189220
description: ObjectProtocol represents an object protocol type.
190221
enum:

0 commit comments

Comments
 (0)