mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
feat(db): define k8s resource model under application
This commit is contained in:
parent
0c457edbe0
commit
03756df5ed
@ -269,7 +269,7 @@ type SyncComponentReq struct {
|
||||
// ComponentK8sAttribute -
|
||||
type ComponentK8sAttribute struct {
|
||||
// Name Define the attribute name, which is currently supported
|
||||
// [nodeSelector/labels/tolerations/volumes/serviceAccountName/privileged/affinity]
|
||||
// [nodeSelector/labels/tolerations/volumes/serviceAccountName/privileged/affinity/volumeMounts]
|
||||
// The field name should be the same as that in the K8s resource yaml file.
|
||||
Name string `json:"name"`
|
||||
|
||||
|
@ -629,3 +629,9 @@ type ComponentK8sAttributeDao interface {
|
||||
CreateOrUpdateAttributesInBatch(attributes []*model.ComponentK8sAttributes) error
|
||||
DeleteByComponentIDAndName(componentID, name string) error
|
||||
}
|
||||
|
||||
// K8sResourceDao -
|
||||
type K8sResourceDao interface {
|
||||
Dao
|
||||
ListByAppID(appID string) ([]model.K8sResource, error)
|
||||
}
|
||||
|
2
db/db.go
2
db/db.go
@ -47,6 +47,8 @@ type Manager interface {
|
||||
AppConfigGroupServiceDaoTransactions(db *gorm.DB) dao.AppConfigGroupServiceDao
|
||||
AppConfigGroupItemDao() dao.AppConfigGroupItemDao
|
||||
AppConfigGroupItemDaoTransactions(db *gorm.DB) dao.AppConfigGroupItemDao
|
||||
K8sResourceDao() dao.K8sResourceDao
|
||||
K8sResourceDaoTransactions(db *gorm.DB) dao.K8sResourceDao
|
||||
EnterpriseDao() dao.EnterpriseDao
|
||||
TenantDao() dao.TenantDao
|
||||
TenantDaoTransactions(db *gorm.DB) dao.TenantDao
|
||||
|
@ -1,3 +1,21 @@
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2020-2022 Goodrain Co., Ltd.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
||||
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
||||
// must be obtained first.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
const (
|
||||
@ -73,7 +91,25 @@ type ApplicationConfigGroup struct {
|
||||
Enable bool `gorm:"column:enable" json:"enable"`
|
||||
}
|
||||
|
||||
// TableName return tableName "application"
|
||||
// TableName return tableName "app_config_group"
|
||||
func (t *ApplicationConfigGroup) TableName() string {
|
||||
return "app_config_group"
|
||||
}
|
||||
|
||||
// K8sResource Save k8s resources under the application
|
||||
type K8sResource struct {
|
||||
Model
|
||||
AppID string `gorm:"column:app_id" json:"app_id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
// The resource kind is the same as that in k8s cluster
|
||||
Kind string `gorm:"column:kind" json:"kind"`
|
||||
// Yaml file for the storage resource
|
||||
Content string `gorm:"column:content;type:longtext" json:"content"`
|
||||
// resource create status
|
||||
Status string `gorm:"column:status;type:longtext" json:"status"`
|
||||
}
|
||||
|
||||
// TableName return tableName "k8s_resources"
|
||||
func (k *K8sResource) TableName() string {
|
||||
return "k8s_resources"
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ const (
|
||||
K8sAttributeNameServiceAccountName = "serviceAccountName"
|
||||
K8sAttributeNamePrivileged = "privileged"
|
||||
K8sAttributeNameAffinity = "affinity"
|
||||
K8sAttributeNameVolumeMounts = "volumeMounts"
|
||||
)
|
||||
|
||||
// ComponentK8sAttributes -
|
||||
@ -35,7 +36,7 @@ type ComponentK8sAttributes struct {
|
||||
ComponentID string `gorm:"column:component_id" json:"component_id"`
|
||||
|
||||
// Name Define the attribute name, which is currently supported
|
||||
// [nodeSelector/labels/tolerations/volumes/serviceAccountName/privileged/affinity]
|
||||
// [nodeSelector/labels/tolerations/volumes/serviceAccountName/privileged/affinity/volumeMounts]
|
||||
// The field name should be the same as that in the K8s resource yaml file.
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
|
||||
|
48
db/mysql/dao/k8s_resource.go
Normal file
48
db/mysql/dao/k8s_resource.go
Normal file
@ -0,0 +1,48 @@
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2022-2022 Goodrain Co., Ltd.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
||||
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
||||
// must be obtained first.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/db/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
// K8sResourceDaoImpl k8s resource dao
|
||||
type K8sResourceDaoImpl struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
// AddModel add model
|
||||
func (t *K8sResourceDaoImpl) AddModel(mo model.Interface) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateModel update model
|
||||
func (t *K8sResourceDaoImpl) UpdateModel(mo model.Interface) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListByAppID list by app id
|
||||
func (t *K8sResourceDaoImpl) ListByAppID(appID string) ([]model.K8sResource, error) {
|
||||
var resources []model.K8sResource
|
||||
if err := t.DB.Where("app_id = ?", appID).Find(&resources).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resources, nil
|
||||
}
|
@ -661,3 +661,17 @@ func (m *Manager) ComponentK8sAttributeDaoTransactions(db *gorm.DB) dao.Componen
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
|
||||
// K8sResourceDao -
|
||||
func (m *Manager) K8sResourceDao() dao.K8sResourceDao {
|
||||
return &mysqldao.K8sResourceDaoImpl{
|
||||
DB: m.db,
|
||||
}
|
||||
}
|
||||
|
||||
// K8sResourceDaoTransactions -
|
||||
func (m *Manager) K8sResourceDaoTransactions(db *gorm.DB) dao.K8sResourceDao {
|
||||
return &mysqldao.K8sResourceDaoImpl{
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +156,7 @@ func (m *Manager) RegisterTableModel() {
|
||||
m.models = append(m.models, &model.TenantServiceScalingRecords{})
|
||||
m.models = append(m.models, &model.TenantServiceMonitor{})
|
||||
m.models = append(m.models, &model.ComponentK8sAttributes{})
|
||||
m.models = append(m.models, &model.K8sResource{})
|
||||
}
|
||||
|
||||
//CheckTable check and create tables
|
||||
|
Loading…
Reference in New Issue
Block a user