Skip to content

Commit

Permalink
Merge pull request #530 from openinfradev/domains
Browse files Browse the repository at this point in the history
trivial. add clusterDomains to sitevalues api
  • Loading branch information
ktkfree authored Jul 10, 2024
2 parents 67b7f7a + 6585574 commit 53a19bf
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 42 deletions.
48 changes: 39 additions & 9 deletions internal/delivery/http/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,31 @@ func (h *StackHandler) CreateStack(w http.ResponseWriter, r *http.Request) {
if err = serializer.Map(r.Context(), input, &dto.Conf); err != nil {
log.Info(r.Context(), err)
}
dto.Domains = make([]model.ClusterDomain, len(input.Domains))
for i, domain := range input.Domains {
if err = serializer.Map(r.Context(), domain, &dto.Domains[i]); err != nil {
log.Info(r.Context(), err)
}

dto.Domains = make([]model.ClusterDomain, 6)
dto.Domains[0] = model.ClusterDomain{
DomainType: "grafana",
Url: input.Domain.Grafana,
}
dto.Domains[1] = model.ClusterDomain{
DomainType: "loki",
Url: input.Domain.Loki,
}
dto.Domains[2] = model.ClusterDomain{
DomainType: "minio",
Url: input.Domain.Minio,
}
dto.Domains[3] = model.ClusterDomain{
DomainType: "thanos_sidecar",
Url: input.Domain.ThanosSidecar,
}
dto.Domains[4] = model.ClusterDomain{
DomainType: "jaeger",
Url: input.Domain.Jaeger,
}
dto.Domains[5] = model.ClusterDomain{
DomainType: "kiali",
Url: input.Domain.Kiali,
}

dto.OrganizationId = organizationId
Expand Down Expand Up @@ -214,10 +234,20 @@ func (h *StackHandler) GetStack(w http.ResponseWriter, r *http.Request) {
if err := serializer.Map(r.Context(), stack, &out.Stack); err != nil {
log.Info(r.Context(), err)
}
out.Stack.Domains = make([]domain.ClusterDomain, len(stack.Domains))
for i, domain := range stack.Domains {
if err = serializer.Map(r.Context(), domain, &out.Stack.Domains[i]); err != nil {
log.Info(r.Context(), err)
for _, domain := range stack.Domains {
switch domain.DomainType {
case "grafana":
out.Stack.Domain.Grafana = domain.Url
case "loki":
out.Stack.Domain.Loki = domain.Url
case "minio":
out.Stack.Domain.Minio = domain.Url
case "thanos_sidecar":
out.Stack.Domain.ThanosSidecar = domain.Url
case "jaeger":
out.Stack.Domain.Jaeger = domain.Url
case "kiali":
out.Stack.Domain.Kiali = domain.Url
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/usecase/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ func (u *ClusterUsecase) GetClusterSiteValues(ctx context.Context, clusterId dom
if err := serializer.Map(ctx, cluster, &out); err != nil {
log.Error(ctx, err)
}
out.Domains = make([]domain.ClusterDomain, len(cluster.Domains))
for i, domain := range cluster.Domains {
if err = serializer.Map(ctx, domain, &out.Domains[i]); err != nil {
log.Info(ctx, err)
}
}

if cluster.StackTemplate.CloudService == "AWS" && cluster.StackTemplate.KubeType == "AWS" {
out.TksUserNode = cluster.TksUserNode / domain.MAX_AZ_NUM
Expand Down
29 changes: 15 additions & 14 deletions pkg/domain/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,21 @@ type SimpleClusterResponse struct {
}

type ClusterSiteValuesResponse struct {
ClusterType string `json:"clusterType"`
SshKeyName string `json:"sshKeyName"`
ClusterRegion string `json:"clusterRegion"`
TksCpNode int `json:"tksCpNode"`
TksCpNodeMax int `json:"tksCpNodeMax,omitempty"`
TksCpNodeType string `json:"tksCpNodeType,omitempty"`
TksInfraNode int `json:"tksInfraNode"`
TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"`
TksInfraNodeType string `json:"tksInfraNodeType,omitempty"`
TksUserNode int `json:"tksUserNode"`
TksUserNodeMax int `json:"tksUserNodeMax,omitempty"`
TksUserNodeType string `json:"tksUserNodeType,omitempty"`
ByoClusterEndpointHost string `json:"byoClusterEndpointHost"`
ByoClusterEndpointPort int `json:"byoClusterEndpointPort"`
ClusterType string `json:"clusterType"`
SshKeyName string `json:"sshKeyName"`
ClusterRegion string `json:"clusterRegion"`
TksCpNode int `json:"tksCpNode"`
TksCpNodeMax int `json:"tksCpNodeMax,omitempty"`
TksCpNodeType string `json:"tksCpNodeType,omitempty"`
TksInfraNode int `json:"tksInfraNode"`
TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"`
TksInfraNodeType string `json:"tksInfraNodeType,omitempty"`
TksUserNode int `json:"tksUserNode"`
TksUserNodeMax int `json:"tksUserNodeMax,omitempty"`
TksUserNodeType string `json:"tksUserNodeType,omitempty"`
ByoClusterEndpointHost string `json:"byoClusterEndpointHost"`
ByoClusterEndpointPort int `json:"byoClusterEndpointPort"`
Domains []ClusterDomain `json:"domains,omitempty"`
}

type GetClustersResponse struct {
Expand Down
47 changes: 28 additions & 19 deletions pkg/domain/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ type StackStepStatus struct {
}

type CreateStackRequest struct {
Name string `json:"name" validate:"required,name,rfc1123"`
Description string `json:"description"`
ClusterId string `json:"clusterId"`
CloudService string `json:"cloudService" validate:"required,oneof=AWS BYOH"`
StackTemplateId string `json:"stackTemplateId" validate:"required"`
CloudAccountId string `json:"cloudAccountId"`
ClusterEndpoint string `json:"userClusterEndpoint,omitempty"`
PolicyIds []string `json:"policyIds,omitempty"`
TksCpNode int `json:"tksCpNode"`
TksCpNodeMax int `json:"tksCpNodeMax,omitempty"`
TksCpNodeType string `json:"tksCpNodeType,omitempty"`
TksInfraNode int `json:"tksInfraNode"`
TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"`
TksInfraNodeType string `json:"tksInfraNodeType,omitempty"`
TksUserNode int `json:"tksUserNode"`
TksUserNodeMax int `json:"tksUserNodeMax,omitempty"`
TksUserNodeType string `json:"tksUserNodeType,omitempty"`
Domains []ClusterDomain `json:"domains,omitempty"`
Name string `json:"name" validate:"required,name,rfc1123"`
Description string `json:"description"`
ClusterId string `json:"clusterId"`
CloudService string `json:"cloudService" validate:"required,oneof=AWS BYOH"`
StackTemplateId string `json:"stackTemplateId" validate:"required"`
CloudAccountId string `json:"cloudAccountId"`
ClusterEndpoint string `json:"userClusterEndpoint,omitempty"`
PolicyIds []string `json:"policyIds,omitempty"`
TksCpNode int `json:"tksCpNode"`
TksCpNodeMax int `json:"tksCpNodeMax,omitempty"`
TksCpNodeType string `json:"tksCpNodeType,omitempty"`
TksInfraNode int `json:"tksInfraNode"`
TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"`
TksInfraNodeType string `json:"tksInfraNodeType,omitempty"`
TksUserNode int `json:"tksUserNode"`
TksUserNodeMax int `json:"tksUserNodeMax,omitempty"`
TksUserNodeType string `json:"tksUserNodeType,omitempty"`
Domain StackDomain `json:"domain,omitempty"`
}

type CreateStackResponse struct {
Expand All @@ -119,6 +119,15 @@ type StackConfResponse struct {
TksUserNodeType string `json:"tksUserNodeType,omitempty"`
}

type StackDomain struct {
Grafana string `json:"grafana"`
Loki string `json:"loki"`
Minio string `json:"minio"`
ThanosSidecar string `json:"thanosSidecar"`
Jaeger string `json:"jaeger"`
Kiali string `json:"kiali"`
}

type StackResponse struct {
ID StackId `json:"id"`
Name string `json:"name"`
Expand All @@ -137,7 +146,7 @@ type StackResponse struct {
ClusterEndpoint string `json:"userClusterEndpoint,omitempty"`
Resource DashboardStackResponse `json:"resource,omitempty"`
AppServeAppCnt int `json:"appServeAppCnt"`
Domains []ClusterDomain `json:"domains"`
Domain StackDomain `json:"domain"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Expand Down

0 comments on commit 53a19bf

Please sign in to comment.