Specify host port for host networking strategy#694
Specify host port for host networking strategy#694openshift-merge-robot merged 1 commit intoopenshift:masterfrom
Conversation
56e039c to
e96b234
Compare
e96b234 to
b23aa47
Compare
2783f49 to
92f526e
Compare
Miciah
left a comment
There was a problem hiding this comment.
routerDefaultHostNetworkStatsPort needs to be fixed. My other comments are all minor suggestions.
| // verify the default ports are used | ||
| checkContainerPort(t, deployment, "http", 80) | ||
| checkContainerPort(t, deployment, "https", 443) | ||
| checkContainerPort(t, deployment, "metrics", 1936) | ||
|
|
There was a problem hiding this comment.
Might as well check the corresponding environment variables too.
There was a problem hiding this comment.
The environment variables for the HTTP and HTTPS have defaults and currently those defaults are used. I've added a check for the stats port environment variable because that's always set regardless of the strategy. Should I update the code to always set those environment variables as well?
There was a problem hiding this comment.
Ah, I see what you're saying—the environment variables are only set if the endpoint publishing strategy is "HostNetwork". Never mind then.
92f526e to
9c9c52c
Compare
7a57f2d to
916a2d5
Compare
|
/lgtm |
|
/hold |
| var statsPort int32 = routerDefaultHostNetworkStatsPort | ||
| var httpPort int32 = routerDefaultHostNetworkHTTPPort | ||
| var httpsPort int32 = routerDefaultHostNetworkHTTPSPort |
There was a problem hiding this comment.
| var statsPort int32 = routerDefaultHostNetworkStatsPort | |
| var httpPort int32 = routerDefaultHostNetworkHTTPPort | |
| var httpsPort int32 = routerDefaultHostNetworkHTTPSPort | |
| var ( | |
| statsPort int32 = routerDefaultHostNetworkStatsPort | |
| httpPort int32 = routerDefaultHostNetworkHTTPPort | |
| httpsPort int32 = routerDefaultHostNetworkHTTPSPort | |
| ) |
| // verify the default ports are used | ||
| checkContainerPort(t, deployment, "http", 80) | ||
| checkContainerPort(t, deployment, "https", 443) | ||
| checkContainerPort(t, deployment, "metrics", 1936) | ||
|
|
There was a problem hiding this comment.
Ah, I see what you're saying—the environment variables are only set if the endpoint publishing strategy is "HostNetwork". Never mind then.
| // append the environment variables for the HTTP and HTTPS ports | ||
| env = append(env, | ||
| corev1.EnvVar{ | ||
| Name: RouterServiceHTTPSPort, | ||
| Value: strconv.Itoa(int(config.HTTPSPort)), | ||
| }, | ||
| corev1.EnvVar{ | ||
| Name: RouterServiceHTTPPort, | ||
| Value: strconv.Itoa(int(config.HTTPPort)), | ||
| }, | ||
| ) | ||
|
|
||
| // set the ports to the values from the host network configuration | ||
| httpPort = config.HTTPPort | ||
| httpsPort = config.HTTPSPort | ||
| statsPort = config.StatsPort |
There was a problem hiding this comment.
Slightly simpler:
| // append the environment variables for the HTTP and HTTPS ports | |
| env = append(env, | |
| corev1.EnvVar{ | |
| Name: RouterServiceHTTPSPort, | |
| Value: strconv.Itoa(int(config.HTTPSPort)), | |
| }, | |
| corev1.EnvVar{ | |
| Name: RouterServiceHTTPPort, | |
| Value: strconv.Itoa(int(config.HTTPPort)), | |
| }, | |
| ) | |
| // set the ports to the values from the host network configuration | |
| httpPort = config.HTTPPort | |
| httpsPort = config.HTTPSPort | |
| statsPort = config.StatsPort | |
| // Set the ports to the values from the host network configuration. | |
| httpPort = config.HTTPPort | |
| httpsPort = config.HTTPSPort | |
| statsPort = config.StatsPort | |
| // Append the environment variables for the HTTP and HTTPS ports. | |
| env = append(env, | |
| corev1.EnvVar{ | |
| Name: RouterServiceHTTPSPort, | |
| Value: strconv.Itoa(int(httpsPort)), | |
| }, | |
| corev1.EnvVar{ | |
| Name: RouterServiceHTTPPort, | |
| Value: strconv.Itoa(int(httpPort)), | |
| }, | |
| ) |
| deployment.Spec.Template.Spec.Containers[0].Ports = append( | ||
| deployment.Spec.Template.Spec.Containers[0].Ports, | ||
| corev1.ContainerPort{ | ||
| Name: HTTPPortName, | ||
| ContainerPort: httpPort, | ||
| }, | ||
| corev1.ContainerPort{ | ||
| Name: HTTPSPortName, | ||
| ContainerPort: httpsPort, | ||
| }, | ||
| corev1.ContainerPort{ | ||
| Name: StatsPortName, | ||
| ContainerPort: statsPort, | ||
| }, | ||
| ) |
There was a problem hiding this comment.
I missed this before, but you need to add some logic to handle updates:
diff --git a/pkg/operator/controller/ingress/deployment.go b/pkg/operator/controller/ingress/deployment.go
index 3aca7adc..5b581376 100644
--- a/pkg/operator/controller/ingress/deployment.go
+++ b/pkg/operator/controller/ingress/deployment.go
@@ -1305,6 +1305,7 @@ func hashableDeployment(deployment *appsv1.Deployment, onlyTemplate bool) *appsv
Image: container.Image,
ImagePullPolicy: container.ImagePullPolicy,
Name: container.Name,
+ Ports: container.Ports,
LivenessProbe: hashableProbe(container.LivenessProbe),
ReadinessProbe: hashableProbe(container.ReadinessProbe),
StartupProbe: hashableProbe(container.StartupProbe),
@@ -1520,6 +1521,7 @@ func deploymentConfigChanged(current, expected *appsv1.Deployment) (bool, *appsv
updated.Spec.Template.Spec.NodeSelector = expected.Spec.Template.Spec.NodeSelector
updated.Spec.Template.Spec.Containers[0].Env = expected.Spec.Template.Spec.Containers[0].Env
updated.Spec.Template.Spec.Containers[0].Image = expected.Spec.Template.Spec.Containers[0].Image
+ updated.Spec.Template.Spec.Containers[0].Ports = expected.Spec.Template.Spec.Containers[0].Ports
updated.Spec.Template.Spec.Containers[0].LivenessProbe = expected.Spec.Template.Spec.Containers[0].LivenessProbe
updated.Spec.Template.Spec.Containers[0].ReadinessProbe = expected.Spec.Template.Spec.Containers[0].ReadinessProbe
updated.Spec.Template.Spec.Containers[0].StartupProbe = expected.Spec.Template.Spec.Containers[0].StartupProbe
diff --git a/pkg/operator/controller/ingress/deployment_test.go b/pkg/operator/controller/ingress/deployment_test.go
index 7e5ba9c8..df176ce2 100644
--- a/pkg/operator/controller/ingress/deployment_test.go
+++ b/pkg/operator/controller/ingress/deployment_test.go
@@ -1163,6 +1163,15 @@ func TestDeploymentConfigChanged(t *testing.T) {
},
expect: false,
},
+ {
+ description: "if ports are changed",
+ mutate: func(deployment *appsv1.Deployment) {
+ deployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = int32(8080)
+ deployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = int32(8443)
+ deployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = int32(8936)
+ },
+ expect: true,
+ },
{
description: "if probe values are set to default values",
mutate: func(deployment *appsv1.Deployment) {
@@ -1335,6 +1344,20 @@ func TestDeploymentConfigChanged(t *testing.T) {
},
},
Image: "openshift/origin-cluster-ingress-operator:v4.0",
+ Ports: []corev1.ContainerPort{
+ {
+ Name: "http",
+ ContainerPort: int32(80),
+ },
+ {
+ Name: "https",
+ ContainerPort: 443,
+ },
+ {
+ Name: "metrics",
+ ContainerPort: 1936,
+ },
+ },
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{916a2d5 to
dff1967
Compare
|
/retest-required |
|
/unhold |
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
3 similar comments
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
|
/hold |
|
Doc PR: openshift/openshift-docs#44435 /label docs-approved FYI @Amrita42 |
|
Reviewed the PR after the rebase, LGTM |
|
/label px-approved |
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
When the load balancer strategy is hostnetworking allow the user to specify which ports on the host the pods should use. Also fixup the container ports.
10abb90 to
af653f9
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alebedev87, arjunrn, Miciah The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
|
/retest-required Please review the full test history for this PR and help us cut down flakes. |
|
@arjunrn: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
When the load balancer strategy is hostnetworking allow the user to
specify which ports on the host the pods should use. Also fixup the
container ports.