Skip to content

Commit 253952f

Browse files
Minor fixes (#31)
* fix: nil check on 204 response has to be allowed * ci: removed broken action for release note
1 parent 1e08b85 commit 253952f

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

.github/workflows/release-tag.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ jobs:
112112
run: |
113113
docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }}
114114
115-
- uses: googleapis/release-please-action@v4
116-
with:
117-
# this is a built-in strategy in release-please, see "Action Inputs"
118-
# for more options
119-
release-type: simple
115+
# - uses: googleapis/release-please-action@v4
116+
# with:
117+
# # this is a built-in strategy in release-please, see "Action Inputs"
118+
# # for more options
119+
# release-type: simple
120120

121121
test:
122122
runs-on: ubuntu-latest

internal/restResources/restResources.go

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,34 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
185185
}
186186
}
187187

188+
// Body can be nil if the API does not return anything on get with a proper status code (204 No Content, 304 Not Modified).
189+
if body == nil {
190+
cond := condition.Available()
191+
cond.Message = "Resource is assumed to be up-to-date. Returned body is nil."
192+
err = unstructuredtools.SetConditions(mg, cond)
193+
if err != nil {
194+
log.Debug("Setting condition", "error", err)
195+
return controller.ExternalObservation{}, err
196+
}
197+
_, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
198+
Pluralizer: h.pluralizer,
199+
DynamicClient: h.dynamicClient,
200+
})
201+
if err != nil {
202+
log.Debug("Updating status", "error", err)
203+
return controller.ExternalObservation{}, err
204+
}
205+
log.Debug("Resource is assumed to be up-to-date. Returned body is nil.")
206+
return controller.ExternalObservation{
207+
ResourceExists: true,
208+
ResourceUpToDate: true,
209+
}, nil
210+
}
188211
b, ok := body.(*map[string]interface{})
189212
if !ok {
190-
log.Debug("Performing REST call", "error", "body is not a map")
191-
return controller.ExternalObservation{}, fmt.Errorf("body is not a map")
213+
log.Debug("Performing REST call", "error", "body is not an object")
214+
return controller.ExternalObservation{}, fmt.Errorf("body is not an object")
192215
}
193-
194216
if b != nil {
195217
err = populateStatusFields(clientInfo, mg, b)
196218
if err != nil {
@@ -293,15 +315,19 @@ func (h *handler) Create(ctx context.Context, mg *unstructured.Unstructured) err
293315
log.Debug("Performing REST call", "error", err)
294316
return err
295317
}
296-
body, ok := body.(*map[string]interface{})
297-
if !ok {
298-
log.Debug("Performing REST call", "error", "body is not a map")
299-
return fmt.Errorf("body is not a map")
300-
}
301-
b, ok := body.(*map[string]interface{})
302-
if !ok {
303-
log.Debug("Performing REST call", "error", "body is not a map")
304-
return fmt.Errorf("body is not a map")
318+
319+
if body != nil {
320+
b, ok := body.(*map[string]interface{})
321+
if !ok {
322+
log.Debug("Performing REST call", "error", "body is not an object")
323+
return fmt.Errorf("body is not an object")
324+
}
325+
326+
err = populateStatusFields(clientInfo, mg, b)
327+
if err != nil {
328+
log.Debug("Updating identifiers", "error", err)
329+
return err
330+
}
305331
}
306332

307333
log.Debug("Creating external resource", "kind", mg.GetKind())
@@ -312,12 +338,6 @@ func (h *handler) Create(ctx context.Context, mg *unstructured.Unstructured) err
312338
return err
313339
}
314340

315-
err = populateStatusFields(clientInfo, mg, b)
316-
if err != nil {
317-
log.Debug("Updating identifiers", "error", err)
318-
return err
319-
}
320-
321341
_, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
322342
Pluralizer: h.pluralizer,
323343
DynamicClient: h.dynamicClient,
@@ -383,21 +403,19 @@ func (h *handler) Update(ctx context.Context, mg *unstructured.Unstructured) err
383403
return err
384404
}
385405

386-
// Handle case where API returns 204 No Content or empty body
406+
// Body can be empty if the API does not return anything on update with a proper status code (204 No Content, 304 Not Modified).
387407
if body != nil {
388408
b, ok := body.(*map[string]interface{})
389409
if !ok {
390-
log.Debug("Performing REST call", "error", "body is not a map")
391-
return fmt.Errorf("body is not a map")
410+
log.Debug("Performing REST call", "error", "body is not an object")
411+
return fmt.Errorf("body is not an object")
392412
}
393413

394414
err = populateStatusFields(clientInfo, mg, b)
395415
if err != nil {
396416
log.Debug("Updating identifiers", "error", err)
397417
return err
398418
}
399-
} else {
400-
log.Debug("Performing REST call", "error", "Body is nil (204 No Content)")
401419
}
402420

403421
log.Debug("Updating external resource", "kind", mg.GetKind())

0 commit comments

Comments
 (0)