Skip to content

Commit fe44f28

Browse files
authored
Improve operator's client SSA error handling (#1485)
1 parent 2eea4f1 commit fe44f28

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/controller/client/client.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/pkg/errors"
8+
k8serr "k8s.io/apimachinery/pkg/api/errors"
89
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
910
"k8s.io/client-go/discovery"
1011
"k8s.io/client-go/dynamic"
@@ -71,7 +72,10 @@ func (c *Client) Apply(ctx context.Context, in ctrlCli.Object, opts ...ctrlCli.P
7172
unstructured.RemoveNestedField(u.Object, "status")
7273

7374
err = c.Client.Patch(ctx, u, ctrlCli.Apply, opts...)
74-
if err != nil {
75+
switch {
76+
case k8serr.IsNotFound(err):
77+
return nil
78+
case err != nil:
7579
return fmt.Errorf("unable to patch object %s: %w", u, err)
7680
}
7781

@@ -98,7 +102,10 @@ func (c *Client) ApplyStatus(ctx context.Context, in ctrlCli.Object, opts ...ctr
98102
unstructured.RemoveNestedField(u.Object, "metadata", "resourceVersion")
99103

100104
err = c.Client.Status().Patch(ctx, u, ctrlCli.Apply, opts...)
101-
if err != nil {
105+
switch {
106+
case k8serr.IsNotFound(err):
107+
return nil
108+
case err != nil:
102109
return fmt.Errorf("unable to patch object status %s: %w", u, err)
103110
}
104111

0 commit comments

Comments
 (0)