-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix content headers in Health Check Node Port response #26458
Conversation
Commit 19e3244f61b09fc21bbb67f713685cecc80c56da does not contain "Signed-off-by". Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin |
before the fix 2 content headers are not returned ```release-note Fix: Return "Content-Type" and "X-Content-Type-Options" headers from Health Check Node Port ``` Signed-off-by: Cezary Zawadka <czawadka@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/test |
@@ -8,6 +8,7 @@ import ( | |||
"net/http/httptest" | |||
"testing" | |||
|
|||
"github.com/google/go-cmp/cmp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to run gofmt on this file
ake: *** [Makefile:645: precheck] Error 1
Unformatted Go source code:
make: *** Waiting for unfinished jobs....
./pkg/service/healthserver/healthserver_test.go
diff ./pkg/service/healthserver/healthserver_test.go.orig ./pkg/service/healthserver/healthserver_test.go
--- ./pkg/service/healthserver/healthserver_test.go.orig
+++ ./pkg/service/healthserver/healthserver_test.go
@@ -8,8 +8,8 @@
"net/http/httptest"
"testing"
- "github.com/google/go-cmp/cmp"
. "github.com/cilium/checkmate"
+ "github.com/google/go-cmp/cmp"
)
type ServiceHealthServerSuite struct{}
@@ -94,7 +94,7 @@
assertRespHeader(c, resp, "Content-Type", "application/json")
assertRespHeader(c, resp, "X-Content-Type-Options", "nosniff")
resp.Body.Close()
-
+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if svc.LocalEndpoints == 0 { | ||
w.WriteHeader(http.StatusServiceUnavailable) | ||
} else { | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
w.Header().Set("Content-Type", "application/json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are trailers https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer
https://pkg.go.dev/net/http#example-ResponseWriter-Trailers
I do not know if this is on purpose though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not look that using trailers instead of headers are on purpose, and using headers is coherent with kube-proxy https://github.com/kubernetes/kubernetes/blob/027ac5a426a261ba6b66a40e79e123e75e9baf5b/pkg/proxy/healthcheck/proxier_health.go#L159-L173 , since this is a "replacement" it makes sense to be consistent.
Also, the failing test indicates that the goal may have been to use headers in the first place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar code in kube-proxy uses regular headers, not trailers
Signed-off-by: Cezary Zawadka <czawadka@google.com>
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Did this actually cause issues or how did you find this?
All required tests passing, and multiple committers approved. Merging 🚀 |
google loadbalancers can use the headers for passing the data of the existing endpoints on the node and this way use weights, the headers were not coming at all 😄 |
Fix content headers in Health Check Node Port response.
Before the fix 2 content headers are not returned, because
w.WriteHeader(http.StatusOK)
must be called after setting the headers map