Skip to content
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
4 changes: 2 additions & 2 deletions api/v1/egressgateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
// EGWDeploymentContainer is a Egress Gateway Deployment container.
type EGWDeploymentContainer struct {
// Name is an enum which identifies the EGW Deployment container by name.
// Supported values are: calico-egw
// +kubebuilder:validation:Enum=calico-egw
// Supported values are: egress-gateway
// +kubebuilder:validation:Enum=egress-gateway
Name string `json:"name"`

// Resources allows customization of limits and requests for compute resources such as cpu and memory.
Expand Down
4 changes: 2 additions & 2 deletions pkg/crds/operator/operator.tigera.io_egressgateways.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,9 @@ spec:
name:
description: |-
Name is an enum which identifies the EGW Deployment container by name.
Supported values are: calico-egw
Supported values are: egress-gateway
enum:
- calico-egw
- egress-gateway
type: string
resources:
description: |-
Expand Down
25 changes: 16 additions & 9 deletions pkg/render/egressgateway/egressgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ func (c *component) egwDeployment() *appsv1.Deployment {
rcomp.ApplyDeploymentOverrides(&d, overrides)
}

// Add AWS specific resource requests/limits after applying overrides to avoid being overwritten
// if the user has specified their own.
c.addAWSResources(&d)
return &d
}

Expand Down Expand Up @@ -215,7 +218,6 @@ func (c *component) egwContainer() *corev1.Container {
Image: c.config.egwImage,
ImagePullPolicy: render.ImagePullPolicy(),
Env: c.egwEnvVars(),
Resources: c.getResources(),
VolumeMounts: c.egwVolumeMounts(),
Ports: c.egwPorts(),
Command: []string{"/start-gateway.sh"},
Expand Down Expand Up @@ -409,16 +411,21 @@ func (c *component) getHTTPProbe() (string, string, string) {
return probeURLs, interval, timeout
}

func (c *component) getResources() corev1.ResourceRequirements {
recommendedQuantity := resource.NewQuantity(1, resource.DecimalSI)
func (c *component) addAWSResources(d *appsv1.Deployment) {
egw := c.config.EgressGW
if egw.Spec.AWS != nil && *egw.Spec.AWS.NativeIP == operatorv1.NativeIPEnabled {
return corev1.ResourceRequirements{
Limits: corev1.ResourceList{"projectcalico.org/aws-secondary-ipv4": *recommendedQuantity},
Requests: corev1.ResourceList{"projectcalico.org/aws-secondary-ipv4": *recommendedQuantity},
}
if egw.Spec.AWS == nil || *egw.Spec.AWS.NativeIP == operatorv1.NativeIPDisabled {
return
}
recommendedQuantity := resource.NewQuantity(1, resource.DecimalSI)
resourceRequirements := &d.Spec.Template.Spec.Containers[0].Resources
if resourceRequirements.Limits == nil {
resourceRequirements.Limits = corev1.ResourceList{}
}
if resourceRequirements.Requests == nil {
resourceRequirements.Requests = corev1.ResourceList{}
}
return corev1.ResourceRequirements{}
resourceRequirements.Limits["projectcalico.org/aws-secondary-ipv4"] = *recommendedQuantity
resourceRequirements.Requests["projectcalico.org/aws-secondary-ipv4"] = *recommendedQuantity
}

func (c *component) getIPPools() string {
Expand Down
12 changes: 10 additions & 2 deletions pkg/render/egressgateway/egressgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,20 @@ var _ = Describe("Egress Gateway rendering tests", func() {
It("should have proper annotations and resources if aws is set", func() {
recommendedQuantity := resource.NewQuantity(1, resource.DecimalSI)
expectedResource := corev1.ResourceRequirements{
Limits: corev1.ResourceList{"projectcalico.org/aws-secondary-ipv4": *recommendedQuantity},
Requests: corev1.ResourceList{"projectcalico.org/aws-secondary-ipv4": *recommendedQuantity},
Limits: corev1.ResourceList{"projectcalico.org/aws-secondary-ipv4": *recommendedQuantity, "cpu": resource.MustParse("100m")},
Requests: corev1.ResourceList{"projectcalico.org/aws-secondary-ipv4": *recommendedQuantity, "cpu": resource.MustParse("100m")},
}

nativeIP := operatorv1.NativeIPEnabled
egw.Spec.AWS = &operatorv1.AWSEgressGateway{NativeIP: &nativeIP, ElasticIPs: []string{"1.2.3.4", "5.6.7.8"}}
deploymentContainer := operatorv1.EGWDeploymentContainer{
Name: "egress-gateway",
Resources: &corev1.ResourceRequirements{
Limits: corev1.ResourceList{"cpu": resource.MustParse("100m")},
Requests: corev1.ResourceList{"cpu": resource.MustParse("100m")},
},
}
egw.Spec.Template.Spec.Containers = append(egw.Spec.Template.Spec.Containers, deploymentContainer)
component := egressgateway.EgressGateway(&egressgateway.Config{
PullSecrets: nil,
Installation: installation,
Expand Down