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

add network to component model #678

Merged
merged 2 commits into from
Sep 26, 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
25 changes: 23 additions & 2 deletions api/deployments/models/component_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,6 +56,7 @@ type componentBuilder struct {
resources *radixv1.ResourceRequirements
runtime *radixv1.Runtime
replicasOverride *int
network *Network
}

func (b *componentBuilder) WithStatus(status ComponentStatus) ComponentBuilder {
Expand Down Expand Up @@ -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(),
})
}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
Expand Down
40 changes: 39 additions & 1 deletion api/deployments/models/component_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/cert-manager/cert-manager v1.15.0
github.com/equinor/radix-common v1.9.5
github.com/equinor/radix-job-scheduler v1.11.0
github.com/equinor/radix-operator v1.59.1
github.com/equinor/radix-operator v1.61.0
github.com/evanphx/json-patch/v5 v5.9.0
github.com/felixge/httpsnoop v1.0.4
github.com/golang-jwt/jwt/v5 v5.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ github.com/equinor/radix-common v1.9.5 h1:p1xldkYUoavwIMguoxxOyVkOXLPA6K8qMsgzez
github.com/equinor/radix-common v1.9.5/go.mod h1:+g0Wj0D40zz29DjNkYKVmCVeYy4OsFWKI7Qi9rA6kpY=
github.com/equinor/radix-job-scheduler v1.11.0 h1:8wCmXOVl/1cto8q2WJQEE06Cw68/QmfoifYVR49vzkY=
github.com/equinor/radix-job-scheduler v1.11.0/go.mod h1:yPXn3kDcMY0Z3kBkosjuefsdY1x2g0NlBeybMmHz5hc=
github.com/equinor/radix-operator v1.59.1 h1:wzb2tF4MWtGDWmyYuIv3oh17G5Bx8ztW9O+WgnI3QFc=
github.com/equinor/radix-operator v1.59.1/go.mod h1:uRW9SgVZ94hkpq87npVv2YVviRuXNJ1zgCleya1uvr8=
github.com/equinor/radix-operator v1.61.0 h1:kHWHn5p9S+wKqOTSKtju2URW5FKgAFng1p6RLRnaTmE=
github.com/equinor/radix-operator v1.61.0/go.mod h1:uRW9SgVZ94hkpq87npVv2YVviRuXNJ1zgCleya1uvr8=
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=
github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
Expand Down
51 changes: 50 additions & 1 deletion swaggerui/html/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5747,6 +5747,9 @@
"x-go-name": "Name",
"example": "server"
},
"network": {
"$ref": "#/definitions/Network"
},
"notifications": {
"$ref": "#/definitions/Notifications"
},
Expand Down Expand Up @@ -6629,6 +6632,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",
Expand Down Expand Up @@ -6887,6 +6918,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",
Expand Down Expand Up @@ -7333,9 +7374,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",
Expand Down
Loading