diff --git a/container/server/client/client.go b/container/server/client/client.go new file mode 100644 index 0000000000000000000000000000000000000000..b66fd26e6fe1716246828b2a19fcfce26da6b8dd --- /dev/null +++ b/container/server/client/client.go @@ -0,0 +1,16 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo-plugins licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Jul 17 11:37:57 2024 +0800 + */ +package client + +import ( + "gitee.com/openeuler/PilotGo/sdk/plugin/client" +) + +var ( + ContainerClient *client.Client +) diff --git a/container/server/config.yml.templete b/container/server/config.yml.templete index 2067b02bdbc7327c74941f0e369305e233252aef..42d95704ed1b5186c486e64c3fed50b14a0d9ac5 100644 --- a/container/server/config.yml.templete +++ b/container/server/config.yml.templete @@ -11,4 +11,12 @@ log: driver: stdout #可选stdout和file。stdout:输出到终端控制台;file:输出到path下的指定文件。 path: ./log/pilotgo_server.log max_file: 1 - max_size: 10485760 \ No newline at end of file + max_size: 10485760 +etcd: + endpoints: + - "localhost:2379" + service_name: "container-service" + version: "3.0" + dialTimeout: 5s + menu_name: "容器管理" + icon: "Odometer" \ No newline at end of file diff --git a/container/server/config/config.go b/container/server/config/config.go index c4ac4e2eef64c4bc23fb69e5359e1740dc61766e..9b97dfebd8f01af42c255f3336dc07a744a525d5 100644 --- a/container/server/config/config.go +++ b/container/server/config/config.go @@ -3,6 +3,7 @@ package config import ( "fmt" "os" + "time" "gitee.com/openeuler/PilotGo/sdk/logger" "gopkg.in/yaml.v3" @@ -19,11 +20,19 @@ type MysqlConf struct { Password string `yaml:"password"` Database string `yaml:"database"` } - +type Etcd struct { + Endpoints []string `yaml:"endpoints"` + ServiveName string `yaml:"service_name"` + Version string `yaml:"version"` + DialTimeout time.Duration `yaml:"dialTimeout"` + MenuName string `yaml:"menu_name"` + Icon string `yaml:"icon"` +} type ServerConfig struct { Http *HttpConf `yaml:"http"` Mysql *MysqlConf `yaml:"mysql"` Logopts *logger.LogOpts `yaml:"log"` + Etcd *Etcd `yaml:"etcd" mapstructure:"etcd"` } const config_file = "./config.yml" diff --git a/container/server/main.go b/container/server/main.go index b02a2fe65391dccf852525aa5ee7bd3c3a9e83a9..727980dab52af52db8f85f3adddce2197bbc5f57 100644 --- a/container/server/main.go +++ b/container/server/main.go @@ -4,26 +4,17 @@ import ( "fmt" "os" + "gitee.com/openeuler/PilotGo/sdk/go-micro/registry" "gitee.com/openeuler/PilotGo/sdk/logger" "gitee.com/openeuler/PilotGo/sdk/plugin/client" "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/PilotGo-plugin-event/service" + cli "openeuler.org/PilotGo/container-plugin/client" "openeuler.org/PilotGo/container-plugin/config" "openeuler.org/PilotGo/container-plugin/database" "openeuler.org/PilotGo/container-plugin/httphandler" ) -const Version = "0.0.1" - -var PluginInfo = &client.PluginInfo{ - Name: "container", - Version: Version, - Description: "Container management plugin", - Author: "wangjunqi", - Email: "wangjunqi@kylinos.cn", - Url: "http://192.168.75.100:9998/plugin/container", - // ReverseDest: "", -} - func main() { fmt.Println("hello gala-ops") @@ -36,8 +27,30 @@ func main() { server := gin.Default() - GlobalClient := client.DefaultClient(PluginInfo) - GlobalClient.RegisterHandlers(server) + sr, err := registry.NewServiceRegistrar(®istry.Options{ + Endpoints: config.Config().Etcd.Endpoints, + ServiceAddr: config.Config().Http.Addr, + ServiceName: config.Config().Etcd.ServiveName, + Version: config.Config().Etcd.Version, + MenuName: config.Config().Etcd.MenuName, + Icon: config.Config().Etcd.Icon, + DialTimeout: config.Config().Etcd.DialTimeout, + Extentions: service.GetExtentions(), + Permissions: service.GetPermissions(), + }) + if err != nil { + logger.Error("failed to initialize registry: %s", err) + os.Exit(-1) + } + + client, err := client.NewClient(config.Config().Etcd.ServiveName, sr.Registry) + if err != nil { + logger.Error("failed to create plugin client: %s", err) + os.Exit(-1) + } + + cli.ContainerClient = client + cli.ContainerClient.RegisterHandlers(server) InitRouter(server) if err := server.Run(config.Config().Http.Addr); err != nil {