Skip to content
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

Wenjian dev #13

Merged
merged 9 commits into from
May 11, 2022
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
.PHONY: generate
generate: controller-gen openapi-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# $(OPENAPI_GEN) --go-header-file="hack/boilerplate.go.txt" --input-dirs="./..." --output-package="$(PROJECT_DIR)/pkg/apis/openapi"
# $(OPENAPI_GEN) --go-header-file="hack/boilerplate.go.txt" --input-dirs="./pkg/apis/core/..." --output-package="centaurusinfra.io/fornax-serverless/pkg/apis/openapi"

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -118,6 +118,25 @@ OPENAPI_GEN = $(shell pwd)/bin/openapi-gen
openapi-gen: ## Download openapi-gen locally if necessary.
$(call go-get-tool,$(OPENAPI_GEN),k8s.io/kube-openapi/cmd/[email protected])

PROTOC_GEN = $(shell pwd)/bin/protoc-gen-go
PROTOC_GEN_GRPC = $(shell pwd)/bin/protoc-gen-go-grpc
PROTOC = $(HOME)/.local/bin/protoc
.PHONY: protoc-gen
protoc-gen: ## Download protc-gen locally if necessary.
h-w-chen marked this conversation as resolved.
Show resolved Hide resolved
$(call go-get-tool,$(PROTOC_GEN),google.golang.org/protobuf/cmd/[email protected])
$(call go-get-tool,$(PROTOC_GEN_GRPC),google.golang.org/grpc/cmd/[email protected])
$(call get-protoc,$(PROTOC))
$(PROTOC) -I=./ -I=./vendor \
--go_out=../.. \
--go-grpc_out=../../ \
--go_opt=Mk8s.io/api/core/v1/generated.proto=k8s.io/api/core/v1 \
--go_opt=Mk8s.io/apimachinery/pkg/api/resource/generated.proto=k8s.io/apimachinery/pkg/api/resource \
--go_opt=Mk8s.io/apimachinery/pkg/apis/meta/v1/generated.proto=k8s.io/apimachinery/pkg/apis/meta/v1 \
--go_opt=Mk8s.io/apimachinery/pkg/runtime/generated.proto=k8s.io/apimachinery/pkg/runtime \
--go_opt=Mk8s.io/apimachinery/pkg/runtime/schema/generated.proto=k8s.io/apimachinery/pkg/runtime/schema \
--go_opt=Mk8s.io/apimachinery/pkg/util/intstr/generated.proto=k8s.io/apimachinery/pkg/util/intstr \
pkg/fornaxcore/fornaxcore.proto

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
Expand All @@ -141,3 +160,16 @@ GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

define get-protoc
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
PB_REL="https://github.com/protocolbuffers/protobuf/releases" ;\
curl -LO $$PB_REL/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip ;\
echo "get protoc" ;\
unzip $$TMP_DIR/protoc-3.12.1-linux-x86_64.zip -d $$HOME/.local ;\
rm -rf $$TMP_DIR ;\
}
endef
17 changes: 14 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,35 @@ module centaurusinfra.io/fornax-serverless
go 1.17

