From 2acf6bbb5773dafe93bf3bc289847d30d6b991fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Gustav=20Str=C3=A5b=C3=B8?= <65334626+nilsgstrabo@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:50:45 +0200 Subject: [PATCH] add network to component model (#678) * add network to component model * add Network info to Component add IsPublic to Port --- api/deployments/models/component_builder.go | 25 ++++++++- .../models/component_deployment.go | 40 ++++++++++++++- swaggerui/html/swagger.json | 51 ++++++++++++++++++- 3 files changed, 112 insertions(+), 4 deletions(-) diff --git a/api/deployments/models/component_builder.go b/api/deployments/models/component_builder.go index deb1a02a..37d5d615 100644 --- a/api/deployments/models/component_builder.go +++ b/api/deployments/models/component_builder.go @@ -6,6 +6,7 @@ import ( "github.com/equinor/radix-api/api/secrets/suffix" "github.com/equinor/radix-api/api/utils/secret" "github.com/equinor/radix-common/utils/pointers" + "github.com/equinor/radix-common/utils/slice" "github.com/equinor/radix-operator/pkg/apis/defaults" "github.com/equinor/radix-operator/pkg/apis/deployment" "github.com/equinor/radix-operator/pkg/apis/ingress" @@ -55,6 +56,7 @@ type componentBuilder struct { resources *radixv1.ResourceRequirements runtime *radixv1.Runtime replicasOverride *int + network *Network } func (b *componentBuilder) WithStatus(status ComponentStatus) ComponentBuilder { @@ -106,8 +108,9 @@ func (b *componentBuilder) WithComponent(component radixv1.RadixCommonDeployComp if component.GetPorts() != nil { for _, port := range component.GetPorts() { ports = append(ports, Port{ - Name: port.Name, - Port: port.Port, + Name: port.Name, + Port: port.Port, + IsPublic: port.Name == component.GetPublicPort(), }) } } @@ -176,6 +179,23 @@ func (b *componentBuilder) WithComponent(component radixv1.RadixCommonDeployComp } b.environmentVariables = component.GetEnvironmentVariables() + + if network := component.GetNetwork(); network != nil { + b.network = &Network{} + + if ingress := network.Ingress; ingress != nil { + b.network.Ingress = &Ingress{} + + if publicIngress := ingress.Public; publicIngress != nil { + b.network.Ingress.Public = &IngressPublic{} + + if allow := publicIngress.Allow; allow != nil { + b.network.Ingress.Public.Allow = slice.Map(*allow, func(v radixv1.IPOrCIDR) string { return string(v) }) + } + } + } + } + return b } @@ -265,6 +285,7 @@ func (b *componentBuilder) BuildComponent() (*Component, error) { CommitID: variables[defaults.RadixCommitHashEnvironmentVariable], GitTags: variables[defaults.RadixGitTagsEnvironmentVariable], Runtime: b.buildRuntimeModel(), + Network: b.network, } if b.resources != nil && (len(b.resources.Limits) > 0 || len(b.resources.Requests) > 0) { component.Resources = pointers.Ptr(ConvertRadixResourceRequirements(*b.resources)) diff --git a/api/deployments/models/component_deployment.go b/api/deployments/models/component_deployment.go index ae95f58b..b6ddc0d0 100644 --- a/api/deployments/models/component_deployment.go +++ b/api/deployments/models/component_deployment.go @@ -138,6 +138,38 @@ type Component struct { // Runtime requirements for the component or job Runtime *Runtime `json:"runtime,omitempty"` + + // Network configuration for the component + // + // required: false + Network *Network `json:"network,omitempty"` +} + +// Network describes network configuration for a component +// swagger:model Network +type Network struct { + // Ingress configuration + // + // required: false + Ingress *Ingress `json:"ingress,omitempty"` +} + +// Ingress describes ingress configuration for a component +// swagger:model Ingress +type Ingress struct { + // Public ingress configuration + // + // required: false + Public *IngressPublic `json:"public,omitempty"` +} + +// IngressPublic describes public ingress configuration for a component +// swagger:model IngressPublic +type IngressPublic struct { + // List of allowed IP addresses or CIDRs. All traffic is allowed if list is empty. + // + // required: true + Allow []string `json:"allow"` } // ExternalDNS describes an external DNS entry for a component @@ -236,9 +268,15 @@ type Port struct { // Component port number. From radixconfig.yaml // - // required: false + // required: true // example: 8080 Port int32 `json:"port"` + + // IsPublic indicates that the port is accessible from the Internet by proxying traffic from 443 + // + // required: true + // example: true + IsPublic bool `json:"isPublic"` } // ComponentSummary describe a component part of a deployment diff --git a/swaggerui/html/swagger.json b/swaggerui/html/swagger.json index 02e6dbc7..1e0d9119 100644 --- a/swaggerui/html/swagger.json +++ b/swaggerui/html/swagger.json @@ -5782,6 +5782,9 @@ "x-go-name": "Name", "example": "server" }, + "network": { + "$ref": "#/definitions/Network" + }, "notifications": { "$ref": "#/definitions/Notifications" }, @@ -6664,6 +6667,34 @@ }, "x-go-package": "github.com/equinor/radix-api/api/privateimagehubs/models" }, + "Ingress": { + "description": "Ingress describes ingress configuration for a component", + "type": "object", + "properties": { + "public": { + "$ref": "#/definitions/IngressPublic" + } + }, + "x-go-package": "github.com/equinor/radix-api/api/deployments/models" + }, + "IngressPublic": { + "description": "IngressPublic describes public ingress configuration for a component", + "type": "object", + "required": [ + "allow" + ], + "properties": { + "allow": { + "description": "List of allowed IP addresses or CIDRs. All traffic is allowed if list is empty.", + "type": "array", + "items": { + "type": "string" + }, + "x-go-name": "Allow" + } + }, + "x-go-package": "github.com/equinor/radix-api/api/deployments/models" + }, "Job": { "description": "Job holds general information about job", "type": "object", @@ -6922,6 +6953,16 @@ }, "x-go-package": "github.com/equinor/radix-api/api/jobs/models" }, + "Network": { + "description": "Network describes network configuration for a component", + "type": "object", + "properties": { + "ingress": { + "$ref": "#/definitions/Ingress" + } + }, + "x-go-package": "github.com/equinor/radix-api/api/deployments/models" + }, "Node": { "description": "Node Defines node attributes, where pod should be scheduled", "type": "object", @@ -7368,9 +7409,17 @@ "description": "Port describe a port of a component", "type": "object", "required": [ - "name" + "name", + "port", + "isPublic" ], "properties": { + "isPublic": { + "description": "IsPublic indicates that the port is accessible from the Internet by proxying traffic from 443", + "type": "boolean", + "x-go-name": "IsPublic", + "example": true + }, "name": { "description": "Component port name. From radixconfig.yaml", "type": "string",