From 1abf6547ffcf70c8e39d1138cc4dabe0b78a6e89 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 16 Jan 2024 18:28:00 -0500 Subject: [PATCH] engine: resources: http: Improved CheckApply for grouped resources --- engine/resources/http.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/engine/resources/http.go b/engine/resources/http.go index b3905f43..62c0e42b 100644 --- a/engine/resources/http.go +++ b/engine/resources/http.go @@ -353,7 +353,8 @@ func (obj *HTTPServerRes) Watch(ctx context.Context) error { // CheckApply never has anything to do for this resource, so it always succeeds. // It does however check that certain runtime requirements (such as the Root dir -// existing if one was specified) are fulfilled. +// existing if one was specified) are fulfilled. If there are any autogrouped +// resources, those will be recursively called so that they can send/recv. func (obj *HTTPServerRes) CheckApply(ctx context.Context, apply bool) (bool, error) { if obj.init.Debug { obj.init.Logf("CheckApply") @@ -363,6 +364,7 @@ func (obj *HTTPServerRes) CheckApply(ctx context.Context, apply bool) (bool, err // Watch has started up, so we must block here until that's the case... // Cheap runtime validation! + // XXX: maybe only do this only once to avoid repeated, unnecessary checks? if obj.Root != "" { fileInfo, err := os.Stat(obj.Root) if err != nil { @@ -373,7 +375,16 @@ func (obj *HTTPServerRes) CheckApply(ctx context.Context, apply bool) (bool, err } } - return true, nil // always succeeds, with nothing to do! + checkOK := true + for _, res := range obj.GetGroup() { // grouped elements + if c, err := res.CheckApply(ctx, apply); err != nil { + return false, errwrap.Wrapf(err, "autogrouped CheckApply failed") + } else if !c { + checkOK = false + } + } + + return checkOK, nil } // Cmp compares two resources and returns an error if they are not equivalent.