Skip to content

Conversation

@miheer
Copy link
Contributor

@miheer miheer commented Dec 25, 2022

Set/Replace/Append HTTP Request/Response Headers via Ingress Controller
API
pkg/operator/controller/ingress/deployment.go Fetches the headers from
the ingress controller CR and then sets the router deployment with
environment vars with the header value and action.
pkg/operator/controller/ingress/deployment_test.go Units tests for
setting enviroment var in thr router deployment.

@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 Dec 25, 2022
@openshift-ci openshift-ci bot requested review from alebedev87 and gcs278 December 25, 2022 07:50
@miheer miheer force-pushed the headers branch 2 times, most recently from bbffb85 to 40e1904 Compare December 26, 2022 05:35
@miheer
Copy link
Contributor Author

miheer commented Dec 26, 2022

/test verify

1 similar comment
@miheer
Copy link
Contributor Author

miheer commented Dec 26, 2022

/test verify

@miheer miheer force-pushed the headers branch 3 times, most recently from 928f19a to 704ce4e Compare December 27, 2022 13:13
@miheer miheer force-pushed the headers branch 14 times, most recently from e90540a to a3a6318 Compare January 13, 2023 03:42
@miheer miheer force-pushed the headers branch 2 times, most recently from f4cb835 to 477e41d Compare January 13, 2023 09:18
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 13, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2023
t.Errorf("failed to get logs from pod %s: %v", clientPod.Name, err)
}

t.Fatalf("failed to observe the expected output: %v\nclient pod spec: %#v\nclient pod logs:\n%s", err, pod, logs)
Copy link
Contributor

@candita candita Aug 10, 2023

Choose a reason for hiding this comment

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

err has been redefined, no longer relevant and could be nil. Just print out the logs.

Suggested change
t.Fatalf("failed to observe the expected output: %v\nclient pod spec: %#v\nclient pod logs:\n%s", err, pod, logs)
t.Errorf("client pod spec: %#v\nclient pod logs:\n%s", pod, logs)

Copy link
Contributor

Choose a reason for hiding this comment

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

Better yet, rename the inner err to err2 so that it doesn't clobber err.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I see that Miheer added a t.Errorf statement earlier on that prints err before it gets clobbered, so no need to print it here anyway.

@candita
Copy link
Contributor

candita commented Aug 10, 2023

/retest-required

