mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-03 12:18:09 +08:00
feat: plugin is used in pipeline (#1568)
* feat: update rbdplugin and rbdability resources * feat: plugin is used in pipeline --------- Co-authored-by: yangk <yangk@goodrain.com> Co-authored-by: 曲源成 <quyc@goodrain.com>
This commit is contained in:
parent
124a2f0846
commit
f9153b37a1
@ -347,7 +347,8 @@ func (c *ClusterController) ListRainbondComponents(w http.ResponseWriter, r *htt
|
|||||||
|
|
||||||
// ListPlugins -
|
// ListPlugins -
|
||||||
func (c *ClusterController) ListPlugins(w http.ResponseWriter, r *http.Request) {
|
func (c *ClusterController) ListPlugins(w http.ResponseWriter, r *http.Request) {
|
||||||
res, err := handler.GetClusterHandler().ListPlugins()
|
official, _ := strconv.ParseBool(r.URL.Query().Get("official"))
|
||||||
|
res, err := handler.GetClusterHandler().ListPlugins(official)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httputil.ReturnBcodeError(r, w, err)
|
httputil.ReturnBcodeError(r, w, err)
|
||||||
return
|
return
|
||||||
|
@ -40,6 +40,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// OfficialPluginLabel Those with this label are official plug-ins
|
||||||
|
OfficialPluginLabel = "plugin.rainbond.io/name"
|
||||||
|
)
|
||||||
|
|
||||||
// ClusterHandler -
|
// ClusterHandler -
|
||||||
type ClusterHandler interface {
|
type ClusterHandler interface {
|
||||||
GetClusterInfo(ctx context.Context) (*model.ClusterResource, error)
|
GetClusterInfo(ctx context.Context) (*model.ClusterResource, error)
|
||||||
@ -64,7 +69,7 @@ type ClusterHandler interface {
|
|||||||
GetRbdPods() (rbds []model.RbdResp, err error)
|
GetRbdPods() (rbds []model.RbdResp, err error)
|
||||||
CreateShellPod(regionName string) (pod *corev1.Pod, err error)
|
CreateShellPod(regionName string) (pod *corev1.Pod, err error)
|
||||||
DeleteShellPod(podName string) error
|
DeleteShellPod(podName string) error
|
||||||
ListPlugins() (rbds []*model.RainbondPlugins, err error)
|
ListPlugins(official bool) (rbds []*model.RainbondPlugins, err error)
|
||||||
ListAbilities() (rbds []unstructured.Unstructured, err error)
|
ListAbilities() (rbds []unstructured.Unstructured, err error)
|
||||||
GetAbility(abilityID string) (rbd *unstructured.Unstructured, err error)
|
GetAbility(abilityID string) (rbd *unstructured.Unstructured, err error)
|
||||||
UpdateAbility(abilityID string, ability *unstructured.Unstructured) error
|
UpdateAbility(abilityID string, ability *unstructured.Unstructured) error
|
||||||
@ -655,68 +660,21 @@ func (c *clusterAction) ListRainbondComponents(ctx context.Context) (res []*mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListPlugins -
|
// ListPlugins -
|
||||||
func (c *clusterAction) ListPlugins() (plugins []*model.RainbondPlugins, err error) {
|
func (c *clusterAction) ListPlugins(official bool) (plugins []*model.RainbondPlugins, err error) {
|
||||||
list, err := c.rainbondClient.RainbondV1alpha1().RBDPlugins(metav1.NamespaceAll).List(context.Background(), metav1.ListOptions{})
|
res, err := c.HandlePlugins()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "get rbd plugins")
|
return nil, errors.Wrap(err, "get rbd plugins")
|
||||||
}
|
}
|
||||||
|
if official {
|
||||||
// list plugin status
|
for _, plugin := range res {
|
||||||
var appIDs []string
|
if name, ok := plugin.Labels[OfficialPluginLabel]; ok && name != "" {
|
||||||
for _, item := range list.Items {
|
plugin.Name = name
|
||||||
if item.Labels["app_id"] != "" {
|
plugins = append(plugins, plugin)
|
||||||
appIDs = append(appIDs, item.Labels["app_id"])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
appStatuses := make(map[string]string)
|
|
||||||
statuses, err := c.statusCli.ListAppStatuses(context.Background(), &pb.AppStatusesReq{
|
|
||||||
AppIds: appIDs,
|
|
||||||
})
|
|
||||||
for _, status := range statuses.AppStatuses {
|
|
||||||
appStatuses[status.AppId] = status.Status
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establish the mapping relationship between appID and teamName
|
|
||||||
apps, err := db.GetManager().ApplicationDao().ListByAppIDs(appIDs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "get apps by app ids")
|
|
||||||
}
|
|
||||||
tenants, err := db.GetManager().TenantDao().GetALLTenants("")
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "get tenants")
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
appTeamIDs = make(map[string]string)
|
|
||||||
teamNames = make(map[string]string)
|
|
||||||
)
|
|
||||||
for _, app := range apps {
|
|
||||||
appTeamIDs[app.AppID] = app.TenantID
|
|
||||||
}
|
|
||||||
for _, tenant := range tenants {
|
|
||||||
teamNames[tenant.UUID] = tenant.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the returned data
|
|
||||||
for _, plugin := range list.Items {
|
|
||||||
appID := plugin.Labels["app_id"]
|
|
||||||
status := "NIL"
|
|
||||||
if appStatuses[appID] != "" {
|
|
||||||
status = appStatuses[appID]
|
|
||||||
}
|
|
||||||
logrus.Debugf("plugin Name: %v, namespace %v", plugin.Name, plugin.Namespace)
|
|
||||||
plugins = append(plugins, &model.RainbondPlugins{
|
|
||||||
RegionAppID: appID,
|
|
||||||
Name: plugin.GetName(),
|
|
||||||
TeamName: teamNames[appTeamIDs[appID]],
|
|
||||||
Icon: plugin.Spec.Icon,
|
|
||||||
Description: plugin.Spec.Description,
|
|
||||||
Version: plugin.Spec.Version,
|
|
||||||
Author: plugin.Spec.Author,
|
|
||||||
Status: status,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return plugins, nil
|
return plugins, nil
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAbilities -
|
// ListAbilities -
|
||||||
@ -816,3 +774,70 @@ func (c *clusterAction) UpdateAbility(abilityID string, ability *unstructured.Un
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandlePlugins -
|
||||||
|
func (c *clusterAction) HandlePlugins() (plugins []*model.RainbondPlugins, err error) {
|
||||||
|
list, err := c.rainbondClient.RainbondV1alpha1().RBDPlugins(metav1.NamespaceAll).List(context.Background(), metav1.ListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "get rbd plugins")
|
||||||
|
}
|
||||||
|
// list plugin status
|
||||||
|
var appIDs []string
|
||||||
|
for _, item := range list.Items {
|
||||||
|
if item.Labels["app_id"] != "" {
|
||||||
|
appIDs = append(appIDs, item.Labels["app_id"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appStatuses := make(map[string]string)
|
||||||
|
statuses, err := c.statusCli.ListAppStatuses(context.Background(), &pb.AppStatusesReq{
|
||||||
|
AppIds: appIDs,
|
||||||
|
})
|
||||||
|
for _, status := range statuses.AppStatuses {
|
||||||
|
appStatuses[status.AppId] = status.Status
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establish the mapping relationship between appID and teamName
|
||||||
|
apps, err := db.GetManager().ApplicationDao().ListByAppIDs(appIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "get apps by app ids")
|
||||||
|
}
|
||||||
|
tenants, err := db.GetManager().TenantDao().GetALLTenants("")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "get tenants")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
appTeamIDs = make(map[string]string)
|
||||||
|
teamNames = make(map[string]string)
|
||||||
|
)
|
||||||
|
for _, app := range apps {
|
||||||
|
appTeamIDs[app.AppID] = app.TenantID
|
||||||
|
}
|
||||||
|
for _, tenant := range tenants {
|
||||||
|
teamNames[tenant.UUID] = tenant.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct the returned data
|
||||||
|
for _, plugin := range list.Items {
|
||||||
|
appID := plugin.Labels["app_id"]
|
||||||
|
status := "NIL"
|
||||||
|
if appStatuses[appID] != "" {
|
||||||
|
status = appStatuses[appID]
|
||||||
|
}
|
||||||
|
logrus.Debugf("plugin Name: %v, namespace %v", plugin.Name, plugin.Namespace)
|
||||||
|
plugins = append(plugins, &model.RainbondPlugins{
|
||||||
|
RegionAppID: appID,
|
||||||
|
Name: plugin.GetName(),
|
||||||
|
TeamName: teamNames[appTeamIDs[appID]],
|
||||||
|
Icon: plugin.Spec.Icon,
|
||||||
|
Description: plugin.Spec.Description,
|
||||||
|
Version: plugin.Spec.Version,
|
||||||
|
Author: plugin.Spec.Author,
|
||||||
|
Status: status,
|
||||||
|
Alias: plugin.Spec.Alias,
|
||||||
|
AccessURLs: plugin.Spec.AccessURLs,
|
||||||
|
Labels: plugin.Labels,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return plugins, nil
|
||||||
|
}
|
||||||
|
@ -2190,6 +2190,9 @@ type RainbondPlugins struct {
|
|||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
Alias string `json:"alias"`
|
||||||
|
AccessURLs []string `json:"access_urls"`
|
||||||
|
Labels map[string]string `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUpdateGovernanceModeReq -
|
// CreateUpdateGovernanceModeReq -
|
||||||
|
@ -36,6 +36,10 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
description: RBDAbilitySpec defines the desired state of RBDAbility
|
description: RBDAbilitySpec defines the desired state of RBDAbility
|
||||||
properties:
|
properties:
|
||||||
|
alias:
|
||||||
|
description: Alias The alias is the name used for display, and if
|
||||||
|
this field is not set, the name in the metadata will be used
|
||||||
|
type: string
|
||||||
watchGroups:
|
watchGroups:
|
||||||
description: Foo is an example field of RBDAbility. Edit rbdplugin_types.go
|
description: Foo is an example field of RBDAbility. Edit rbdplugin_types.go
|
||||||
to remove/update
|
to remove/update
|
||||||
|
@ -36,6 +36,17 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
description: RBDPluginSpec defines the desired state of RBDPlugin
|
description: RBDPluginSpec defines the desired state of RBDPlugin
|
||||||
properties:
|
properties:
|
||||||
|
access_urls:
|
||||||
|
description: AccessUrls Access URL defines the accessible address
|
||||||
|
of the plug-in. If this field is not set, all accessible addresses
|
||||||
|
under the application will be listed in the platform.
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
alias:
|
||||||
|
description: Alias The alias is the name used for display, and if
|
||||||
|
this field is not set, the name in the metadata will be used
|
||||||
|
type: string
|
||||||
author:
|
author:
|
||||||
description: Foo is an example field of RBDPlugin. Edit rbdplugin_types.go
|
description: Foo is an example field of RBDPlugin. Edit rbdplugin_types.go
|
||||||
to remove/update
|
to remove/update
|
||||||
|
1
go.mod
1
go.mod
@ -110,6 +110,7 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/etcd v3.3.13+incompatible
|
github.com/coreos/etcd v3.3.13+incompatible
|
||||||
|
github.com/go-playground/assert/v2 v2.0.1
|
||||||
github.com/helm/helm v2.17.0+incompatible
|
github.com/helm/helm v2.17.0+incompatible
|
||||||
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
|
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
|
||||||
k8s.io/klog/v2 v2.60.1
|
k8s.io/klog/v2 v2.60.1
|
||||||
|
@ -32,6 +32,8 @@ type RBDAbilitySpec struct {
|
|||||||
|
|
||||||
// Foo is an example field of RBDAbility. Edit rbdplugin_types.go to remove/update
|
// Foo is an example field of RBDAbility. Edit rbdplugin_types.go to remove/update
|
||||||
WatchGroups []WatchGroup `json:"watchGroups,omitempty"`
|
WatchGroups []WatchGroup `json:"watchGroups,omitempty"`
|
||||||
|
// Alias The alias is the name used for display, and if this field is not set, the name in the metadata will be used
|
||||||
|
Alias string `json:"alias,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WatchGroup Defines what types of resources are listed.
|
// WatchGroup Defines what types of resources are listed.
|
||||||
|
@ -35,6 +35,11 @@ type RBDPluginSpec struct {
|
|||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Icon string `json:"icon,omitempty"`
|
Icon string `json:"icon,omitempty"`
|
||||||
|
// Alias The alias is the name used for display, and if this field is not set, the name in the metadata will be used
|
||||||
|
Alias string `json:"alias,omitempty"`
|
||||||
|
// AccessUrls Access URL defines the accessible address of the plug-in.
|
||||||
|
// If this field is not set, all accessible addresses under the application will be listed in the platform.
|
||||||
|
AccessURLs []string `json:"access_urls,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RBDPluginStatus defines the observed state of RBDPlugin
|
// RBDPluginStatus defines the observed state of RBDPlugin
|
||||||
|
@ -494,7 +494,7 @@ func (in *RBDPlugin) DeepCopyInto(out *RBDPlugin) {
|
|||||||
*out = *in
|
*out = *in
|
||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
out.Spec = in.Spec
|
in.Spec.DeepCopyInto(&out.Spec)
|
||||||
out.Status = in.Status
|
out.Status = in.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,6 +551,11 @@ func (in *RBDPluginList) DeepCopyObject() runtime.Object {
|
|||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *RBDPluginSpec) DeepCopyInto(out *RBDPluginSpec) {
|
func (in *RBDPluginSpec) DeepCopyInto(out *RBDPluginSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
if in.AccessURLs != nil {
|
||||||
|
in, out := &in.AccessURLs, &out.AccessURLs
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RBDPluginSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RBDPluginSpec.
|
||||||
|
Loading…
Reference in New Issue
Block a user