Skip to content

Commit 0f3db0c

Browse files
authored
fix: report NotFound status for deleted KCC resources (#2689)
* fix: report NotFound status for deleted KCC resources The current custom StatusReader for Config Connector resources will report Unknown status when a Config Connector resource is not found (aka deleted). This causes the `kpt live destroy` reconcile loop to run forever since it expects a NotFound status to end. This commit ensures that deleted resources report a NotFound status instead. * refactor: Fix linting issue for unkeyed fields in composite literal
1 parent ef1a189 commit 0f3db0c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/status/configconnector.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strings"
2121

2222
v1 "k8s.io/api/core/v1"
23+
"k8s.io/apimachinery/pkg/api/errors"
2324
"k8s.io/apimachinery/pkg/api/meta"
2425
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2526
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -58,6 +59,9 @@ func (c *ConfigConnectorStatusReader) ReadStatus(ctx context.Context, reader eng
5859
u.SetGroupVersionKind(gvk)
5960
err = reader.Get(ctx, key, &u)
6061
if err != nil {
62+
if errors.IsNotFound(err) {
63+
return newResourceStatus(id, status.NotFoundStatus, &u, "Resource not found")
64+
}
6165
return newUnknownResourceStatus(id, nil, err)
6266
}
6367

pkg/status/configconnector_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/assert"
8+
"k8s.io/apimachinery/pkg/api/errors"
89
"k8s.io/apimachinery/pkg/runtime/schema"
910
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/testutil"
1011
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
@@ -53,6 +54,7 @@ func TestReadStatus(t *testing.T) {
5354
resource string
5455
gvk schema.GroupVersionKind
5556
expectedStatus status.Status
57+
deleted bool
5658
}{
5759
"Resource with deletionTimestap is Terminating": {
5860
resource: `
@@ -117,6 +119,22 @@ status:
117119
},
118120
expectedStatus: status.FailedStatus,
119121
},
122+
123+
"Resource has been deleted": {
124+
resource: `
125+
apiVersion: storage.cnrm.cloud.google.com/v1beta1
126+
kind: StorageBucket
127+
metadata:
128+
name: fake-bucket
129+
`,
130+
gvk: schema.GroupVersionKind{
131+
Group: "storage.cnrm.cloud.google.com",
132+
Version: "v1beta1",
133+
Kind: "StorageBucket",
134+
},
135+
expectedStatus: status.NotFoundStatus,
136+
deleted: true,
137+
},
120138
}
121139

122140
for tn, tc := range testCases {
@@ -126,6 +144,12 @@ status:
126144
fakeClusterReader := &fakeClusterReader{
127145
getResource: obj,
128146
}
147+
// Return not found error if we want the resource to be deleted.
148+
if tc.deleted {
149+
fakeClusterReader.getResource = nil
150+
fakeClusterReader.getErr = errors.NewNotFound(schema.GroupResource{Group: tc.gvk.Group, Resource: tc.gvk.Kind}, "fake-name")
151+
}
152+
129153
fakeMapper := fakemapper.NewFakeRESTMapper(tc.gvk)
130154
statusReader := &ConfigConnectorStatusReader{
131155
Mapper: fakeMapper,

0 commit comments

Comments
 (0)