Skip to content

Versioned proto and golang package structure #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/csi.proto.tmp
*.tmp
.DS_Store
.build
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
all: build

CSI_SPEC := spec.md

CSI_PROTO := csi.proto
VERSIONED_PROTO := versioned.proto

PROTOS := $(CSI_PROTO) $(VERSIONED_PROTO)

.SUFFIXES:
.SUFFIXES: .proto .tmp

# This is the target for building the temporary CSI protobuf file.
#
# The temporary file is not versioned, and thus will always be
# built on Travis-CI.
$(CSI_PROTO).tmp: $(CSI_SPEC)
cat $? | \
sed -n -e '/```protobuf$$/,/```$$/ p' | \
sed -e 's@^```.*$$@////////@g' > $@
$(PROTOS:.proto=.tmp): $(CSI_SPEC)
cat $? | sed -n -e '/```protobuf$$/,/^```$$/ { /^\/\/csi:file=$*.proto$$/,/^```$$/ { /^\(\/\/\|```$$\)/!p } }' > $@

# This is the target for building the CSI protobuf file.
#
Expand All @@ -21,7 +26,7 @@ $(CSI_PROTO).tmp: $(CSI_SPEC)
# will fail.
#
# Locally the temp file is simply copied over the real file.
$(CSI_PROTO): $(CSI_PROTO).tmp
.tmp.proto:
ifeq (true,$(TRAVIS))
diff "$@" "$?"
else
Expand All @@ -41,10 +46,10 @@ endif
clean:

clobber: clean
rm -f $(CSI_PROTO) $(CSI_PROTO).tmp
rm -f $(PROTOS) $(PROTOS:.proto=.tmp)

# check generated files for violation of standards
check: $(CSI_PROTO)
check: $(PROTOS)
awk '{ if (length > 72) print NR, $$0 }' $? | diff - /dev/null

