Skip to content

Commit 79b3985

Browse files
authored
Add a proper content type to Healthhook (#51)
Some application require the Content-Type be set to json to parse json. So now we provide it by default
1 parent fcb19c3 commit 79b3985

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/controller/applicationdisruptionbudget_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ func (r *ApplicationDisruptionBudgetResolver) CallHealthHook(ctx context.Context
222222
}
223223

224224
client := &http.Client{}
225+
headers := make(map[string][]string, 1)
225226

226227
data, err := json.Marshal(nd)
227228
if err != nil {
@@ -233,6 +234,10 @@ func (r *ApplicationDisruptionBudgetResolver) CallHealthHook(ctx context.Context
233234
return err
234235
}
235236

237+
headers["Content-Type"] = []string{"application/json"}
238+
239+
req.Header = headers
240+
236241
resp, err := client.Do(req)
237242
if err != nil {
238243
return err

internal/controller/nodedisruption_controller_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ var _ = Describe("NodeDisruption controller", func() {
248248
Expect(err).Should(Succeed())
249249
hookURL = req.URL.String()
250250
hookCallCount++
251+
// Validate that the hook is called with valid headers
252+
Expect(req.Header["Content-Type"][0]).Should(Equal("application/json"))
251253
w.WriteHeader(http.StatusOK)
252254
}
253255

0 commit comments

Comments
 (0)