Skip to content

Commit 6b33e5f

Browse files
feat(api): Add external API structs for COSI objectstorage
add COSI objectstorage v1alpha1 APIs to external APIs dir.
1 parent a209459 commit 6b33e5f

File tree

9 files changed

+1002
-1
lines changed

9 files changed

+1002
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package,register
18+
// +groupName=objectstorage.k8s.io
19+
// +k8s:protobuf-gen=package
20+
// +k8s:openapi-gen=true
21+
// +kubebuilder:validation:Required
22+
23+
package v1alpha1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package v1alpha1
2+
3+
// COSI relevant event reasons
4+
const (
5+
FailedCreateBucket = "FailedCreateBucket"
6+
FailedDeleteBucket = "FailedDeleteBucket"
7+
WaitingForBucket = "WaitingForBucket"
8+
9+
FailedGrantAccess = "FailedGrantAccess"
10+
FailedRevokeAccess = "FailedRevokeAccess"
11+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
"sigs.k8s.io/container-object-storage-interface/client/apis/objectstorage"
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
var (
26+
// GroupVersion is group version used to register these objects
27+
SchemeGroupVersion = schema.GroupVersion{Group: objectstorage.GroupName, Version: "v1alpha1"}
28+
29+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
30+
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
31+
32+
// AddToScheme adds the types in this group-version to the given scheme.
33+
AddToScheme = SchemeBuilder.AddToScheme
34+
)
35+
36+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
37+
func Resource(resource string) schema.GroupResource {
38+
return SchemeGroupVersion.WithResource(resource).GroupResource()
39+
}
Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
func init() {
25+
SchemeBuilder.Register(&Bucket{}, &BucketList{})
26+
SchemeBuilder.Register(&BucketClaim{}, &BucketClaimList{})
27+
SchemeBuilder.Register(&BucketClass{}, &BucketClassList{})
28+
29+
SchemeBuilder.Register(&BucketAccess{}, &BucketAccessList{})
30+
SchemeBuilder.Register(&BucketAccessClass{}, &BucketAccessClassList{})
31+
}
32+
33+
type DeletionPolicy string
34+
35+
const (
36+
DeletionPolicyRetain DeletionPolicy = "Retain"
37+
DeletionPolicyDelete DeletionPolicy = "Delete"
38+
)
39+
40+
type Protocol string
41+
42+
const (
43+
ProtocolS3 Protocol = "S3"
44+
ProtocolAzure Protocol = "Azure"
45+
ProtocolGCP Protocol = "GCP"
46+
)
47+
48+
type AuthenticationType string
49+
50+
const (
51+
AuthenticationTypeKey AuthenticationType = "Key"
52+
AuthenticationTypeIAM AuthenticationType = "IAM"
53+
)
54+
55+
// +genclient
56+
// +genclient:nonNamespaced
57+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
58+
// +kubebuilder:resource:scope=Cluster
59+
// +kubebuilder:storageversion
60+
// +kubebuilder:subresource:status
61+
type Bucket struct {
62+
metav1.TypeMeta `json:",inline"`
63+
64+
// +optional
65+
metav1.ObjectMeta `json:"metadata,omitempty"`
66+
67+
Spec BucketSpec `json:"spec,omitempty"`
68+
69+
// +optional
70+
Status BucketStatus `json:"status,omitempty"`
71+
}
72+
73+
type BucketSpec struct {
74+
// DriverName is the name of driver associated with this bucket
75+
DriverName string `json:"driverName"`
76+
77+
// Name of the BucketClass specified in the BucketRequest
78+
BucketClassName string `json:"bucketClassName"`
79+
80+
// Name of the BucketClaim that resulted in the creation of this Bucket
81+
// In case the Bucket object was created manually, then this should refer
82+
// to the BucketClaim with which this Bucket should be bound
83+
BucketClaim *corev1.ObjectReference `json:"bucketClaim"`
84+
85+
// Protocols are the set of data APIs this bucket is expected to support.
86+
// The possible values for protocol are:
87+
// - S3: Indicates Amazon S3 protocol
88+
// - Azure: Indicates Microsoft Azure BlobStore protocol
89+
// - GCS: Indicates Google Cloud Storage protocol
90+
Protocols []Protocol `json:"protocols"`
91+
92+
// +optional
93+
Parameters map[string]string `json:"parameters,omitempty"`
94+
95+
// DeletionPolicy is used to specify how COSI should handle deletion of this
96+
// bucket. There are 2 possible values:
97+
// - Retain: Indicates that the bucket should not be deleted from the OSP (default)
98+
// - Delete: Indicates that the bucket should be deleted from the OSP
99+
// once all the workloads accessing this bucket are done
100+
// +optional
101+
// +kubebuilder:default:=Retain
102+
DeletionPolicy DeletionPolicy `json:"deletionPolicy"`
103+
104+
// ExistingBucketID is the unique id of the bucket in the OSP. This field should be
105+
// used to specify a bucket that has been created outside of COSI.
106+
// This field will be empty when the Bucket is dynamically provisioned by COSI.
107+
// +optional
108+
ExistingBucketID string `json:"existingBucketID,omitempty"`
109+
}
110+
111+
type BucketStatus struct {
112+
// BucketReady is a boolean condition to reflect the successful creation
113+
// of a bucket.
114+
BucketReady bool `json:"bucketReady,omitempty"`
115+
116+
// BucketID is the unique id of the bucket in the OSP. This field will be
117+
// populated by COSI.
118+
// +optional
119+
BucketID string `json:"bucketID,omitempty"`
120+
}
121+
122+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
123+
type BucketList struct {
124+
metav1.TypeMeta `json:",inline"`
125+
metav1.ListMeta `json:"metadata,omitempty"`
126+
Items []Bucket `json:"items"`
127+
}
128+
129+
// +genclient
130+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
131+
// +kubebuilder:resource:scope=Namespaced
132+
// +kubebuilder:subresource:status
133+
// +kubebuilder:storageversion
134+
type BucketClaim struct {
135+
metav1.TypeMeta `json:",inline"`
136+
137+
// +optional
138+
metav1.ObjectMeta `json:"metadata,omitempty"`
139+
140+
Spec BucketClaimSpec `json:"spec,omitempty"`
141+
142+
// +optional
143+
Status BucketClaimStatus `json:"status,omitempty"`
144+
}
145+
146+
type BucketClaimSpec struct {
147+
// Name of the BucketClass
148+
BucketClassName string `json:"bucketClassName,omitempty"`
149+
150+
// Protocols are the set of data API this bucket is required to support.
151+
// The possible values for protocol are:
152+
// - S3: Indicates Amazon S3 protocol
153+
// - Azure: Indicates Microsoft Azure BlobStore protocol
154+
// - GCS: Indicates Google Cloud Storage protocol
155+
Protocols []Protocol `json:"protocols"`
156+
157+
// Name of a bucket object that was manually
158+
// created to import a bucket created outside of COSI
159+
// If unspecified, then a new Bucket will be dynamically provisioned
160+
// +optional
161+
ExistingBucketName string `json:"existingBucketName,omitempty"`
162+
}
163+
164+
type BucketClaimStatus struct {
165+
// BucketReady indicates that the bucket is ready for consumpotion
166+
// by workloads
167+
BucketReady bool `json:"bucketReady"`
168+
169+
// BucketName is the name of the provisioned Bucket in response
170+
// to this BucketClaim. It is generated and set by the COSI controller
171+
// before making the creation request to the OSP backend.
172+
// +optional
173+
BucketName string `json:"bucketName,omitempty"`
174+
}
175+
176+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
177+
type BucketClaimList struct {
178+
metav1.TypeMeta `json:",inline"`
179+
metav1.ListMeta `json:"metadata,omitempty"`
180+
Items []BucketClaim `json:"items"`
181+
}
182+
183+
// +genclient
184+
// +genclient:nonNamespaced
185+
// +genclient:noStatus
186+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
187+
// +kubebuilder:resource:scope=Cluster
188+
// +kubebuilder:storageversion
189+
type BucketClass struct {
190+
metav1.TypeMeta `json:",inline"`
191+
192+
// +optional
193+
metav1.ObjectMeta `json:"metadata,omitempty"`
194+
195+
// DriverName is the name of driver associated with this bucket
196+
DriverName string `json:"driverName"`
197+
198+
// DeletionPolicy is used to specify how COSI should handle deletion of this
199+
// bucket. There are 2 possible values:
200+
// - Retain: Indicates that the bucket should not be deleted from the OSP
201+
// - Delete: Indicates that the bucket should be deleted from the OSP
202+
// once all the workloads accessing this bucket are done
203+
// +kubebuilder:default:=Retain
204+
DeletionPolicy DeletionPolicy `json:"deletionPolicy"`
205+
206+
// Parameters is an opaque map for passing in configuration to a driver
207+
// for creating the bucket
208+
// +optional
209+
Parameters map[string]string `json:"parameters,omitempty"`
210+
}
211+
212+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
213+
type BucketClassList struct {
214+
metav1.TypeMeta `json:",inline"`
215+
metav1.ListMeta `json:"metadata,omitempty"`
216+
Items []BucketClass `json:"items"`
217+
}
218+
219+
// +genclient
220+
// +genclient:nonNamespaced
221+
// +genclient:noStatus
222+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
223+
// +kubebuilder:resource:scope=Cluster
224+
// +kubebuilder:storageversion
225+
type BucketAccessClass struct {
226+
metav1.TypeMeta `json:",inline"`
227+
228+
// +optional
229+
metav1.ObjectMeta `json:"metadata,omitempty"`
230+
231+
// DriverName is the name of driver associated with
232+
// this BucketAccess
233+
DriverName string `json:"driverName"`
234+
235+
// AuthenticationType denotes the style of authentication
236+
// It can be one of
237+
// Key - access, secret tokens based authentication
238+
// IAM - implicit authentication of pods to the OSP based on service account mappings
239+
AuthenticationType AuthenticationType `json:"authenticationType"`
240+
241+
// Parameters is an opaque map for passing in configuration to a driver
242+
// for granting access to a bucket
243+
// +optional
244+
Parameters map[string]string `json:"parameters,omitempty"`
245+
}
246+
247+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
248+
249+
type BucketAccessClassList struct {
250+
metav1.TypeMeta `json:",inline"`
251+
metav1.ListMeta `json:"metadata,omitempty"`
252+
Items []BucketAccessClass `json:"items"`
253+
}
254+
255+
// +genclient
256+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
257+
// +kubebuilder:resource:scope=Namespaced
258+
// +kubebuilder:storageversion
259+
// +kubebuilder:subresource:status
260+
type BucketAccess struct {
261+
metav1.TypeMeta `json:",inline"`
262+
263+
// +optional
264+
metav1.ObjectMeta `json:"metadata,omitempty"`
265+
266+
Spec BucketAccessSpec `json:"spec,omitempty"`
267+
268+
// +optional
269+
Status BucketAccessStatus `json:"status"`
270+
}
271+
272+
type BucketAccessSpec struct {
273+
// BucketClaimName is the name of the BucketClaim.
274+
BucketClaimName string `json:"bucketClaimName"`
275+
276+
// Protocol is the name of the Protocol
277+
// that this access credential is supposed to support
278+
// If left empty, it will choose the protocol supported
279+
// by the bucket. If the bucket supports multiple protocols,
280+
// the end protocol is determined by the driver.
281+
// +optional
282+
Protocol Protocol `json:"protocol,omitempty"`
283+
284+
// BucketAccessClassName is the name of the BucketAccessClass
285+
BucketAccessClassName string `json:"bucketAccessClassName"`
286+
287+
// CredentialsSecretName is the name of the secret that COSI should populate
288+
// with the credentials. If a secret by this name already exists, then it is
289+
// assumed that credentials have already been generated. It is not overridden.
290+
// This secret is deleted when the BucketAccess is delted.
291+
CredentialsSecretName string `json:"credentialsSecretName"`
292+
293+
// ServiceAccountName is the name of the serviceAccount that COSI will map
294+
// to the OSP service account when IAM styled authentication is specified
295+
// +optional
296+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
297+
}
298+
299+
type BucketAccessStatus struct {
300+
// AccountID is the unique ID for the account in the OSP. It will be populated
301+
// by the COSI sidecar once access has been successfully granted.
302+
// +optional
303+
AccountID string `json:"accountID,omitempty"`
304+
305+
// AccessGranted indicates the successful grant of privileges to access the bucket
306+
// +optional
307+
AccessGranted bool `json:"accessGranted"`
308+
}
309+
310+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
311+
312+
type BucketAccessList struct {
313+
metav1.TypeMeta `json:",inline"`
314+
metav1.ListMeta `json:"metadata,omitempty"`
315+
Items []BucketAccess `json:"items"`
316+
}

0 commit comments

Comments
 (0)