universe.resource.v1
This API is available for Tenants only
Proto file, generated GO client and test tool for the API can be found in universe-api repo
This API is served by universe-infra-resource-manager
The intent of this API is to provide a way to create Kubernetes resource in the infrastructure cluster from the Tenant cluster.
universe-k8s-tenant-resource-plugin relies on this API for resource creation.
check Manual GRPC API usage doc before start
Here some examples using ‘grpcurl’ tool to access the API:
Replace $API_GW_ADDRESS
with address of iCP API GW in your environment
Replace $TENANT_ID
with existing tenant id
Create and Update requests contain binary fields. grpcurl
utility requires
binary fields to be encoded to base64 encoded before they can be used as request parameters.
Create Pod
# put base64 encoded Pod spec to RULE_TEMPLATE shel variable
POD_TEMPLATE=$(cat << EOM | base64 -w0
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "nginx"
},
"spec": {
"containers": [
{
"name": "nginx",
"image": "nginx:1.14.2",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}
EOM
)
# -d @ argument for grpcurl mean read arguments from STDIN
# use content of POD_TEMPLATE shel variable as obj_spec
grpcurl -cacert=ca.crt -cert=admin.crt -key=admin.key -servername api-gateway.local \
-H tenant-id:$TENANT_ID \
-d @ -proto universe/resource/v1/universe_resource.proto $API_GW_ADDRESS \
universe.resource.v1.UniverseResourceService.Create << EOM
{
"type": {"api_version": "v1", "kind": "Pod"},
"obj": {"obj_spec" : "$POD_TEMPLATE"}
}
EOM
Update Pod
# put base64 encoded Pod spec to RULE_TEMPLATE shel variable
POD_TEMPLATE=$(cat << EOM | base64 -w0
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "nginx",
"labels": {"foo": "bar"}
},
"spec": {
"containers": [
{
"name": "nginx",
"image": "nginx:1.14.2",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}
EOM
)
# -d @ argument for grpcurl mean read arguments from STDIN
# use content of POD_TEMPLATE shel variable as obj_spec
grpcurl -cacert=ca.crt -cert=admin.crt -key=admin.key -servername api-gateway.local \
-H tenant-id:$TENANT_ID \
-d @ -proto universe/resource/v1/universe_resource.proto $API_GW_ADDRESS \
universe.resource.v1.UniverseResourceService.Update << EOM
{
"type": {"api_version": "v1", "kind": "Pod"},
"obj": {"obj_spec" : "$POD_TEMPLATE"}
}
EOM
List Pods
grpcurl -cacert=ca.crt -cert=admin.crt -key=admin.key -servername api-gateway.local \
-H tenant-id:$TENANT_ID \
-d '{"type": {"api_version": "v1", "kind": "Pod"}}' \
-proto universe/resource/v1/universe_resource.proto $API_GW_ADDRESS \
universe.resource.v1.UniverseResourceService.List
Get Pod
grpcurl -cacert=ca.crt -cert=admin.crt -key=admin.key -servername api-gateway.local \
-H tenant-id:$TENANT_ID \
-d '{"type": {"api_version": "v1", "kind": "Pod"}, "name": "nginx" }' \
-proto universe/resource/v1/universe_resource.proto $API_GW_ADDRESS \
universe.resource.v1.UniverseResourceService.Get
Delete Pod
grpcurl -cacert=ca.crt -cert=admin.crt -key=admin.key -servername api-gateway.local \
-H tenant-id:$TENANT_ID \
-d '{"type": {"api_version": "v1", "kind": "Pod"}, "name": "nginx" }' \
-proto universe/resource/v1/universe_resource.proto $API_GW_ADDRESS \
universe.resource.v1.UniverseResourceService.Delete
syntax = "proto3";
package universe.resource.v1;
// UniverseResourceService is a service used to perform CRUD operations on Universe K8s Objects for the specified tenant
// The following client metadata fields are used:
// "tenant-id" (required): tenant identifier
service UniverseResourceService {
rpc Create(CreateRequest) returns (CreateResponse) {}
rpc Delete(DeleteRequest) returns (DeleteResponse) {}
rpc Update(UpdateRequest) returns (UpdateResponse) {}
rpc Get(GetRequest) returns (GetResponse) {}
rpc List(ListRequest) returns (ListResponse) {}
}
// ResourceType is a message passed as part of CRUD requests for server to determine the resource type to work with
message ResourceType {
string api_version = 1; // API version of the universe resource e.g apps/v1
string kind = 2; // The kind of resource e.g DaemonSet
}
// RawUniverseObject is a message that contains a raw universe object and its status as byte arrays
message RawUniverseObject {
bytes obj_spec = 1; // Universe object spec
bytes obj_status = 2; // Universe object status
}
// CreateRequest is used to create Universe objects in the infrastructure cluster
message CreateRequest {
ResourceType type = 1; // Type of the object to create
RawUniverseObject obj = 2; // Raw object to create
}
// Keep empty for now, later on rpc may be extended
message CreateResponse {}
// UpdateRequest is used to update already existing Universe objects in the infrastructure cluster
message UpdateRequest {
ResourceType type = 1; // Type of the object to update
RawUniverseObject obj = 2; // Changed raw object to update
}
// Keep empty for now, later on rpc may be extended
message UpdateResponse {}
// DeleteRequest is used to delete already existing Universe objects in the infrastructure cluster
message DeleteRequest {
ResourceType type = 1; // Type of the object to delete
string name = 2; // Name of the object to delete
}
// Keep empty for now, later on rpc may be extended
message DeleteResponse {}
// GetRequest is used to request already existing Universe objects in the infrastructure cluster
message GetRequest {
ResourceType type = 1; // Type of the object to get
string name = 2; // Name of the object to get
}
// GetResponse contains the object requested with GetRequest
message GetResponse {
RawUniverseObject obj = 1;
}
// ListRequest is used to list already existing Universe objects of certain type
message ListRequest {
ResourceType type = 1; // Type of the objects to list
}
// ListRequest contains the list of objects requested with ListRequest
message ListResponse {
repeated RawUniverseObject objs = 1;
}