-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from KubeLilin/dev
* 服务(添加/编辑) apply * 服务(添加/编辑) apply ; fixed bugs for service. * 项目部署指标统计 * 修改服务名=部署名+'-svc' * 获取部署列表添加服务端口属性
- Loading branch information
Showing
18 changed files
with
267 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 集群内部署APISIX | ||
## 修改配置 | ||
在apisix.yaml中找到service配置成NodePort(默认30000),端口只要与主机端口不冲突即可。 | ||
|
||
记录下文件中 admin_key的值,用于记录网关认证。 | ||
## 安装 | ||
* kubectl apply -f ./etcd.yaml | ||
* kubectl apply -f ./apisix.yaml | ||
* kubectl apply -f ./apisix-dashboard.yaml | ||
|
||
## Nginx Or Caddy 代理 | ||
使用反代服务将主机NodePort映射出来,这里反代IP即为网关的出口IP,可以绑定域名使用。 | ||
|
||
## 网关登记 | ||
PaaS数据库中,application_api_gateway表,新添加一条记录: | ||
* access_token: {admin_key} | ||
* admin_url:绑定的域名 | ||
* cluster_id:PaaS集群IP | ||
* vip:内网IP | ||
* cluster_ip:出口IP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package devops | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
"kubelilin/domain/dto" | ||
) | ||
|
||
type ProjectService struct { | ||
db *gorm.DB | ||
} | ||
|
||
func NewProjectService(db *gorm.DB) *ProjectService { | ||
return &ProjectService{db: db} | ||
} | ||
|
||
func (service *ProjectService) GetResourceMetrics(tenantId uint64, projectId uint64) (dto.DevOpsProjectResourceTotals, error) { | ||
var resourceList []dto.DevOpsProjectResource | ||
sql := `SELECT deploy.level,SUM(deploy.replicas) replicas,SUM(container.limit_cpu * deploy.replicas) sum_cpu,SUM(container.limit_memory * deploy.replicas) sum_memory | ||
FROM devops_projects dps | ||
INNER JOIN devops_projects_apps dpsapp on dpsapp.project_id = dps.id | ||
INNER JOIN sgr_tenant_deployments deploy on deploy.app_id = dpsapp.application_id | ||
INNER JOIN sgr_tenant_deployments_containers container on container.deploy_id = deploy.id | ||
WHERE dps.tenant_id = ? AND dps.id = ? | ||
GROUP BY deploy.level` | ||
err := service.db.Raw(sql, tenantId, projectId).Scan(&resourceList).Error | ||
return getTotalDetailsInfo(resourceList), err | ||
} | ||
|
||
func (service *ProjectService) GetResourceMetricsByTenantId(tenantId uint64) (dto.DevOpsProjectResourceTotals, error) { | ||
var resourceList []dto.DevOpsProjectResource | ||
sql := `SELECT deploy.level,SUM(deploy.replicas) replicas,SUM(container.limit_cpu * deploy.replicas) sum_cpu,SUM(container.limit_memory * deploy.replicas) sum_memory | ||
FROM sgr_tenant_deployments deploy | ||
INNER JOIN sgr_tenant_deployments_containers container on container.deploy_id = deploy.id | ||
WHERE deploy.tenant_id = ? | ||
GROUP BY deploy.level` | ||
err := service.db.Raw(sql, tenantId).Scan(&resourceList).Error | ||
return getTotalDetailsInfo(resourceList), err | ||
} | ||
|
||
func getTotalDetailsInfo(items []dto.DevOpsProjectResource) dto.DevOpsProjectResourceTotals { | ||
resourceTotal := &dto.DevOpsProjectResourceTotals{ | ||
TotalCpu: 0, | ||
TotalMemory: 0, | ||
DevMetrics: dto.DevOpsProjectResource{Level: "dev", Replicas: 0, SumCpu: 0, SumMemory: 0}, | ||
TestMetrics: dto.DevOpsProjectResource{Level: "test", Replicas: 0, SumCpu: 0, SumMemory: 0}, | ||
ReleaseMetrics: dto.DevOpsProjectResource{Level: "release", Replicas: 0, SumCpu: 0, SumMemory: 0}, | ||
ProdMetrics: dto.DevOpsProjectResource{Level: "prod", Replicas: 0, SumCpu: 0, SumMemory: 0}, | ||
} | ||
for _, item := range items { | ||
resourceTotal.TotalMemory += item.SumMemory | ||
resourceTotal.TotalCpu += item.SumCpu | ||
|
||
switch item.Level { | ||
case "dev": | ||
resourceTotal.DevMetrics = item | ||
break | ||
case "test": | ||
resourceTotal.TestMetrics = item | ||
break | ||
case "release": | ||
resourceTotal.ReleaseMetrics = item | ||
break | ||
case "prod": | ||
resourceTotal.ProdMetrics = item | ||
break | ||
} | ||
} | ||
|
||
return *resourceTotal | ||
} |
Oops, something went wrong.