Skip to content

Commit 36bb899

Browse files
authored
Merge pull request #2452 from k8s-infra-cherrypick-robot/cherry-pick-2433-to-release-0.15
[release-0.15] 🐛 Add missing return statement in the webhook admissions func
2 parents 0269522 + 685c56a commit 36bb899

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

pkg/webhook/admission/decode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (d *Decoder) DecodeRaw(rawObj runtime.RawExtension, into runtime.Object) er
7171
return err
7272
}
7373
unstructuredInto.SetUnstructuredContent(object)
74+
return nil
7475
}
7576

7677
deserializer := d.codecs.UniversalDeserializer()

pkg/webhook/admission/decode_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ var _ = Describe("Admission Webhook Decoder", func() {
123123
}))
124124
})
125125

126+
// NOTE: This will only pass if a GVK is provided. An unstructered object without a GVK may succeed
127+
// in decoding to an alternate type.
126128
It("should fail to decode if the object in the request doesn't match the passed-in type", func() {
127129
By("trying to extract a pod from the quest into a node")
128130
Expect(decoder.Decode(req, &corev1.Node{})).NotTo(Succeed())
@@ -152,4 +154,35 @@ var _ = Describe("Admission Webhook Decoder", func() {
152154
"namespace": "default",
153155
}))
154156
})
157+
158+
req2 := Request{
159+
AdmissionRequest: admissionv1.AdmissionRequest{
160+
Operation: "CREATE",
161+
Object: runtime.RawExtension{
162+
Raw: []byte(`{
163+
"metadata": {
164+
"name": "foo",
165+
"namespace": "default"
166+
},
167+
"spec": {
168+
"containers": [
169+
{
170+
"image": "bar:v2",
171+
"name": "bar"
172+
}
173+
]
174+
}
175+
}`),
176+
},
177+
OldObject: runtime.RawExtension{
178+
Object: nil,
179+
},
180+
},
181+
}
182+
183+
It("should decode a valid admission request without GVK", func() {
184+
By("extracting the object from the request")
185+
var target3 unstructured.Unstructured
186+
Expect(decoder.DecodeRaw(req2.Object, &target3)).To(Succeed())
187+
})
155188
})

0 commit comments

Comments
 (0)