Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit eb167f7

Browse files
authored
Merge pull request #23 from krishchow/api-verifications-changes
adds conversion methods between spec and API
2 parents 7c26b4f + f00fe2d commit eb167f7

26 files changed

+225
-77
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.build
44
*.swp
55
release-tools
6+
vendor
7+
.idea

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ This repository hosts the API defintion of the Custom Resource Definitions (CRD)
1717

1818
**NOTE**: All of the APIs are defined under the API group `objectstorage.k8s.io`.
1919

20-
For more information about COSI, visit our [documentation](https://github.com/kubernetes-sigs/container-object-storage-interface-api/tree/master/docs/index.md).
20+
For more information about COSI, visit our [documentation](https://sigs.k8s.io/container-object-storage-interface-api/tree/master/docs/index.md).
2121

2222
## Developer Guide
2323

2424
All API definitions are in [`apis/objectstorage.k8s.io/`](./apis/objectstorage.k8s.io/). All API changes **_MUST_** satisfy the following requirements:
2525

2626
- Must be backwards compatible
27-
- Must be in-sync with the API definitions in [sigs.k8s.io/container-object-storage-interface-spec](https://github.com/kubernetes-sigs/container-object-storage-interface-spec)
27+
- Must be in-sync with the API definitions in [sigs.k8s.io/container-object-storage-interface-spec](https://sigs.k8s.io/container-object-storage-interface-spec)
2828

2929
### Build and Test
3030

Diff for: apis/objectstorage.k8s.io/v1alpha1/azure_types.go

+18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,25 @@ limitations under the License.
1818

1919
package v1alpha1
2020

21+
import osspec "sigs.k8s.io/container-object-storage-interface-spec"
22+
2123
type AzureProtocol struct {
2224
ContainerName string `json:"containerName,omitempty"`
2325
StorageAccount string `json:"storageAccount,omitempty"`
2426
}
27+
28+
func (azure *AzureProtocol) ConvertToExternal() *osspec.Protocol_AzureBlob {
29+
return &osspec.Protocol_AzureBlob{
30+
AzureBlob: &osspec.AzureBlobParameters{
31+
ContainerName: azure.ContainerName,
32+
StorageAccount: azure.StorageAccount,
33+
},
34+
}
35+
}
36+
37+
func ConvertFromAzureExternal(ext *osspec.AzureBlobParameters) *AzureProtocol {
38+
return &AzureProtocol{
39+
StorageAccount: ext.StorageAccount,
40+
ContainerName: ext.ContainerName,
41+
}
42+
}

Diff for: apis/objectstorage.k8s.io/v1alpha1/gcs_types.go

+22
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,31 @@ limitations under the License.
1818

1919
package v1alpha1
2020

21+
import osspec "sigs.k8s.io/container-object-storage-interface-spec"
22+
2123
type GCSProtocol struct {
2224
BucketName string `json:"bucketName,omitempty"`
2325
PrivateKeyName string `json:"privateKeyName,omitempty"`
2426
ProjectID string `json:"projectID,omitempty"`
2527
ServiceAccount string `json:"serviceAccount,omitempty"`
2628
}
29+
30+
func (gcs *GCSProtocol) ConvertToExternal() *osspec.Protocol_Gcs {
31+
return &osspec.Protocol_Gcs{
32+
Gcs: &osspec.GCSParameters{
33+
BucketName: gcs.BucketName,
34+
PrivateKeyName: gcs.PrivateKeyName,
35+
ProjectId: gcs.ProjectID,
36+
ServiceAccount: gcs.ServiceAccount,
37+
},
38+
}
39+
}
40+
41+
func ConvertFromGCSExternal(ext *osspec.GCSParameters) *GCSProtocol {
42+
return &GCSProtocol{
43+
BucketName: ext.BucketName,
44+
PrivateKeyName: ext.PrivateKeyName,
45+
ProjectID: ext.ProjectId,
46+
ServiceAccount: ext.ServiceAccount,
47+
}
48+
}

Diff for: apis/objectstorage.k8s.io/v1alpha1/openapi_generated.go

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: apis/objectstorage.k8s.io/v1alpha1/protocol_types.go

+75
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19+
import (
20+
"errors"
21+
22+
osspec "sigs.k8s.io/container-object-storage-interface-spec"
23+
)
24+
1925
type ProtocolName string
2026

2127
const (
2228
ProtocolNameS3 ProtocolName = "s3"
2329
ProtocolNameAzure ProtocolName = "azureBlob"
2430
ProtocolNameGCS ProtocolName = "gcs"
31+
32+
MissingS3Protocol = "missing s3 in protocol"
33+
MissingAzureProtocol = "missing azure in protocol"
34+
MissingGCSProtocol = "missing gcs in protocol"
35+
InvalidProtocolName = "invalid protocol name"
2536
)
2637

2738
type Protocol struct {
@@ -36,3 +47,67 @@ type Protocol struct {
3647
// +optional
3748
GCS *GCSProtocol `json:"gcs,omitempty"`
3849
}
50+
51+
func (in *Protocol) ConvertToExternal() (*osspec.Protocol, error) {
52+
external := &osspec.Protocol{
53+
Version: in.Version,
54+
}
55+
56+
switch in.Name {
57+
case ProtocolNameS3:
58+
if in.S3 == nil {
59+
return nil, errors.New(MissingS3Protocol)
60+
}
61+
external.Name = osspec.ProtocolName_S3
62+
external.Type = in.S3.ConvertToExternal()
63+
case ProtocolNameAzure:
64+
if in.AzureBlob == nil {
65+
return nil, errors.New(MissingAzureProtocol)
66+
}
67+
external.Name = osspec.ProtocolName_AZURE
68+
external.Type = in.AzureBlob.ConvertToExternal()
69+
case ProtocolNameGCS:
70+
if in.GCS == nil {
71+
return nil, errors.New(MissingGCSProtocol)
72+
}
73+
external.Name = osspec.ProtocolName_GCS
74+
external.Type = in.GCS.ConvertToExternal()
75+
default:
76+
external.Name = osspec.ProtocolName_UnknownProtocol
77+
return external, errors.New(InvalidProtocolName)
78+
79+
}
80+
81+
return external, nil
82+
}
83+
84+
func ConvertFromProtocolExternal(external *osspec.Protocol) (*Protocol, error) {
85+
in := &Protocol{}
86+
in.Version = external.Version
87+
88+
switch external.Name {
89+
case osspec.ProtocolName_S3:
90+
if external.GetS3() == nil {
91+
return nil, errors.New(MissingS3Protocol)
92+
}
93+
in.Name = ProtocolNameS3
94+
in.S3 = ConvertFromS3External(external.GetS3())
95+
case osspec.ProtocolName_AZURE:
96+
if external.GetAzureBlob() == nil {
97+
return nil, errors.New(MissingAzureProtocol)
98+
}
99+
in.Name = ProtocolNameAzure
100+
in.AzureBlob = ConvertFromAzureExternal(external.GetAzureBlob())
101+
case osspec.ProtocolName_GCS:
102+
if external.GetGcs() == nil {
103+
return nil, errors.New(MissingGCSProtocol)
104+
}
105+
in.Name = ProtocolNameGCS
106+
in.GCS = ConvertFromGCSExternal(external.GetGcs())
107+
default:
108+
// TODO - Do we to set the protocol Name to specific value here?
109+
return nil, errors.New(InvalidProtocolName)
110+
}
111+
112+
return in, nil
113+
}

Diff for: apis/objectstorage.k8s.io/v1alpha1/s3_types.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,50 @@ limitations under the License.
1818

1919
package v1alpha1
2020

21+
import (
22+
osspec "sigs.k8s.io/container-object-storage-interface-spec"
23+
)
24+
2125
type S3SignatureVersion string
2226

2327
const (
24-
S3SignatureVersionV2 S3SignatureVersion = "S3v2"
25-
S3SignatureVersionV4 S3SignatureVersion = "S3v4"
28+
S3SignatureVersionV2 S3SignatureVersion = "S3V2"
29+
S3SignatureVersionV4 S3SignatureVersion = "S3V4"
2630
)
2731

2832
type S3Protocol struct {
2933
Endpoint string `json:"endpoint,omitempty"`
3034
BucketName string `json:"bucketName,omitempty"`
3135
Region string `json:"region,omitempty"`
32-
// +kubebuilder:validation:Enum:={s3v2,s3v4}
36+
// +kubebuilder:validation:Enum:={S3V2,S3V4}
3337
SignatureVersion S3SignatureVersion `json:"signatureVersion,omitempty"`
3438
}
39+
40+
func (s3 *S3Protocol) ConvertToExternal() *osspec.Protocol_S3 {
41+
sigver, ok := osspec.S3SignatureVersion_value[string(s3.SignatureVersion)]
42+
if !ok {
43+
// NOTE - 0 here is equivalent to UnknownSignature
44+
sigver = 0
45+
}
46+
return &osspec.Protocol_S3{
47+
S3: &osspec.S3Parameters{
48+
Endpoint: s3.Endpoint,
49+
BucketName: s3.BucketName,
50+
Region: s3.Region,
51+
SignatureVersion: osspec.S3SignatureVersion(sigver),
52+
},
53+
}
54+
}
55+
56+
func ConvertFromS3External(ext *osspec.S3Parameters) *S3Protocol {
57+
vers, ok := osspec.S3SignatureVersion_name[int32(ext.SignatureVersion)]
58+
if !ok {
59+
vers = osspec.S3SignatureVersion_name[0]
60+
}
61+
return &S3Protocol{
62+
BucketName: ext.BucketName,
63+
Endpoint: ext.Endpoint,
64+
Region: ext.Region,
65+
SignatureVersion: S3SignatureVersion(vers),
66+
}
67+
}

Diff for: clientset/fake/register.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crds/objectstorage.k8s.io_bucketaccessclasses.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.4.1
7+
controller-gen.kubebuilder.io/version: (devel)
88
creationTimestamp: null
99
name: bucketaccessclasses.objectstorage.k8s.io
1010
spec:

Diff for: crds/objectstorage.k8s.io_bucketaccesses.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.4.1
7+
controller-gen.kubebuilder.io/version: (devel)
88
creationTimestamp: null
99
name: bucketaccesses.objectstorage.k8s.io
1010
spec:

Diff for: crds/objectstorage.k8s.io_bucketaccessrequests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.4.1
7+
controller-gen.kubebuilder.io/version: (devel)
88
creationTimestamp: null
99
name: bucketaccessrequests.objectstorage.k8s.io
1010
spec:

Diff for: crds/objectstorage.k8s.io_bucketclasses.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.4.1
7+
controller-gen.kubebuilder.io/version: (devel)
88
creationTimestamp: null
99
name: bucketclasses.objectstorage.k8s.io
1010
spec:
@@ -91,8 +91,8 @@ spec:
9191
type: string
9292
signatureVersion:
9393
enum:
94-
- s3v2
95-
- s3v4
94+
- S3V2
95+
- S3V4
9696
type: string
9797
type: object
9898
version:

0 commit comments

Comments
 (0)