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

Automated backport of #3275: Add init container to the gateway to wait for node readiness #3276

Open
wants to merge 2 commits into
base: release-0.18
Choose a base branch
from
Open
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
44 changes: 31 additions & 13 deletions controllers/submariner/gateway_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ func newGatewayPodTemplate(cr *v1alpha1.Submariner, name string, podSelectorLabe
})
}

securityContext := &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{"net_admin"},
Drop: []corev1.Capability{"all"},
},
// The gateway needs to be privileged so it can write to /proc/sys
AllowPrivilegeEscalation: ptr.To(true),
Privileged: ptr.To(true),
RunAsNonRoot: ptr.To(false),
// We need to be able to update /var/lib/alternatives (for iptables)
ReadOnlyRootFilesystem: ptr.To(false),
}

podTemplate := corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: podSelectorLabels,
Expand All @@ -149,24 +162,29 @@ func newGatewayPodTemplate(cr *v1alpha1.Submariner, name string, podSelectorLabe
},
},
NodeSelector: map[string]string{"submariner.io/gateway": "true"},
// Wait for the node to be ready before starting the gateway.
InitContainers: []corev1.Container{
{
Name: name + "-init",
Image: getImagePath(cr, opnames.GatewayImage, names.GatewayComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.GatewayComponent]),
SecurityContext: securityContext,
Env: httpproxy.AddEnvVars([]corev1.EnvVar{
{Name: "SUBMARINER_WAITFORNODE", Value: "true"},
{Name: "NODE_NAME", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
}},
}),
},
},
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, opnames.GatewayImage, names.GatewayComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.GatewayComponent]),
Command: []string{"submariner.sh"},
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{"net_admin"},
Drop: []corev1.Capability{"all"},
},
// The gateway needs to be privileged so it can write to /proc/sys
AllowPrivilegeEscalation: ptr.To(true),
Privileged: ptr.To(true),
RunAsNonRoot: ptr.To(false),
// We need to be able to update /var/lib/alternatives (for iptables)
ReadOnlyRootFilesystem: ptr.To(false),
},
SecurityContext: securityContext,
Ports: []corev1.ContainerPort{
{
Name: encapsPortName,
Expand Down
1 change: 0 additions & 1 deletion controllers/submariner/route_agent_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, name string) *appsv1.Daemon
Name: name + "-init",
Image: getImagePath(cr, opnames.RouteAgentImage, names.RouteAgentComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.RouteAgentComponent]),
Command: []string{"submariner-route-agent.sh"},
Env: httpproxy.AddEnvVars([]corev1.EnvVar{
{Name: "SUBMARINER_WAITFORNODE", Value: "true"},
{Name: "NODE_NAME", ValueFrom: &corev1.EnvVarSource{
Expand Down
2 changes: 0 additions & 2 deletions scripts/test/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ function verify_subm_gateway_pod() {
validate_pod_container_equals 'securityContext.privileged' 'true'
validate_pod_container_equals 'securityContext.readOnlyRootFilesystem' 'false'
validate_pod_container_equals 'securityContext.runAsNonRoot' 'false'
validate_pod_container_has 'command' 'submariner.sh'

jq -r '.spec.containers[].env' "$json_file"
validate_pod_container_env 'SUBMARINER_NAMESPACE' "$subm_ns"
Expand Down Expand Up @@ -322,7 +321,6 @@ function verify_subm_routeagent_pod() {
validate_pod_container_equals 'securityContext.privileged' 'true'
validate_pod_container_equals 'securityContext.readOnlyRootFilesystem' 'false'
validate_pod_container_equals 'securityContext.runAsNonRoot' 'false'
validate_pod_container_has 'command' 'submariner-route-agent.sh'

jq -r '.spec.containers[].env' "$json_file"
validate_pod_container_env 'SUBMARINER_NAMESPACE' "$subm_ns"
Expand Down
Loading