Skip to content

Commit 70599c2

Browse files
authored
Merge pull request #9 from appuio/fix/newline-in-warning
Fix invalid warning with newline
2 parents 9216e2a + c1a85e3 commit 70599c2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

webhooks/ratio_validator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ func (v *RatioValidator) Handle(ctx context.Context, req admission.Request) admi
7070
if r.Below(*v.RatioLimit) {
7171
return admission.Response{
7272
AdmissionResponse: admissionv1.AdmissionResponse{
73-
Allowed: true,
74-
Warnings: []string{fmt.Sprintf("Current memory to CPU ratio of %s/core in this namespace is below the fair use ratio of %s/core\n This might lead to additional cost.", r, v.RatioLimit)},
73+
Allowed: true,
74+
// WARNING(glrf) Warnings MUST NOT contain newlines. K8s will simply drop your warning if you add newlines.
75+
Warnings: []string{
76+
fmt.Sprintf("Current memory to CPU ratio of %s/core in this namespace is below the fair use ratio of %s/core. This might lead to additional costs.", r, v.RatioLimit),
77+
},
7578
}}
7679
}
7780
return admission.Allowed("ok")

webhooks/ratio_validator_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func TestRatioValidator_Handle(t *testing.T) {
226226
assert.True(t, resp.Allowed)
227227
if tc.warn {
228228
assert.NotEmpty(t, resp.AdmissionResponse.Warnings)
229+
for _, w := range resp.AdmissionResponse.Warnings {
230+
assert.NotContainsf(t, w, "\n", "Warning are not allowed to contain newlines")
231+
}
229232
} else {
230233
assert.Empty(t, resp.AdmissionResponse.Warnings)
231234
}

0 commit comments

Comments
 (0)