add proto demo

Signed-off-by: devad <cossjie@foxmail.com>
This commit is contained in:
devad 2022-03-30 18:27:09 +08:00
parent 58865b6bab
commit 1c603f035d
23 changed files with 150 additions and 35 deletions

1
.gitignore vendored
View File

@ -28,5 +28,6 @@ go.sum
# config file
aksk.conf
config.yaml
log/

View File

@ -1,10 +1,10 @@
package eci
import (
"PCM/adaptor/container_api_adaptor/common/auth/aksk"
"PCM/adaptor/container_api_adaptor/common/config"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/eci"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/auth/aksk"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/config"
)
// CreateContainerGroup 创建

View File

@ -1,10 +1,10 @@
package api
import (
"PCM/adaptor/container_api_adaptor/alibaba/eci"
cciAksk "PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
cci "PCM/adaptor/container_api_adaptor/huawei/resources/pod"
"PCM/adaptor/container_api_adaptor/tencent/eks"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/alibaba/eci"
cciAksk "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
cci "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/resources/pod"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/tencent/eks"
)
//CreatePod 创建Pod通用方法

View File

@ -1,10 +1,10 @@
package aksk
import (
"PCM/adaptor/container_api_adaptor/common/auth/aksk"
"PCM/adaptor/container_api_adaptor/common/config"
clientset "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1"
"fmt"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/auth/aksk"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/config"
clientset "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"

View File

@ -19,7 +19,7 @@ limitations under the License.
package v1beta1
import (
networkingcciv1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1"
networkingcciv1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
flowcontrol "k8s.io/client-go/util/flowcontrol"

View File

@ -19,9 +19,9 @@ limitations under the License.
package fake
import (
clientset "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1"
networkingcciv1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1"
fakenetworkingcciv1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1/fake"
clientset "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1"
networkingcciv1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1"
fakenetworkingcciv1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1/fake"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/discovery"

View File

@ -19,7 +19,7 @@ limitations under the License.
package fake
import (
networkingcciv1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
networkingcciv1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"

View File

@ -19,7 +19,7 @@ limitations under the License.
package scheme
import (
networkingcciv1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
networkingcciv1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"

View File

@ -19,7 +19,7 @@ limitations under the License.
package fake
import (
v1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
v1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
schema "k8s.io/apimachinery/pkg/runtime/schema"

View File

@ -19,7 +19,7 @@ limitations under the License.
package fake
import (
v1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1"
v1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/typed/networking.cci.io/v1beta1"
rest "k8s.io/client-go/rest"
testing "k8s.io/client-go/testing"
)

View File

@ -21,8 +21,8 @@ package v1beta1
import (
"time"
v1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
scheme "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/scheme"
v1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
scheme "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/scheme"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"

View File

@ -19,8 +19,8 @@ limitations under the License.
package v1beta1
import (
v1beta1 "PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
"PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/scheme"
v1beta1 "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1/scheme"
rest "k8s.io/client-go/rest"
)

View File

@ -1,11 +1,11 @@
package network
import (
"PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
"PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/apis/networking.cci.io/v1beta1"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
"time"
clientset "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1"
clientset "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
)

View File

@ -1,8 +1,8 @@
package pod
import (
"PCM/adaptor/container_api_adaptor/common/config"
"fmt"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/config"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@ -1,13 +1,13 @@
package eks
import (
"PCM/adaptor/container_api_adaptor/common/auth/aksk"
pcmCommon "PCM/adaptor/container_api_adaptor/common/config"
"fmt"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
"gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/auth/aksk"
pcmCommon "gitlink.org.cn/JCCE/PCM/adaptor/container_api_adaptor/common/config"
)
func CreateEksInstance(cloudStack string, akskPath string, configPath string) {

5
gen.sh Executable file
View File

@ -0,0 +1,5 @@
#/bin/bash
rm -rf lan_trans/gen/*
buf mod update
buf generate

10
go.mod
View File

@ -1,12 +1,18 @@
module PCM
module gitlink.org.cn/JCCE/PCM
go 1.17
require (
github.com/Unknwon/goconfig v1.0.0
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1530
github.com/golang/glog v1.0.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0
github.com/pkg/errors v0.9.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.371
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.371
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.28.0
k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
@ -17,7 +23,6 @@ require (
github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550 // indirect
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d // indirect
github.com/imdario/mergo v0.3.5 // indirect
@ -34,7 +39,6 @@ require (
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

17
internal/server/server.go Normal file
View File

@ -0,0 +1,17 @@
package server
import (
"context"
"gitlink.org.cn/JCCE/PCM/lan_trans/gen/idl/demo"
)
type Server struct {
// 使用unsafe可以强制让编译器检查是否实现了相关方法
demo.UnsafeDemoServiceServer
}
func (s *Server) Echo(ctx context.Context, req *demo.StringMessage) (*demo.StringMessage, error) {
return &demo.StringMessage{
Value: "Welcome to JCCE PCM",
}, nil
}

View File

@ -1,6 +1,16 @@
version: v1
plugins:
- name: cpp
out: gen/proto/cpp
- name: java
out: gen/proto/java
- name: go
out: gen
opt:
- paths=source_relative
- name: go-grpc
out: gen
opt:
- paths=source_relative
- name: grpc-gateway
out: gen
opt:
- paths=source_relative
- name: openapiv2
out: gen/openapiv2

View File

@ -1,4 +1,5 @@
version: v1
name: buf.build/JCCE/PCM
breaking:
use:
- FILE

View File

@ -1,7 +1,7 @@
syntax = "proto3";
package demo;
option go_package = "gitlink.org.cn/JCCE/PCM/lan_trans/gen/proto/demo";
option go_package = "gitlink.org.cn/JCCE/PCM/lan_trans/gen/idl/demo";
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

64
main.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
"context"
"flag"
"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/pkg/errors"
"gitlink.org.cn/JCCE/PCM/internal/server"
"gitlink.org.cn/JCCE/PCM/lan_trans/gen/idl/demo"
"google.golang.org/grpc"
"net"
"net/http"
)
var (
// command-line options:
// gRPC server endpoint
grpcServerEndpoint = flag.String("grpc-server-endpoint", ":9090", ":8081")
)
func run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Register gRPC server endpoint
// Note: Make sure the gRPC server is running properly and accessible
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
if err := demo.RegisterDemoServiceHandlerFromEndpoint(ctx, mux, *grpcServerEndpoint, opts); err != nil {
return errors.Wrap(err, "RegisterDemoServiceHandlerFromEndpoint error")
}
// Start HTTP server (and proxy calls to gRPC server endpoint)
return http.ListenAndServe(":8081", mux)
}
func main() {
var configFile string
flag.StringVar(&configFile, "conf", "config.yaml", "config.yaml")
flag.Parse()
defer glog.Flush()
glog.Infof("load tenant from file finished")
go func() {
lis, err := net.Listen("tcp", ":9090")
if err != nil {
glog.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
demo.RegisterDemoServiceServer(s, &server.Server{})
if err = s.Serve(lis); err != nil {
glog.Fatalf("failed to serve: %v", err)
}
}()
if err := run(); err != nil {
glog.Fatal(err)
}
}

13
swagger.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# 请先保证swagger的安装可参考 https://goswagger.io/install.html
swagger mixin lan_trans/gen/openapiv2/idl/*/*.json -o lan_trans/gen/swagger.json
rm -rf lan_trans/gen/openapiv2
# 将机器的sshkey保存到公有云机器121.41.88.120上
#scp -P 22 gen/swagger.json root@121.41.88.120:/root/doc
# 服务端运行的docker
# docker run --name swagger -d --rm -p 80:80 -v /root/doc:/usr/share/nginx/html/swagger -e SPEC_URL=swagger/swagger.json redocly/redoc