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:
Quyc 2023-02-23 14:15:37 +08:00 committed by GitHub
parent 124a2f0846
commit f9153b37a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 122 additions and 65 deletions

View File

@ -347,7 +347,8 @@ func (c *ClusterController) ListRainbondComponents(w http.ResponseWriter, r *htt
// ListPlugins -
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 {
httputil.ReturnBcodeError(r, w, err)
return

View File

@ -40,6 +40,11 @@ import (
"time"
)
const (
// OfficialPluginLabel Those with this label are official plug-ins
OfficialPluginLabel = "plugin.rainbond.io/name"
)
// ClusterHandler -
type ClusterHandler interface {
GetClusterInfo(ctx context.Context) (*model.ClusterResource, error)
@ -64,7 +69,7 @@ type ClusterHandler interface {
GetRbdPods() (rbds []model.RbdResp, err error)
CreateShellPod(regionName string) (pod *corev1.Pod, err 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)
GetAbility(abilityID string) (rbd *unstructured.Unstructured, err error)
UpdateAbility(abilityID string, ability *unstructured.Unstructured) error
@ -655,68 +660,21 @@ func (c *clusterAction) ListRainbondComponents(ctx context.Context) (res []*mode
}
// ListPlugins -
func (c *clusterAction) ListPlugins() (plugins []*model.RainbondPlugins, err error) {
list, err := c.rainbondClient.RainbondV1alpha1().RBDPlugins(metav1.NamespaceAll).List(context.Background(), metav1.ListOptions{})
func (c *clusterAction) ListPlugins(official bool) (plugins []*model.RainbondPlugins, err error) {
res, err := c.HandlePlugins()
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"])
if official {
for _, plugin := range res {
if name, ok := plugin.Labels[OfficialPluginLabel]; ok && name != "" {
plugin.Name = name
plugins = append(plugins, plugin)
}
}
return plugins, nil
}
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 res, nil
}
// ListAbilities -
@ -816,3 +774,70 @@ func (c *clusterAction) UpdateAbility(abilityID string, ability *unstructured.Un
}
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
}

View File

@ -2185,11 +2185,14 @@ type RainbondPlugins struct {
Name string `json:"name"`
TeamName string `json:"team_name"`
//Namespace string `json:"namespace"`
Icon string `json:"icon"`
Description string `json:"description"`
Version string `json:"version"`
Author string `json:"author"`
Status string `json:"status"`
Icon string `json:"icon"`
Description string `json:"description"`
Version string `json:"version"`
Author string `json:"author"`
Status string `json:"status"`
Alias string `json:"alias"`
AccessURLs []string `json:"access_urls"`
Labels map[string]string `json:"labels"`
}
// CreateUpdateGovernanceModeReq -

View File

@ -36,6 +36,10 @@ spec:
spec:
description: RBDAbilitySpec defines the desired state of RBDAbility
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:
description: Foo is an example field of RBDAbility. Edit rbdplugin_types.go
to remove/update

View File

@ -36,6 +36,17 @@ spec:
spec:
description: RBDPluginSpec defines the desired state of RBDPlugin
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:
description: Foo is an example field of RBDPlugin. Edit rbdplugin_types.go
to remove/update

1
go.mod
View File

@ -110,6 +110,7 @@ require (
require (
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
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
k8s.io/klog/v2 v2.60.1

View File

@ -32,6 +32,8 @@ type RBDAbilitySpec struct {
// Foo is an example field of RBDAbility. Edit rbdplugin_types.go to remove/update
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.

View File

@ -35,6 +35,11 @@ type RBDPluginSpec struct {
Version string `json:"version,omitempty"`
Description string `json:"description,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

View File

@ -494,7 +494,7 @@ func (in *RBDPlugin) DeepCopyInto(out *RBDPlugin) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
in.Spec.DeepCopyInto(&out.Spec)
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.
func (in *RBDPluginSpec) DeepCopyInto(out *RBDPluginSpec) {
*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.