Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes-sigs/controller-runtime
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.15.1
Choose a base ref
...
head repository: kubernetes-sigs/controller-runtime
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.15.2
Choose a head ref
  • 4 commits
  • 4 files changed
  • 3 contributors

Commits on Aug 7, 2023

  1. terminal error fix

    sheidkamp committed Aug 7, 2023
    Copy the full SHA
    84525cc View commit details

Commits on Aug 8, 2023

  1. Merge pull request #2443 from sheidkamp/terminal-error-panic-backport…

    …-to-v0.15
    
    [release-0.15] 🐛 Fix TerminalError(nil).Error() panic
    k8s-ci-robot authored Aug 8, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0269522 View commit details

Commits on Aug 18, 2023

  1. Add missing return statement in the webhook admissions func

    As the function is currently written without a return, for an
    unstructured object which is successfully unmashalled, it will fall
    through to the subsequent lines and fail to decode properly.
    
    Add return statement to successful unstructured decode.
    
    Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
    lleshchi authored and k8s-infra-cherrypick-robot committed Aug 18, 2023
    Copy the full SHA
    685c56a View commit details
  2. 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
    k8s-ci-robot authored Aug 18, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    36bb899 View commit details
Showing with 43 additions and 0 deletions.
  1. +4 −0 pkg/reconcile/reconcile.go
  2. +5 −0 pkg/reconcile/reconcile_test.go
  3. +1 −0 pkg/webhook/admission/decode.go
  4. +33 −0 pkg/webhook/admission/decode_test.go
4 changes: 4 additions & 0 deletions pkg/reconcile/reconcile.go
Original file line number Diff line number Diff line change
@@ -112,11 +112,15 @@ type terminalError struct {
err error
}

// This function will return nil if te.err is nil.
func (te *terminalError) Unwrap() error {
return te.err
}

func (te *terminalError) Error() string {
if te.err == nil {
return "nil terminal error"
}
return "terminal error: " + te.err.Error()
}

5 changes: 5 additions & 0 deletions pkg/reconcile/reconcile_test.go
Original file line number Diff line number Diff line change
@@ -96,5 +96,10 @@ var _ = Describe("reconcile", func() {

Expect(apierrors.IsGone(terminalError)).To(BeTrue())
})

It("should handle nil terminal errors properly", func() {
err := reconcile.TerminalError(nil)
Expect(err.Error()).To(Equal("nil terminal error"))
})
})
})
1 change: 1 addition & 0 deletions pkg/webhook/admission/decode.go
Original file line number Diff line number Diff line change
@@ -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()
33 changes: 33 additions & 0 deletions pkg/webhook/admission/decode_test.go
Original file line number Diff line number Diff line change
@@ -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())
@@ -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())
})
})