Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivial. add clusterDomains to sitevalues api #530

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading