Skip to content

Commit

Permalink
Add a proper content type to Healthhook (#51)
Browse files Browse the repository at this point in the history
Some application require the Content-Type be set to json
to parse json. So now we provide it by default
  • Loading branch information
geobeau authored Dec 12, 2023
1 parent fcb19c3 commit 79b3985
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/controller/applicationdisruptionbudget_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (r *ApplicationDisruptionBudgetResolver) CallHealthHook(ctx context.Context
}

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

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

headers["Content-Type"] = []string{"application/json"}

req.Header = headers

resp, err := client.Do(req)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/nodedisruption_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ var _ = Describe("NodeDisruption controller", func() {
Expect(err).Should(Succeed())
hookURL = req.URL.String()
hookCallCount++
// Validate that the hook is called with valid headers
Expect(req.Header["Content-Type"][0]).Should(Equal("application/json"))
w.WriteHeader(http.StatusOK)
}

Expand Down

0 comments on commit 79b3985

Please sign in to comment.