Skip to content

Commit

Permalink
[NET-6787] HostNetwork support for meshgw deployments (#3379)
Browse files Browse the repository at this point in the history
Add configuration for host network for mesh gateway deployments
  • Loading branch information
jm96441n authored Dec 14, 2023
1 parent 6c71611 commit c8e5d9e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions charts/consul/templates/crd-gatewayclassconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ spec:
type: object
type: object
type: object
hostNetwork:
description: HostNetwork specifies whether the gateway pods should
run on the host network
type: boolean
initContainer:
description: InitContainer contains config specific to the created
Deployment's init container
Expand Down
3 changes: 3 additions & 0 deletions charts/consul/templates/gateway-resources-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ data:
{{- with .Values.meshGateway.nodeSelector }}
nodeSelector: {{ fromYaml . | toJson }}
{{- end }}
{{- with .Values.meshGateway.hostNetwork }}
hostNetwork: {{ . }}
{{- end }}
priorityClassName: {{ toJson .Values.meshGateway.priorityClassName }}
replicas:
default: {{ .Values.meshGateway.replicas }}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/api/mesh/v2beta1/gateway_class_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type GatewayClassDeploymentConfig struct {
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
// Tolerations specifies the tolerations to use on the created Deployment
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// HostNetwork specifies whether the gateway pods should run on the host network
HostNetwork bool `json:"hostNetwork,omitempty"`
}

type GatewayClassReplicasConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ spec:
type: object
type: object
type: object
hostNetwork:
description: HostNetwork specifies whether the gateway pods should
run on the host network
type: boolean
initContainer:
description: InitContainer contains config specific to the created
Deployment's init container
Expand Down
13 changes: 4 additions & 9 deletions control-plane/gateways/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,12 @@ func (b *meshGatewayBuilder) deploymentSpec() (*appsv1.DeploymentSpec, error) {

var (
containerConfig *meshv2beta1.GatewayClassContainerConfig
nodeSelector map[string]string
tolerations []corev1.Toleration
deploymentConfig meshv2beta1.GatewayClassDeploymentConfig
replicas *meshv2beta1.GatewayClassReplicasConfig
)

if b.gcc != nil {
containerConfig = b.gcc.Spec.Deployment.Container
deploymentConfig = b.gcc.Spec.Deployment
nodeSelector = b.gcc.Spec.Deployment.NodeSelector
tolerations = b.gcc.Spec.Deployment.Tolerations
replicas = b.gcc.Spec.Deployment.Replicas
}

container, err := consulDataplaneContainer(b.config, containerConfig, b.gateway.Name, b.gateway.Namespace)
Expand All @@ -59,7 +53,7 @@ func (b *meshGatewayBuilder) deploymentSpec() (*appsv1.DeploymentSpec, error) {

return &appsv1.DeploymentSpec{
// TODO NET-6721
Replicas: deploymentReplicaCount(replicas, nil),
Replicas: deploymentReplicaCount(deploymentConfig.Replicas, nil),
Selector: &metav1.LabelSelector{
MatchLabels: b.Labels(),
},
Expand Down Expand Up @@ -101,9 +95,10 @@ func (b *meshGatewayBuilder) deploymentSpec() (*appsv1.DeploymentSpec, error) {
},
},
},
NodeSelector: nodeSelector,
NodeSelector: deploymentConfig.NodeSelector,
PriorityClassName: deploymentConfig.PriorityClassName,
Tolerations: tolerations,
HostNetwork: deploymentConfig.HostNetwork,
Tolerations: deploymentConfig.Tolerations,
ServiceAccountName: b.serviceAccountName(),
},
},
Expand Down
2 changes: 2 additions & 0 deletions control-plane/subcommand/gateway-resources/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ var validGWConfigurationKitchenSink = `gatewayClassConfigs:
name: consul-mesh-gateway
spec:
deployment:
hostNetwork: true
replicas:
min: 3
default: 3
Expand Down Expand Up @@ -449,6 +450,7 @@ func TestRun_loadGatewayConfigs(t *testing.T) {
config: validGWConfigurationKitchenSink,
filename: "kitchenSinkConfig.yaml",
expectedDeployment: v2beta1.GatewayClassDeploymentConfig{
HostNetwork: true,
NodeSelector: map[string]string{
"beta.kubernetes.io/arch": "amd64",
"beta.kubernetes.io/os": "linux",
Expand Down

0 comments on commit c8e5d9e

Please sign in to comment.