require (
google.golang.org/grpc v1.40.0
google.golang.org/protobuf v1.27.1
github.com/golang/protobuf v1.5.2
k8s.io/api v0.23.1
k8s.io/apimachinery v0.23.1
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65
sigs.k8s.io/apiserver-runtime v1.1.1
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -33,7 +44,7 @@ require (
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiserver v0.23.1 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
Expand Down
160 changes: 160 additions & 0 deletions pkg/fornaxcore/fornaxcore.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
syntax = "proto2";
h-w-chen marked this conversation as resolved.
Show resolved Hide resolved
package centaurusinfra.io.fornaxcore.service;

option go_package = "centaurusinfra.io/fornax-serverless/pkg/fornaxcore/grpc";

import "google/protobuf/empty.proto";
import "k8s.io/api/core/v1/generated.proto";

service FornaxCoreService {
rpc getMessage(google.protobuf.Empty) returns (stream FornaxCoreMessage);
rpc putMessage(FornaxCoreMessage) returns (google.protobuf.Empty);
h-w-chen marked this conversation as resolved.
Show resolved Hide resolved
}

enum MessageType {
UNSPECIFIED = 0;
FORNAX_CORE_CONFIGURATION = 100;
NODE_CONFIGURATION = 200;
NODE_REGISTER = 201;
NODE_READY = 202;
NODE_STATE = 203;
POD_CREATE = 300;
POD_TERMINATE = 301;
POD_ACTIVE = 302;
POD_STATE = 303;
SESSION_START = 400;
SESSION_CLOSE = 401;
SESSION_STATE = 402;
}

message FornaxCoreMessage {
required string messageIdentifier = 1;
required string nodeIdentifier = 2;
required MessageType messageType = 3;
oneof MessageBody {
FornaxCoreConfiguration fornaxCoreConfiguration = 100;
NodeConfiguration nodeConfiguration = 200;
NodeRegistry nodeRegistry = 201;
NodeReady nodeReady = 202;
NodeState nodeState= 203;
PodCreate podCreate = 300;
PodTerminate podTerminate = 301;
PodActive podActive = 302;
PodState podState = 303;
SessionStart sessionStart = 400;
SessionClose sessionClose = 401;
SessionState sessionState = 402;
}
}

message FornaxCore {
required string ip = 1;
required string identifier = 2;
}

message FornaxCoreConfiguration {
required FornaxCore primary = 1;
repeated FornaxCore standbys = 2;
}

message NodeConfiguration {
required k8s.io.api.core.v1.NodeSpec nodeSpec = 1;
}

message NodeRegistry {
required string nodeIp = 1;
required NodeResource resourceLimit = 2;
}

message NodeResource {
required k8s.io.api.core.v1.NodeStatus status = 1;
}

message NodeReady {
required string nodeIp = 1;
required NodeResource resourceLimit = 2;
}

message NodeState {
required string nodeIp = 1;
enum State {
Available = 0;
Problemtic = 10;
ReachResourceLimit = 20;
}
required State state = 2;
required NodeResource nodeResource = 3;
repeated PodState podStates = 4;
repeated SessionState sessionStates = 5;
}

message PodState {
required string podIdentifier = 1;
required string appIdentifier = 2;
enum State {
Creating = 0;
Standby = 10;
Activating = 20;
Running = 30;
Evacuating = 40;
Terminating = 50;
Terminated = 60;
}
required State state = 3;
required k8s.io.api.core.v1.PodStatus podStatus = 4;
optional PodResource resource = 5;
}

message PodResource {
optional k8s.io.api.core.v1.ResourceQuotaStatus resourceQuotaStatus = 1;
repeated k8s.io.api.core.v1.AttachedVolume volumes = 2;
}

message PodCreate {
required string podIdentifier = 1;
required string appIdentifier = 2;
enum CreateMode {
Active = 0;
Standby = 10;
}
required CreateMode mode = 3;
required k8s.io.api.core.v1.PodSpec podSpec = 4;
optional k8s.io.api.core.v1.ConfigMap configMapSpec = 5;
}

message PodTerminate {
required string podIdentifier = 1;
required string appIdentifier = 2;
}

message PodActive {
required string podIdentifier = 1;
required string appIdentifier = 2;
}

message SessionState {
required string sessionIdentifier = 1;
required string podIdentifier = 2;
required string appIdentifier = 3;
enum State {
Starting = 0;
Ready = 10;
Live = 20;
Evacuating = 30;
Terminating = 40;
Terminated = 50;
}
required State state = 4;
}

message SessionStart {
required string sessionIdentifier = 1;
required string podIdentifier = 2;
required string appIdentifier = 3;
}

message SessionClose {
required string sessionIdentifier = 1;
required string podIdentifier = 2;
required string appIdentifier = 3;
}
Loading