File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -3403,6 +3403,32 @@ var _ = Describe("IgnoreNotFound", func() {
34033403 })
34043404})
34053405
3406+ var _ = Describe ("IgnoreAlreadyExists" , func () {
3407+ It ("should return nil on a 'AlreadyExists' error" , func () {
3408+ By ("creating a AlreadyExists error" )
3409+ err := apierrors .NewAlreadyExists (schema.GroupResource {}, "" )
3410+
3411+ By ("returning no error" )
3412+ Expect (client .IgnoreAlreadyExists (err )).To (Succeed ())
3413+ })
3414+
3415+ It ("should return the error on a status other than already exists" , func () {
3416+ By ("creating a BadRequest error" )
3417+ err := apierrors .NewBadRequest ("" )
3418+
3419+ By ("returning an error" )
3420+ Expect (client .IgnoreAlreadyExists (err )).To (HaveOccurred ())
3421+ })
3422+
3423+ It ("should return the error on a non-status error" , func () {
3424+ By ("creating an fmt error" )
3425+ err := fmt .Errorf ("arbitrary error" )
3426+
3427+ By ("returning an error" )
3428+ Expect (client .IgnoreAlreadyExists (err )).To (HaveOccurred ())
3429+ })
3430+ })
3431+
34063432type fakeReader struct {
34073433 Called int
34083434}
Original file line number Diff line number Diff line change @@ -143,3 +143,13 @@ func IgnoreNotFound(err error) error {
143143 }
144144 return err
145145}
146+
147+ // IgnoreAlreadyExists returns nil on AlreadyExists errors.
148+ // All other values that are not AlreadyExists errors or nil are returned unmodified.
149+ func IgnoreAlreadyExists (err error ) error {
150+ if apierrors .IsAlreadyExists (err ) {
151+ return nil
152+ }
153+
154+ return err
155+ }
You can’t perform that action at this time.
0 commit comments