@miheer miheer force-pushed the headers branch 2 times, most recently from 29c86b4 to 4dc8310 Compare August 11, 2023 00:03
Comment on lines +173 to +180
echoRoute := buildRoute(echoPod.Name, echoPod.Namespace, echoService.Name)
if err := kclient.Create(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to create route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
defer func() {
if err := kclient.Delete(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to delete route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should make the test a little more reliable:

Suggested change
echoRoute := buildRoute(echoPod.Name, echoPod.Namespace, echoService.Name)
if err := kclient.Create(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to create route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
defer func() {
if err := kclient.Delete(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to delete route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
}()
echoRoute := buildRoute(echoPod.Name, echoPod.Namespace, echoService.Name)
if err := kclient.Create(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to create route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
defer func() {
if err := kclient.Delete(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to delete route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
}()
cond := routev1.RouteIngressCondition{
Type: routev1.RouteAdmitted,
Status: corev1.ConditionTrue,
}
echoRouteName := types.NamespacedName{
Namespace: echoRoute.Namespace,
Name: echoRoute.Name,
}
waitForRouteIngressConditions(t, kclient, echoRouteName, ic.Name, cond)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 236 to 251
echoRoute := buildRouteWithHTTPResponseHeaders(echoPod.Name, echoPod.Namespace, echoService.Name, headerNameXFrame, "DENY")
if err := kclient.Create(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to create route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
defer func() {
if err := kclient.Delete(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to delete route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
}()
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
echoRoute := buildRouteWithHTTPResponseHeaders(echoPod.Name, echoPod.Namespace, echoService.Name, headerNameXFrame, "DENY")
if err := kclient.Create(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to create route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
defer func() {
if err := kclient.Delete(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to delete route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
}()
echoRoute := buildRouteWithHTTPResponseHeaders(echoPod.Name, echoPod.Namespace, echoService.Name, headerNameXFrame, "DENY")
if err := kclient.Create(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to create route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
defer func() {
if err := kclient.Delete(context.TODO(), echoRoute); err != nil {
t.Fatalf("failed to delete route %s/%s: %v", echoRoute.Namespace, echoRoute.Name, err)
}
}()
cond := routev1.RouteIngressCondition{
Type: routev1.RouteAdmitted,
Status: corev1.ConditionTrue,
}
echoRouteName := types.NamespacedName{
Namespace: echoRoute.Namespace,
Name: echoRoute.Name,
}
waitForRouteIngressConditions(t, kclient, echoRouteName, ic.Name, cond)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

for scanner.Scan() {
line := scanner.Text()
if strings.Contains(strings.ToLower(line), expectedResponse) {
t.Logf("found %d expected: %s", expectedMatches, line)
Copy link
Contributor

Choose a reason for hiding this comment

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

You aren't checking the number of matches anymore, so why do you need expectedMatches?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
}
}()
expectedResponse = strings.ToLower(expectedResponse)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use strings.ToLower here and below? Just delcare headerNameXFrame to be lower-case x-frame-options below, and then you don't need any strings.ToLower.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


func TestSetIngressControllerResponseHeaders(t *testing.T) {
t.Parallel()
var headerNameXFrame string = "X-Frame-Options"
Copy link
Contributor

Choose a reason for hiding this comment

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

Better yet:

Suggested change
var headerNameXFrame string = "X-Frame-Options"
const (
headerName = "x-frame-options"
headerValue = "DENY"
)

And replace "DENY" with headerValue below.


var podCount int

func testHeaders(t *testing.T, image string, route *routev1.Route, address string, headers []string, expectedResponse string, expectedMatches int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete the headers parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@Miciah
Copy link
Contributor

Miciah commented Aug 11, 2023

@miheer, the commits are backwards. Do the vendor bump first, then the implementation.

… used to set the HTTP

header request/reponse in Ingress Controller CR's spec.
The other files are generated files after running `go mod tidy` followed
by `go mod vendor`.
@miheer
Copy link
Contributor Author

miheer commented Aug 11, 2023

/retest

1 similar comment
@miheer
Copy link
Contributor Author

miheer commented Aug 11, 2023

/retest

@miheer
Copy link
Contributor Author

miheer commented Aug 11, 2023

https://github.com/openshift/cluster-ingress-operator/compare/5ceabd73033d098a2b3006370c1309b346ee1deb..29c86b4ca01dc3738c87018f6cfef2bfa6565bbc -first iteration RAW push had comments just had pushed to test. This had @candita 's suggestion for changing the block with return true and false and not using number of matches logic.

https://github.com/openshift/cluster-ingress-operator/compare/29c86b4ca01dc3738c87018f6cfef2bfa6565bbc..4dc8310c9d3698bf41ffd7b391a6ffa38951b60b --- comments removed and code was cleaned up.

https://github.com/openshift/cluster-ingress-operator/compare/4dc8310c9d3698bf41ffd7b391a6ffa38951b60b..32a6380e633d74a67db6f3007eccee5830e2d5a6 ---- consists of @Miciah suggestions and also some @candita suggestions to fix log statements.

The last push was just changing the sequence of the commits as
@Miciah proposed.

@miheer
Copy link
Contributor Author

miheer commented Aug 11, 2023

@miheer, the commits are backwards. Do the vendor bump first, then the implementation.

done

API
pkg/operator/controller/ingress/deployment.go Fetches the headers from
the ingress controller CR and then sets the router deployment with
environment vars with the header value and action.
pkg/operator/controller/ingress/deployment_test.go Units tests for
setting enviroment var in thr router deployment.
@miheer
Copy link
Contributor Author

miheer commented Aug 11, 2023

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 11, 2023

@miheer: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-ovn-serial a3a6318 link true /test e2e-gcp-ovn-serial

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.

@candita
Copy link
Contributor

candita commented Aug 11, 2023

Two hypershift unit tests failed:
=== FAIL: TestNodePool/NodePool_Tests_Group/TestNTOMachineConfigGetsRolledOut/EnsureNoCrashingPods (0.01s)
util.go:464: Container controller in pod cloud-network-config-controller-5d5b8949b-kgtk5 has a restartCount > 0 (1)
--- FAIL: TestNodePool/NodePool_Tests_Group/TestNTOMachineConfigGetsRolledOut/EnsureNoCrashingPods (0.01s)
=== FAIL: TestNodePool/NodePool_Tests_Group (0.00s)
--- FAIL: TestNodePool/NodePool_Tests_Group (0.00s)

/test e2e-hypershift

@candita
Copy link
Contributor

candita commented Aug 11, 2023

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: candita

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-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 11, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 11, 2023

/test remaining-required

@candita
Copy link
Contributor

candita commented Aug 11, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2023
@openshift-merge-robot openshift-merge-robot merged commit 56a00a7 into openshift:master Aug 11, 2023
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 jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. qe-approved Signifies that QE has signed off on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants