feat: pcm-k8s-native增删改查功能实现

Signed-off-by: devad <cossjie@foxmail.com>
This commit is contained in:
devad 2023-03-14 15:48:52 +08:00
parent a5d3c89ac0
commit 2171a4361f
19 changed files with 705 additions and 6 deletions

4
.gitignore vendored
View File

@ -31,3 +31,7 @@ configs/tenanter.yaml
log/
/go_build_gitlink_org_cn_JCCE_PCM
/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenative/
/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenativeclient/
/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/server/
/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc/

View File

@ -99,7 +99,7 @@ func Post(ctx *context.Context, url string, contentType string,
client := httpclient.NewHttpsClient()
req, err := NewRequest(client)
if err != nil {
logx.WithContext(*ctx).Errorf("AC", "Func: %s, Post Request URL : %s, Init Request Client err: %s", funcName, url, err.Error())
logx.WithContext(*ctx).Errorf("AC Func: %s, Post Request URL : %s, Init Request Client err: %s", funcName, url, err.Error())
return nil, err
}

View File

@ -0,0 +1,10 @@
Name: kubenative.rpc
ListenOn: 0.0.0.0:2200
#Etcd:
# Hosts:
# - 127.0.0.1:2379
# Key: kubenative.rpc
KubeConfig:
Server: 10.101.15.3:6443
Token: eyJhbGciOiJSUzI1NiIsImtpZCI6IllCbUxDUnBlNG1FWnh2aVRpcHpHdU1WT1ViZEpkRVBJcFVHcjJlRUk5WUEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlLW5hdGl2ZS10b2tlbi05OTRjMiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlLW5hdGl2ZSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjdkZWY5MmFmLTU4ZDAtNGQwMy04M2ZmLTgxYTIzYWQzNDY3ZCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTprdWJlLW5hdGl2ZSJ9.EI6ZEBEZysdxQHe4_I6eu4gTKymgZxuOAE6CSjK4JT0jXr2CLuXW0V9Nw3FZjEfWR7F2fEVBEnFkOOqvsfWIWOwduATV8t4LfZwCzBJZArTOw4AvV-WsYiyaJXQhx0AnowSJTZyY55ZuSenUFf6ZrDhvlkUGkTNU9fmNMzWpcjwcYKrI_ZoI9pu0mXtwr0RdjvklQqaR1bGI7m1j6uWir2NZrvgJt0-kdsFyRtAzZjiCSHtf2YO6Cm5-w2zPJp-SoNvaO97cJy_wjGIrUHrP-CwqZ0m_-SzZ23Z-sH91U1zGrKD6dso-5-qOArPODrRr-GNG5kTrKkLyRnsAOm7vvw

View File

@ -0,0 +1,8 @@
package config
import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
KubeConfig KubeConfig
}

View File

@ -0,0 +1,6 @@
package config
type KubeConfig struct {
Server string `json:"server"`
Token string `json:"token"`
}

View File

@ -0,0 +1,101 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/util"
"bytes"
"context"
"fmt"
"io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/restmapper"
sigyaml "sigs.k8s.io/yaml"
)
// CreateOrUpdateFromYaml 实现apply
func CreateOrUpdateFromYaml(yamlString string) error {
d := yaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
clientSet, err := util.GetKubeClientSet()
dynamicClient, err := util.GetKubeDynamicClient()
for {
var rawObj runtime.RawExtension
err = d.Decode(&rawObj)
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("decode is err %v", err)
}
obj, _, err := syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, nil)
if err != nil {
return fmt.Errorf("rawobj is err%v", err)
}
unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return fmt.Errorf("tounstructured is err %v", err)
}
unstructureObj := &unstructured.Unstructured{Object: unstructuredMap}
gvr, err := GetGVR(clientSet, unstructureObj.GroupVersionKind())
if err != nil {
return err
}
unstructuredYaml, err := sigyaml.Marshal(unstructureObj)
if err != nil {
return fmt.Errorf("unable to marshal resource as yaml: %w", err)
}
if unstructureObj.GetNamespace() == "" {
unstructureObj.SetNamespace("default")
}
_, getErr := dynamicClient.Resource(gvr).Namespace(unstructureObj.GetNamespace()).Get(context.Background(), unstructureObj.GetName(), metav1.GetOptions{})
if getErr != nil {
_, createErr := dynamicClient.Resource(gvr).Namespace(unstructureObj.GetNamespace()).Create(context.Background(), unstructureObj, metav1.CreateOptions{})
if createErr != nil {
return createErr
}
}
force := true
_, err = dynamicClient.Resource(gvr).
Namespace(unstructureObj.GetNamespace()).
Patch(context.Background(),
unstructureObj.GetName(),
types.ApplyPatchType,
unstructuredYaml, metav1.PatchOptions{
FieldManager: unstructureObj.GetName(),
Force: &force,
})
if err != nil {
return fmt.Errorf("unable to patch resource: %w", err)
}
}
return nil
}
// GetGVR 获取GVR
func GetGVR(clientSet *kubernetes.Clientset, gvk schema.GroupVersionKind) (schema.GroupVersionResource, error) {
gr, err := restmapper.GetAPIGroupResources(clientSet)
if err != nil {
return schema.GroupVersionResource{}, err
}
mapper := restmapper.NewDiscoveryRESTMapper(gr)
mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
return schema.GroupVersionResource{}, err
}
return mapping.Resource, nil
}

