Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.15] 馃悰 Add missing return statement in the webhook admissions func #2452

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/webhook/admission/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (d *Decoder) DecodeRaw(rawObj runtime.RawExtension, into runtime.Object) er
return err
}
unstructuredInto.SetUnstructuredContent(object)
return nil
}

deserializer := d.codecs.UniversalDeserializer()
Expand Down
33 changes: 33 additions & 0 deletions pkg/webhook/admission/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ var _ = Describe("Admission Webhook Decoder", func() {
}))
})

// NOTE: This will only pass if a GVK is provided. An unstructered object without a GVK may succeed
// in decoding to an alternate type.
It("should fail to decode if the object in the request doesn't match the passed-in type", func() {
By("trying to extract a pod from the quest into a node")
Expect(decoder.Decode(req, &corev1.Node{})).NotTo(Succeed())
Expand Down Expand Up @@ -152,4 +154,35 @@ var _ = Describe("Admission Webhook Decoder", func() {
"namespace": "default",
}))
})

req2 := Request{
AdmissionRequest: admissionv1.AdmissionRequest{
Operation: "CREATE",
Object: runtime.RawExtension{
Raw: []byte(`{
"metadata": {
"name": "foo",
"namespace": "default"
},
"spec": {
"containers": [
{
"image": "bar:v2",
"name": "bar"
}
]
}
}`),
},
OldObject: runtime.RawExtension{
Object: nil,
},
},
}

It("should decode a valid admission request without GVK", func() {
By("extracting the object from the request")
var target3 unstructured.Unstructured
Expect(decoder.DecodeRaw(req2.Object, &target3)).To(Succeed())
})
})