From d6cb3a557fd482532cea7f3950cb630d095a2dd2 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Tue, 27 Feb 2024 10:29:19 +0100 Subject: [PATCH 1/2] Added ext dns aliases to application --- api/applications/models/application.go | 5 +++ api/applications/models/external_dns_alias.go | 23 +++++++++++ api/models/application.go | 13 ++++--- api/models/external_dns_alias.go | 18 +++++++++ swaggerui/html/swagger.json | 38 +++++++++++++++++++ 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 api/applications/models/external_dns_alias.go create mode 100644 api/models/external_dns_alias.go diff --git a/api/applications/models/application.go b/api/applications/models/application.go index 7328d786..8d94f328 100644 --- a/api/applications/models/application.go +++ b/api/applications/models/application.go @@ -34,6 +34,11 @@ type Application struct { // required: false DNSAliases []DNSAlias `json:"dnsAliases,omitempty"` + // List of external DNS names and which component and environment incoming requests shall be routed to. + // + // required: false + DNSExternalAliases []DNSExternalAlias `json:"dnsExternalAliases,omitempty"` + // App alias showing nicer endpoint for application // // required: false diff --git a/api/applications/models/external_dns_alias.go b/api/applications/models/external_dns_alias.go new file mode 100644 index 00000000..7fe2118c --- /dev/null +++ b/api/applications/models/external_dns_alias.go @@ -0,0 +1,23 @@ +package models + +// DNSExternalAlias holds public external DNS alias information +// swagger:model DNSExternalAlias +type DNSExternalAlias struct { + // URL the public endpoint + // + // required: true + // example: https://my-app.equinor.com + URL string `json:"url"` + + // ComponentName the component exposing the endpoint + // + // required: true + // example: frontend + ComponentName string `json:"componentName"` + + // EnvironmentName the environment hosting the endpoint + // + // required: true + // example: prod + EnvironmentName string `json:"environmentName"` +} diff --git a/api/models/application.go b/api/models/application.go index f3aed0fb..e33da181 100644 --- a/api/models/application.go +++ b/api/models/application.go @@ -9,12 +9,13 @@ import ( // BuildApplication builds an Application model. func BuildApplication(rr *radixv1.RadixRegistration, ra *radixv1.RadixApplication, reList []radixv1.RadixEnvironment, rdList []radixv1.RadixDeployment, rjList []radixv1.RadixJob, ingressList []networkingv1.Ingress, userIsAdmin bool, dnsAliases []applicationModels.DNSAlias) *applicationModels.Application { application := applicationModels.Application{ - Name: rr.Name, - Registration: *BuildApplicationRegistration(rr), - Jobs: BuildJobSummaryList(rjList), - AppAlias: BuildApplicationAlias(ingressList, reList), - UserIsAdmin: userIsAdmin, - DNSAliases: dnsAliases, + Name: rr.Name, + Registration: *BuildApplicationRegistration(rr), + Jobs: BuildJobSummaryList(rjList), + AppAlias: BuildApplicationAlias(ingressList, reList), + UserIsAdmin: userIsAdmin, + DNSAliases: dnsAliases, + DNSExternalAliases: BuildDNSExternalAliases(ra), } if ra != nil { application.Environments = BuildEnvironmentSummaryList(rr, ra, reList, rdList, rjList) diff --git a/api/models/external_dns_alias.go b/api/models/external_dns_alias.go new file mode 100644 index 00000000..b1f4faf9 --- /dev/null +++ b/api/models/external_dns_alias.go @@ -0,0 +1,18 @@ +package models + +import ( + "github.com/equinor/radix-api/api/applications/models" + "github.com/equinor/radix-common/utils/slice" + radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1" +) + +// BuildDNSExternalAliases builds DNSExternalAliases model list +func BuildDNSExternalAliases(ra *radixv1.RadixApplication) []models.DNSExternalAlias { + return slice.Reduce(ra.Spec.DNSExternalAlias, make([]models.DNSExternalAlias, 0), func(acc []models.DNSExternalAlias, externalAlias radixv1.ExternalAlias) []models.DNSExternalAlias { + return append(acc, models.DNSExternalAlias{ + URL: externalAlias.Alias, + ComponentName: externalAlias.Component, + EnvironmentName: externalAlias.Environment, + }) + }) +} diff --git a/swaggerui/html/swagger.json b/swaggerui/html/swagger.json index 25b0dbd0..5809d4dc 100644 --- a/swaggerui/html/swagger.json +++ b/swaggerui/html/swagger.json @@ -5022,6 +5022,14 @@ }, "x-go-name": "DNSAliases" }, + "dnsExternalAliases": { + "description": "List of external DNS names and which component and environment incoming requests shall be routed to.", + "type": "array", + "items": { + "$ref": "#/definitions/DNSExternalAlias" + }, + "x-go-name": "DNSExternalAliases" + }, "environments": { "description": "Environments List of environments for this application", "type": "array", @@ -5726,6 +5734,36 @@ }, "x-go-package": "github.com/equinor/radix-api/api/applications/models" }, + "DNSExternalAlias": { + "description": "DNSExternalAlias holds public external DNS alias information", + "type": "object", + "required": [ + "url", + "componentName", + "environmentName" + ], + "properties": { + "componentName": { + "description": "ComponentName the component exposing the endpoint", + "type": "string", + "x-go-name": "ComponentName", + "example": "frontend" + }, + "environmentName": { + "description": "EnvironmentName the environment hosting the endpoint", + "type": "string", + "x-go-name": "EnvironmentName", + "example": "prod" + }, + "url": { + "description": "URL the public endpoint", + "type": "string", + "x-go-name": "URL", + "example": "https://my-app.equinor.com" + } + }, + "x-go-package": "github.com/equinor/radix-api/api/applications/models" + }, "DeployKeyAndSecret": { "description": "DeployKeyAndSecret Holds generated public deploy key and shared secret", "type": "object", From 02205a8455189bb62b17bc33041533773d292b5c Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Tue, 27 Feb 2024 10:39:32 +0100 Subject: [PATCH 2/2] Fixed failed list --- api/models/external_dns_alias.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/models/external_dns_alias.go b/api/models/external_dns_alias.go index b1f4faf9..4cafb0ad 100644 --- a/api/models/external_dns_alias.go +++ b/api/models/external_dns_alias.go @@ -8,6 +8,9 @@ import ( // BuildDNSExternalAliases builds DNSExternalAliases model list func BuildDNSExternalAliases(ra *radixv1.RadixApplication) []models.DNSExternalAlias { + if ra == nil { + return nil + } return slice.Reduce(ra.Spec.DNSExternalAlias, make([]models.DNSExternalAlias, 0), func(acc []models.DNSExternalAlias, externalAlias radixv1.ExternalAlias) []models.DNSExternalAlias { return append(acc, models.DNSExternalAlias{ URL: externalAlias.Alias,