View File

@ -0,0 +1,41 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenative"
"context"
"k8s.io/apimachinery/pkg/util/json"
"github.com/zeromicro/go-zero/core/logx"
)
type ApplyYamlLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewApplyYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyYamlLogic {
return &ApplyYamlLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApplyYamlLogic) ApplyYaml(in *kubenative.ApplyReq) (*kubenative.Resp, error) {
msg := &kubenative.Resp{
Code: "200",
Msg: "success",
Data: "",
}
err := CreateOrUpdateFromYaml(in.YamlString)
if err != nil {
msg.Code = "500"
msg.Msg = "failed"
marshal, _ := json.Marshal(err)
msg.Data = string(marshal)
return msg, nil
}
return msg, nil
}

View File

@ -0,0 +1,91 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/util"
"bytes"
"context"
"github.com/sirupsen/logrus"
"github.com/zeromicro/go-zero/core/logx"
"io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/restmapper"
)
// DeleteFromYaml 实现delete
func DeleteFromYaml(yamlString string) (err error) {
d := yaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
clientSet, err := util.GetKubeClientSet()
dynamicClient, err := util.GetKubeDynamicClient()
dc := clientSet.Discovery()
restMapperRes, err := restmapper.GetAPIGroupResources(dc)
if err != nil {
logx.WithContext(context.TODO()).Errorf("delete %v %v \n", err)
return nil
}
restMapper := restmapper.NewDiscoveryRESTMapper(restMapperRes)
for {
ext := runtime.RawExtension{}
if err := d.Decode(&ext); err != nil {
if err == io.EOF {
break
}
logx.WithContext(context.TODO()).Errorf("delete %v %v \n", err)
}
obj, gvk, err := unstructured.UnstructuredJSONScheme.Decode(ext.Raw, nil, nil)
if err != nil {
logrus.Error(err)
return err
}
mapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
logrus.Error(err)
return err
}
// runtime.Object转换为unstructed
unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
logrus.Error(err)
return err
}
var unstruct unstructured.Unstructured
unstruct.Object = unstructuredObj
tmpMetadata := unstructuredObj["metadata"].(map[string]interface{})
tmpName := tmpMetadata["name"].(string)
tmpKind := unstructuredObj["kind"].(string)
if unstruct.GetNamespace() == "" {
unstruct.SetNamespace("default")
}
logrus.Info("deleting resource name: " + tmpName + ", kind: " + tmpKind + ", ns: " + unstruct.GetNamespace())
if unstruct.GetNamespace() == "" {
err := dynamicClient.Resource(mapping.Resource).Delete(context.TODO(), tmpName, metav1.DeleteOptions{})
if err != nil {
logrus.Error(err)
return err
}
} else {
err := dynamicClient.Resource(mapping.Resource).Namespace(unstruct.GetNamespace()).Delete(context.TODO(), tmpName, metav1.DeleteOptions{})
if err != nil {
logrus.Error(err)
return err
}
}
}
return err
}

View File

@ -0,0 +1,39 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenative"
"context"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteYamlLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteYamlLogic {
return &DeleteYamlLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DeleteYamlLogic) DeleteYaml(in *kubenative.ApplyReq) (*kubenative.Resp, error) {
msg := &kubenative.Resp{
Code: "200",
Msg: "success",
Data: "",
}
err := DeleteFromYaml(in.YamlString)
if err != nil {
msg.Code = "500"
msg.Msg = "failed"
msg.Data = "服务繁忙"
return msg, nil
}
return msg, nil
}

View File