.PHONY: clean clobber check
74 changes: 5 additions & 69 deletions csi.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
////////
syntax = "proto3";
package csi;
////////
////////
service Identity {
rpc GetSupportedVersions (GetSupportedVersionsRequest)
returns (GetSupportedVersionsResponse) {}
import "versioned.proto";
package csi.v1;

option go_package = "csi";

service Identity {
rpc GetPluginInfo(GetPluginInfoRequest)
returns (GetPluginInfoResponse) {}

Expand Down Expand Up @@ -59,29 +57,6 @@ service Node {
rpc NodeGetCapabilities (NodeGetCapabilitiesRequest)
returns (NodeGetCapabilitiesResponse) {}
}
////////
////////
message GetSupportedVersionsRequest {
}

message GetSupportedVersionsResponse {
// All the CSI versions that the Plugin supports. This field is
// REQUIRED.
repeated Version supported_versions = 1;
}

// Specifies a version in Semantic Version 2.0 format.
// (http://semver.org/spec/v2.0.0.html)
message Version {
// The value of this field MUST NOT be negative.
int32 major = 1; // This field is REQUIRED.
// The value of this field MUST NOT be negative.
int32 minor = 2; // This field is REQUIRED.
// The value of this field MUST NOT be negative.
int32 patch = 3; // This field is REQUIRED.
}
////////
////////
message GetPluginInfoRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand All @@ -103,8 +78,6 @@ message GetPluginInfoResponse {
// This field is OPTIONAL. Values are opaque to the CO.
map<string, string> manifest = 3;
}
////////
////////
message GetPluginCapabilitiesRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand All @@ -116,7 +89,6 @@ message GetPluginCapabilitiesResponse {
repeated PluginCapability capabilities = 2;
}

// Specifies a capability of the plugin.
message PluginCapability {
message Service {
enum Type {
Expand All @@ -139,8 +111,6 @@ message PluginCapability {
Service service = 1;
}
}
////////
////////
message CreateVolumeRequest {
// The API version assumed by the CO. This field is REQUIRED.
Version version = 1;
Expand Down Expand Up @@ -203,7 +173,6 @@ message CreateVolumeResponse {
Volume volume = 1;
}

// Specify a capability of a volume.
message VolumeCapability {
// Indicate that the volume will be accessed via the block device API.
message BlockVolume {
Expand Down Expand Up @@ -264,9 +233,6 @@ message VolumeCapability {
AccessMode access_mode = 3;
}

// The capacity of the storage space in bytes. To specify an exact size,
// `required_bytes` and `limit_bytes` can be set to the same value. At
// least one of the these fields MUST be specified.
message CapacityRange {
// Volume must be at least this big. This field is OPTIONAL.
// A value of 0 is equal to an unspecified field value.
Expand All @@ -279,7 +245,6 @@ message CapacityRange {
int64 limit_bytes = 2;
}

// The information about a provisioned volume.
message Volume {
// The capacity of the volume in bytes. This field is OPTIONAL. If not
// set (value of 0), it indicates that the capacity of the volume is
Expand All @@ -302,8 +267,6 @@ message Volume {
// be passed to volume validation and publishing calls.
map<string,string> attributes = 3;
}
////////
////////
message DeleteVolumeRequest {
// The API version assumed by the CO. This field is REQUIRED.
Version version = 1;
Expand All @@ -327,8 +290,6 @@ message DeleteVolumeRequest {
}

message DeleteVolumeResponse {}
////////
////////
message ControllerPublishVolumeRequest {
// The API version assumed by the CO. This field is REQUIRED.
Version version = 1;
Expand Down Expand Up @@ -374,8 +335,6 @@ message ControllerPublishVolumeResponse {
// This information is opaque to the CO. This field is OPTIONAL.
map<string, string> publish_info = 1;
}
////////
////////
message ControllerUnpublishVolumeRequest {
// The API version assumed by the CO. This field is REQUIRED.
Version version = 1;
Expand Down Expand Up @@ -405,8 +364,6 @@ message ControllerUnpublishVolumeRequest {
}

message ControllerUnpublishVolumeResponse {}
////////
////////
message ValidateVolumeCapabilitiesRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand Down Expand Up @@ -434,8 +391,6 @@ message ValidateVolumeCapabilitiesResponse {
// An empty string is equal to an unspecified field value.
string message = 2;
}
////////
////////
message ListVolumesRequest {
// The API version assumed by the CO. This field is REQUIRED.
Version version = 1;
Expand Down Expand Up @@ -472,8 +427,6 @@ message ListVolumesResponse {
// An empty string is equal to an unspecified field value.
string next_token = 2;
}
////////
////////
message GetCapacityRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand Down Expand Up @@ -501,16 +454,12 @@ message GetCapacityResponse {
// The value of this field MUST NOT be negative.
int64 available_capacity = 1;
}
////////
////////
message ControllerProbeRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
}

message ControllerProbeResponse {}
////////
////////
message ControllerGetCapabilitiesRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand All @@ -522,7 +471,6 @@ message ControllerGetCapabilitiesResponse {
repeated ControllerServiceCapability capabilities = 2;
}

// Specifies a capability of the controller service.
message ControllerServiceCapability {
message RPC {
enum Type {
Expand All @@ -541,8 +489,6 @@ message ControllerServiceCapability {
RPC rpc = 1;
}
}
////////
////////
message NodePublishVolumeRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand Down Expand Up @@ -593,8 +539,6 @@ message NodePublishVolumeRequest {
}

message NodePublishVolumeResponse {}
////////
////////
message NodeUnpublishVolumeRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand Down Expand Up @@ -622,8 +566,6 @@ message NodeUnpublishVolumeRequest {
}

message NodeUnpublishVolumeResponse {}
////////
////////
message NodeGetIdRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand All @@ -635,16 +577,12 @@ message NodeGetIdResponse {
// This is a REQUIRED field.
string node_id = 1;
}
////////
////////
message NodeProbeRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
}

message NodeProbeResponse {}
////////
////////
message NodeGetCapabilitiesRequest {
// The API version assumed by the CO. This is a REQUIRED field.
Version version = 1;
Expand All @@ -656,7 +594,6 @@ message NodeGetCapabilitiesResponse {
repeated NodeServiceCapability capabilities = 1;
}

// Specifies a capability of the node service.
message NodeServiceCapability {
message RPC {
enum Type {
Expand All @@ -671,4 +608,3 @@ message NodeServiceCapability {
RPC rpc = 1;
}
}
////////
1 change: 0 additions & 1 deletion lib/go/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/protoc
/protoc-gen-go
/csi.a
/csi/.build/
22 changes: 13 additions & 9 deletions lib/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,29 @@ export PATH := $(shell pwd):$(PATH)
########################################################################
## BUILD ##
########################################################################
CSI_GO := csi/csi.pb.go
CSI_A := csi.a
CSI_PROTOS := ../../csi.proto ../../versioned.proto
CSI_PROTO := ../../csi.proto
CSI_GO_TMP := csi/.build/csi.pb.go
CSI_PKG := $(shell cat $(CSI_PROTO) | sed -n -e 's/^package.\([^;]*\);$$/\1/p'|tr '.' '/')
CSI_GO := $(CSI_PKG)/csi.pb.go $(CSI_PKG)/versioned.pb.go
CSI_A := csi.a
CSI_GO_TMP := $(CSI_PKG)/.build/csi.pb.go $(CSI_PKG)/.build/versioned.pb.go

../../versioned.proto:

# This recipe generates the go language bindings to a temp area.
$(CSI_GO_TMP): $(CSI_PROTO) | $(PROTOC) $(PROTOC_GEN_GO)
$(CSI_GO_TMP): $(CSI_PROTOS) | $(PROTOC) $(PROTOC_GEN_GO)
@mkdir -p "$(@D)"
$(PROTOC) -I "$(<D)" --go_out=plugins=grpc:"$(@D)" "$<"
$(PROTOC) -I "$(<D)" --go_out=plugins=grpc:"$(@D)" $^

# The temp language bindings are compared to the ones that are
# versioned. If they are different then it means the language
# bindings were not updated prior to being committed.
$(CSI_GO): $(CSI_GO_TMP)
ifeq (true,$(TRAVIS))
diff "$@" "$?"
diff "$@" "$(<D)/$(@F)"
else
@mkdir -p "$(@D)"
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
diff "$@" "$(<D)/$(@F)" > /dev/null 2>&1 || cp -f "$(<D)/$(@F)" "$@"
endif

# This recipe builds the Go archive from the sources in three steps:
Expand All @@ -104,8 +108,8 @@ endif
# 3. Build the archive file.
$(CSI_A): $(CSI_GO)
go get -d ./...
go install ./csi
go build -o "$@" ./csi
go install ./$(CSI_PKG)
go build -o "$@" ./$(CSI_PKG)

build: $(CSI_A)

Expand Down
Loading