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

Commit 895e4c3

Browse files
author
Krish Chowdhary
committed
adds conversion methods between spec and API
1 parent 7c26b4f commit 895e4c3

21 files changed

+207
-59
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+
azure := &AzureProtocol{}
39+
azure.StorageAccount = ext.StorageAccount
40+
azure.ContainerName = ext.ContainerName
41+
return azure
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+
gcs := &GCSProtocol{}
43+
gcs.BucketName = ext.BucketName
44+
gcs.PrivateKeyName = ext.PrivateKeyName
45+
gcs.ProjectID = ext.ProjectId
46+
gcs.ServiceAccount = ext.ServiceAccount
47+
return gcs
48+
}

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+
s3 := &S3Protocol{}
58+
s3.BucketName = ext.BucketName
59+
s3.Endpoint = ext.Endpoint
60+
s3.Region = ext.Region
61+
vers, ok := osspec.S3SignatureVersion_name[int32(ext.SignatureVersion)]
62+
if !ok {
63+
vers = osspec.S3SignatureVersion_name[0]
64+
}
65+
s3.SignatureVersion = S3SignatureVersion(vers)
66+
return s3
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_bucketclasses.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -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:

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ spec:
151151
type: string
152152
signatureVersion:
153153
enum:
154-
- s3v2
155-
- s3v4
154+
- S3V2
155+
- S3V4
156156
type: string
157157
type: object
158158
version:

Diff for: docs/deployment-guide.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ Execute following commands to setup COSI:
2020

2121
```sh
2222
# Install CRDs
23-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-api
23+
kubectl create -k sigs.k8s.io/container-object-storage-interface-api
2424

2525
# Install controller
26-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-controller
26+
kubectl create -k sigs.k8s.io/container-object-storage-interface-controller
2727

2828
# Sample Provisioner and Sidecar
29-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar
29+
kubectl create -k sigs.k8s.io/container-object-storage-interface-provisioner-sidecar
3030

3131
# Node Adapter
32-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-csi-adapter
32+
kubectl create -k sigs.k8s.io/container-object-storage-interface-csi-adapter
3333
```
3434

3535
### CustomResourceDefinitions
@@ -46,30 +46,30 @@ COSI acts on following custom resource definitions (CRDs):
4646
All [COSI custom resource definitions](../crds) can be installed using [kustomization file](../kustomization.yaml) and `kubectl` with following command:
4747

4848
```sh
49-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-api
49+
kubectl create -k sigs.k8s.io/container-object-storage-interface-api
5050
```
5151

5252
### Controller
5353

54-
COSI controller can be setup using the [kustomization file](https://github.com/kubernetes-sigs/container-object-storage-interface-controller/blob/master/kustomization.yaml) from the [container-object-storage-interface-controller](https://github.com/kubernetes-sigs/container-object-storage-interface-controller) repository with following command:
54+
COSI controller can be setup using the [kustomization file](https://sigs.k8s.io/container-object-storage-interface-controller/blob/master/kustomization.yaml) from the [container-object-storage-interface-controller](https://sigs.k8s.io/container-object-storage-interface-controller) repository with following command:
5555

5656
```sh
57-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-controller
57+
kubectl create -k sigs.k8s.io/container-object-storage-interface-controller
5858
```
5959

6060
The controller will be deployed in the `default` namespace.
6161

6262
### Sample Driver & Sidecar
6363

64-
Sample Driver & Sidecar can be setup using the [kustomization file](https://github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/blob/master/kustomization.yaml) from the [container-object-storage-interface-provisioner-sidecar](https://github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar) repository with following command:
64+
Sample Driver & Sidecar can be setup using the [kustomization file](https://sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/blob/master/kustomization.yaml) from the [container-object-storage-interface-provisioner-sidecar](https://sigs.k8s.io/container-object-storage-interface-provisioner-sidecar) repository with following command:
6565

6666
```sh
67-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar
67+
kubectl create -k sigs.k8s.io/container-object-storage-interface-provisioner-sidecar
6868
```
6969
### Node Adapter
7070

71-
Node adapter can be setup using the [kustomization file](https://github.com/kubernetes-sigs/container-object-storage-interface-csi-adapter/blob/master/kustomization.yaml) from the [container-object-storage-interface-csi-adapter](https://github.com/kubernetes-sigs/container-object-storage-interface-csi-adapter) repository with following command:
71+
Node adapter can be setup using the [kustomization file](https://sigs.k8s.io/container-object-storage-interface-csi-adapter/blob/master/kustomization.yaml) from the [container-object-storage-interface-csi-adapter](https://sigs.k8s.io/container-object-storage-interface-csi-adapter) repository with following command:
7272

7373
```sh
74-
kubectl create -k github.com/kubernetes-sigs/container-object-storage-interface-csi-adapter
74+
kubectl create -k sigs.k8s.io/container-object-storage-interface-csi-adapter
7575
```

Diff for: docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ The existing primitives in CSI do not apply to objectstorage. Thus the need for
3636
## Other
3737

3838
- [Project Board](https://github.com/orgs/kubernetes-sigs/projects/8)
39-
- [Weekly Meetings](https://github.com/kubernetes-sigs/container-object-storage-interface-api/tree/master/docs/meetings.md)
39+
- [Weekly Meetings](https://sigs.k8s.io/container-object-storage-interface-api/tree/master/docs/meetings.md)
4040
- [Roadmap](https://github.com/orgs/kubernetes-sigs/projects/8)

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ require (
1212
k8s.io/apimachinery v0.19.4
1313
k8s.io/client-go v0.19.4
1414
k8s.io/kube-openapi v0.0.0-20200923155610-8b5066479488
15+
sigs.k8s.io/container-object-storage-interface-spec v0.0.0-20210224211525-dfa3af562c18
1516
sigs.k8s.io/controller-runtime v0.6.3
1617
)

0 commit comments

Comments
 (0)