@ -0,0 +1,58 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/util"
"bytes"
"context"
"fmt"
"io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/util/yaml"
)
// GetFromYaml 实现get
func GetFromYaml(yamlString string) (data *unstructured.Unstructured, err error) {
d := yaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
clientSet, err := util.GetKubeClientSet()
dynamicClient, err := util.GetKubeDynamicClient()
for {
var (
rawObj runtime.RawExtension
)
err = d.Decode(&rawObj)
if err == io.EOF {
break
}
obj, _, err := syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, nil)
if err != nil {
return data, fmt.Errorf("rawobj is err%v", err)
}
unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return data, fmt.Errorf("tounstructured is err %v", err)
}
unstructuredObj := &unstructured.Unstructured{Object: unstructuredMap}
gvr, err := GetGVR(clientSet, unstructuredObj.GroupVersionKind())
if err != nil {
return data, fmt.Errorf("get gvr is false %v", err)
}
if unstructuredObj.GetNamespace() == "" {
unstructuredObj.SetNamespace("default")
}
data, err = dynamicClient.Resource(gvr).Namespace(unstructuredObj.GetNamespace()).Get(context.TODO(), unstructuredObj.GetName(), metav1.GetOptions{})
if err != nil {
return data, fmt.Errorf("get resource err %v", err)
}
}
return data, nil
}

View File

@ -0,0 +1,46 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenative"
"context"
"encoding/json"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogic {
return &GetLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetLogic) Get(in *kubenative.GetReq) (*kubenative.Resp, error) {
msg := &kubenative.Resp{
Code: "200",
Msg: "success",
Data: "",
}
data, err := GetFromYaml(in.YamlString)
if err != nil && err.Error() != "EOF" {
marshal, _ := json.Marshal(err)
msg.Code = "500"
msg.Msg = "failed"
msg.Data = string(marshal)
return msg, nil
}
if data != nil {
marshal, _ := json.Marshal(data)
msg.Data = string(marshal)
}
return msg, nil
}

View File

@ -0,0 +1,58 @@
package logic
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/util"
"bytes"
"context"
"fmt"
"io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/util/yaml"
)
// ListFromYaml 实现List
func ListFromYaml(yamlString string) (unstructuredList *unstructured.UnstructuredList, err error) {
d := yaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
clientSet, err := util.GetKubeClientSet()
dynamicClient, err := util.GetKubeDynamicClient()
for {
var (
rawObj runtime.RawExtension
)
err = d.Decode(&rawObj)
if err == io.EOF {
break
}
obj, _, err := syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, nil)
if err != nil {
return unstructuredList, fmt.Errorf("rawobj is err%v", err)
}
unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return unstructuredList, fmt.Errorf("tounstructured is err %v", err)
}
unstructuredObj := &unstructured.Unstructured{Object: unstructuredMap}
gvr, err := GetGVR(clientSet, unstructuredObj.GroupVersionKind())
if err != nil {
return unstructuredList, fmt.Errorf("get gvr is false %v", err)
}
if unstructuredObj.GetNamespace() == "" {
unstructuredObj.SetNamespace("default")
}
unstructuredList, err = dynamicClient.Resource(gvr).Namespace(unstructuredObj.GetNamespace()).List(context.Background(), metav1.ListOptions{})
if err != nil {
return unstructuredList, fmt.Errorf("get resource err %v", err)
}
}
return unstructuredList, nil
}

View File

@ -0,0 +1,47 @@
package logic
import (
"context"
"encoding/json"
"fmt"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenative"
"github.com/zeromicro/go-zero/core/logx"
)
type ListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
return &ListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ListLogic) List(in *kubenative.ListReq) (*kubenative.Resp, error) {
msg := &kubenative.Resp{
Code: "200",
Msg: "success",
Data: "",
}
unstructuredList, err := ListFromYaml(in.YamlString)
if err != nil && err.Error() != "EOF" {
msg.Code = "500"
msg.Msg = "failed"
msg.Data = "服务繁忙"
return msg, nil
}
if unstructuredList != nil {
marshal, _ := json.Marshal(unstructuredList)
msg.Data = string(marshal)
}
fmt.Print("查询数据", msg)
return msg, nil
}

View File

