Skip to content

Specify host port for host networking strategy#694

Merged
openshift-merge-robot merged 1 commit intoopenshift:masterfrom
arjunrn:ingress-host-bind-ports
Apr 26, 2022
Merged

Specify host port for host networking strategy#694
openshift-merge-robot merged 1 commit intoopenshift:masterfrom
arjunrn:ingress-host-bind-ports

Conversation

@arjunrn
Copy link
Contributor

@arjunrn arjunrn commented Jan 14, 2022

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.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 14, 2022
@openshift-ci openshift-ci bot requested review from frobware and rfredette January 14, 2022 13:51
@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch 2 times, most recently from 56e039c to e96b234 Compare January 19, 2022 10:03
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 27, 2022
@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch from e96b234 to b23aa47 Compare January 27, 2022 13:10
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 27, 2022
@arjunrn arjunrn changed the title [WIP] Updated dependencies to upstream k/k v1.23.0 Specify host port for host networking strategy Jan 27, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 27, 2022
@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch 3 times, most recently from 2783f49 to 92f526e Compare March 28, 2022 18:28
Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

routerDefaultHostNetworkStatsPort needs to be fixed. My other comments are all minor suggestions.

Comment on lines 551 to 555
// verify the default ports are used
checkContainerPort(t, deployment, "http", 80)
checkContainerPort(t, deployment, "https", 443)
checkContainerPort(t, deployment, "metrics", 1936)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well check the corresponding environment variables too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you're saying—the environment variables are only set if the endpoint publishing strategy is "HostNetwork". Never mind then.

@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch from 92f526e to 9c9c52c Compare March 29, 2022 09:02
Copy link
Contributor

@alebedev87 alebedev87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch 2 times, most recently from 7a57f2d to 916a2d5 Compare April 1, 2022 09:36
@alebedev87
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 1, 2022
@alebedev87
Copy link
Contributor

alebedev87 commented Apr 1, 2022

/hold
@Miciah unhold if it's fine with you

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 1, 2022
Comment on lines 612 to 614
var statsPort int32 = routerDefaultHostNetworkStatsPort
var httpPort int32 = routerDefaultHostNetworkHTTPPort
var httpsPort int32 = routerDefaultHostNetworkHTTPSPort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var statsPort int32 = routerDefaultHostNetworkStatsPort
var httpPort int32 = routerDefaultHostNetworkHTTPPort
var httpsPort int32 = routerDefaultHostNetworkHTTPSPort
var (
statsPort int32 = routerDefaultHostNetworkStatsPort
httpPort int32 = routerDefaultHostNetworkHTTPPort
httpsPort int32 = routerDefaultHostNetworkHTTPSPort
)

Comment on lines 551 to 555
// verify the default ports are used
checkContainerPort(t, deployment, "http", 80)
checkContainerPort(t, deployment, "https", 443)
checkContainerPort(t, deployment, "metrics", 1936)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you're saying—the environment variables are only set if the endpoint publishing strategy is "HostNetwork". Never mind then.

Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to rebase for #720. Sorry about that.

Comment on lines 635 to 650
// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly simpler:

Suggested change
// 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)),
},
)

Comment on lines +1065 to +1107
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,
},
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{

@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch from 916a2d5 to dff1967 Compare April 4, 2022 08:56
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 4, 2022
@arjunrn
Copy link
Contributor Author

arjunrn commented Apr 4, 2022

/retest-required

@alebedev87
Copy link
Contributor

/unhold

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Apr 25, 2022
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@Miciah
Copy link
Contributor

Miciah commented Apr 25, 2022

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 25, 2022
@alebedev87
Copy link
Contributor

Doc PR: openshift/openshift-docs#44435

/label docs-approved

FYI @Amrita42

@openshift-ci openshift-ci bot added the docs-approved Signifies that Docs has signed off on this PR label Apr 25, 2022
@alebedev87
Copy link
Contributor

Reviewed the PR after the rebase, LGTM
/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 25, 2022
@CFields651
Copy link

/label px-approved

@openshift-ci openshift-ci bot added the px-approved Signifies that Product Support has signed off on this PR label Apr 25, 2022
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2022
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.
@arjunrn arjunrn force-pushed the ingress-host-bind-ports branch from 10abb90 to af653f9 Compare April 26, 2022 08:02
@openshift-ci openshift-ci bot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 26, 2022
@alebedev87
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 26, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 26, 2022

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 26, 2022

@arjunrn: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. docs-approved Signifies that Docs has signed off on this PR lgtm Indicates that a PR is ready to be merged. px-approved Signifies that Product Support has signed off on this PR qe-approved Signifies that QE has signed off on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants