Compare commits

...

2 Commits

Author SHA1 Message Date
zhangwei bd8353cefb 修改rpc地址 2024-01-08 16:26:32 +08:00
zhangwei 2bc04fb986 修改状态信息 2023-12-14 17:20:04 +08:00
7 changed files with 12 additions and 98 deletions

View File

@ -23,8 +23,8 @@ KubeConfig:
PcmCoreRpcConf:
Endpoints:
- 119.45.100.73:32456
# Endpoints:
# - 0.0.0.0:2004
NonBlock: true
# Endpoints:
# - 0.0.0.0:2004
# NonBlock: true
ParticipantId: 1696118513460056064

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.3
github.com/zeromicro/go-zero v1.6.0
gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.14-0.20231206063304-ae0e5330582a
gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.13-0.20231212031023-6c24bf2812d4
gitlink.org.cn/jcce-pcm/utils v0.0.2
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0

8
go.sum
View File

@ -198,8 +198,8 @@ github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE
github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/zeromicro/go-zero v1.6.0 h1:UwSOR1lGZ2g7L0S07PM8RoneAcubtd5x//EfbuNucQ0=
github.com/zeromicro/go-zero v1.6.0/go.mod h1:E9GCFPb0SwsTKFBcFr9UynGvXiDMmfc6fI5F15vqvAQ=
gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.14-0.20231206063304-ae0e5330582a h1:+aZfuzxBddrVDwgzeRoipt5nrbHtQCtZ2piyvdhwMds=
gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.14-0.20231206063304-ae0e5330582a/go.mod h1:SUfW2b7f/AvTnwOtxDgTG+YCad9FWzo3p3zLLyurid8=
gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.13-0.20231212031023-6c24bf2812d4 h1:atSTLcxYGIm74EKYNinlf/MhzyjLraul+BkKTsE+2QQ=
gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.13-0.20231212031023-6c24bf2812d4/go.mod h1:QnnUd5bqfj8HqgIUbmlzy4UKcoBHqswMseOJAOADa1c=
gitlink.org.cn/jcce-pcm/utils v0.0.2 h1:Stif8W9C9TOCS2hw4g+OlOywDrsVYNrkiyKfBrWkT0w=
gitlink.org.cn/jcce-pcm/utils v0.0.2/go.mod h1:u8PTlBpzUyOlbQJgfSiutq91q/JtrJIQiPNDe4S/pGs=
go.etcd.io/etcd/api/v3 v3.5.10 h1:szRajuUUbLyppkhs9K6BRtjY37l66XQQmw7oZRANE4k=
@ -315,8 +315,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -1,19 +0,0 @@
package cron
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/participantservice"
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/internal/pkg"
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/internal/svc"
)
func ApplyList(svc *svc.ServiceContext) {
listResp, err := svc.ParticipantRpc.ApplyList(context.Background(), &participantservice.ApplyListReq{})
if err != nil {
return
}
for _, info := range listResp.InfoList {
pkg.Apply(info.YamlString, pkg.KClients[info.ParticipantName].ClientSet, pkg.KClients[info.ParticipantName].DynamicClient)
}
}

View File

@ -7,9 +7,9 @@ import (
func AddCronGroup(svc *svc.ServiceContext) {
// 同步任务信息到core端
//svc.Cron.AddFunc("*/5 * * * * ?", func() {
// SyncTask(svc)
//})
svc.Cron.AddFunc("*/5 * * * * ?", func() {
SyncTask(svc)
})
// 推送p端心跳
svc.Cron.AddFunc("*/5 * * * * ?", func() {
@ -21,13 +21,4 @@ func AddCronGroup(svc *svc.ServiceContext) {
tracker.NodesDynamicInfo(svc.Config.Participant.MetricsUrl, svc.ParticipantRpc, svc.ClientSet)
})
// 从C端同步配置信息
svc.Cron.AddFunc("0 0/2 * * * ?", func() {
SyncProfile(svc)
})
// 从C端同步配置信息
svc.Cron.AddFunc("*/5 * * * * ?", func() {
ApplyList(svc)
})
}

View File

@ -1,54 +0,0 @@
package cron
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/pcmcore"
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/internal/pkg"
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/internal/svc"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol"
)
// 同步配置
func SyncProfile(svc *svc.ServiceContext) {
//从c端获取ListParticipantResp信息
req := pcmcore.ParticipantTenant{}
resp, err := svc.ParticipantRpc.ListPhyInformation(context.Background(), &req)
if err != nil {
logx.Errorf("同步配置失败获取ListParticipantResp信息失败err:%v", err)
panic(err)
}
//遍历resp信息
for _, v := range resp.ParticipantPhys {
//过滤掉不是sealos的信息
if v.Type == "CLOUD" {
client := CreateClient(v.Address, v.Token)
pkg.KClients[v.Name] = &pkg.KubernetesClient{ClientSet: client.ClientSet, DynamicClient: client.DynamicClient}
}
}
//初始化客户端
logx.Infof("同步配置成功,====客户端信息:%v", pkg.KClients)
}
func CreateClient(server, token string) *pkg.KubernetesClient {
restConfig := &rest.Config{
Host: server,
RateLimiter: flowcontrol.NewTokenBucketRateLimiter(1000, 1000),
BearerToken: token,
TLSClientConfig: rest.TLSClientConfig{
Insecure: true,
},
}
clientSet, err := kubernetes.NewForConfig(restConfig)
if err != nil {
logx.Errorf("Failed to create Kubernetes client for %s: %v\n", server, err)
}
dynamicClient, err := dynamic.NewForConfig(restConfig)
if err != nil {
logx.Errorf("Failed to create Kubernetes client for %s: %v\n", server, err)
}
return &pkg.KubernetesClient{ClientSet: clientSet, DynamicClient: dynamicClient}
}

View File

@ -3,7 +3,6 @@ package main
import (
"context"
"flag"
"fmt"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
@ -44,11 +43,8 @@ func main() {
cron.AddCronGroup(ctx)
// 推送p端静态信息
PushParticipantInfo(ctx.Config, ctx.ParticipantRpc, ctx.ClientSet)
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
cron.SyncProfile(ctx)
// todo 测试
//Operate(ctx.ClientSet)
cron.SyncProfile(svc.NewServiceContext(c))
s.Start()
}