@ -0,0 +1,103 @@
package util
import (
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/config"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc"
"context"
"flag"
"fmt"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"gopkg.in/yaml.v3"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
var configFile = flag.String("f2", "adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/etc/kubenative.yaml", "the config file")
var (
clientSet *kubernetes.Clientset
dynamicClient dynamic.Interface
restConfig *rest.Config
discoveryClient *discovery.DiscoveryClient
)
func initKubeRestConfig() *rest.Config {
var cf config.Config
conf.MustLoad(*configFile, &cf)
ctx := svc.NewServiceContext(cf)
restConfig = &rest.Config{
Host: ctx.Config.KubeConfig.Server,
BearerToken: ctx.Config.KubeConfig.Token,
TLSClientConfig: rest.TLSClientConfig{
Insecure: true,
},
}
return restConfig
}
// GetKubeClientSet 获取kubernetes ClientSet
func GetKubeClientSet() (*kubernetes.Clientset, error) {
if clientSet != nil {
return clientSet, nil
}
var err error
// 实例化客户端
clientSet, err = kubernetes.NewForConfig(initKubeRestConfig())
if err != nil {
logx.WithContext(context.TODO()).Errorf("Initialization kubernetes clientSet failed ", "err: %s", err.Error())
return nil, err
}
return clientSet, nil
}
// GetKubeDynamicClient 获取kubernetes DynamicClient
func GetKubeDynamicClient() (dynamic.Interface, error) {
if dynamicClient != nil {
return dynamicClient, nil
}
var err error
// 实例化客户端
dynamicClient, err = dynamic.NewForConfig(initKubeRestConfig())
if err != nil {
logx.WithContext(context.TODO()).Errorf("Initialization kubernetes dynamicClient failed ", "err: %s", err.Error())
return nil, err
}
return dynamicClient, nil
}
// GetDiscoveryClient 获取kubernetes DiscoveryClient
func GetDiscoveryClient() (*discovery.DiscoveryClient, error) {
if discoveryClient != nil {
return discoveryClient, nil
}
var err error
// 创建discovery客户端
discoveryClient, err = discovery.NewDiscoveryClientForConfig(initKubeRestConfig())
if err != nil {
logx.WithContext(context.TODO()).Errorf("Initialization kubernetes discoveryClient failed ", "err: %s", err.Error())
return nil, err
}
return discoveryClient, nil
}
// YamlStr2Map yaml str转换map
func YamlStr2Map(yamlStr string) (res map[string]interface{}, err error) {
var yamlMap map[string]interface{}
err = yaml.Unmarshal([]byte(yamlStr), &yamlMap)
if err != nil {
return nil, err
}
return yamlMap, nil
}
func MapInterface2String(inputData map[string]interface{}) map[string]string {
ret := make(map[string]string, len(inputData))
for k, v := range inputData {
ret[k] = fmt.Sprint(v)
}
return ret
}

View File

@ -0,0 +1,39 @@
package main
import (
"flag"
"fmt"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/config"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/server"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/svc"
"PCM/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/kubenative"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/etc/kubenative.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
kubenative.RegisterKubeNativeServer(grpcServer, server.NewKubeNativeServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}

View File

@ -0,0 +1,46 @@
syntax = "proto3";
import "google/protobuf/any.proto";
import "google/protobuf/empty.proto";
package kubenative;
option go_package = "/kubenative";
message Unstructured{
map<string, google.protobuf.Any> Unstructured = 1;
}
message UnstructuredList{
map<string, google.protobuf.Any> object = 1;
repeated Unstructured items = 2;
}
message GetReq {
string yamlString = 1;
}
message ListReq {
string yamlString = 1;
}
message ApplyReq{
string yamlString = 1; // @gotags: copier:"yamlString", json:"yaml_string"
}
message ApplyErr{
map<string, google.protobuf.Any> obj = 1;
}
message Resp{
string code = 1; // @gotags: copier:"Code", json:"code"
string msg = 2; // @gotags: copier:"Msg", json:"msg"
string data = 3; // @gotags: copier:"Data", json:"msg"
}
service kubeNative {
rpc ApplyYaml(ApplyReq) returns(Resp);
rpc DeleteYaml(ApplyReq) returns(Resp);
rpc Get(GetReq) returns (Resp);
rpc List(ListReq) returns (Resp);
}

View File

@ -1,3 +0,0 @@
syntax = "proto3";
package template;

7
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.3.1
github.com/sirupsen/logrus v1.8.1
github.com/sony/sonyflake v1.1.0
github.com/zeromicro/go-zero v1.4.4
google.golang.org/grpc v1.50.1
@ -15,6 +16,8 @@ require (
gorm.io/driver/mysql v1.4.7
gorm.io/gorm v1.24.5
k8s.io/api v0.22.9
k8s.io/apimachinery v0.22.9
k8s.io/client-go v0.22.9
sigs.k8s.io/yaml v1.2.0
)
@ -43,6 +46,7 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
@ -58,6 +62,7 @@ require (
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
@ -86,8 +91,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.22.9 // indirect
k8s.io/client-go v0.22.9 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect

2
go.sum
View File

@ -626,6 +626,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
@ -781,6 +782,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sony/sonyflake v1.1.0 h1:wnrEcL3aOkWmPlhScLEGAXKkLAIslnBteNUq4Bw6MM4=
github.com/sony/sonyflake v1.1.0/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y=