From 8d9bfa1f5fee85abf05a4d893b772831de506776 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 00:05:13 +0000 Subject: [PATCH] fix(deps): update github.com/cilium/hive digest to d66ad09 Signed-off-by: renovate[bot] --- cmapisrv-mock/go.mod | 2 +- cmapisrv-mock/go.sum | 4 +- .../github.com/cilium/hive/script/cmds.go | 10 ++- .../github.com/cilium/hive/script/engine.go | 77 ++++++++++++++----- .../github.com/cilium/hive/script/state.go | 17 ++-- cmapisrv-mock/vendor/modules.txt | 2 +- 6 files changed, 81 insertions(+), 31 deletions(-) diff --git a/cmapisrv-mock/go.mod b/cmapisrv-mock/go.mod index 4479374..08e805b 100644 --- a/cmapisrv-mock/go.mod +++ b/cmapisrv-mock/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/cilium/cilium v1.16.3 - github.com/cilium/hive v0.0.0-20241021113747-bb8f3c0bede4 + github.com/cilium/hive v0.0.0-20241025140746-d66ad09f4384 github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.1 diff --git a/cmapisrv-mock/go.sum b/cmapisrv-mock/go.sum index 94269e8..21bdf7d 100644 --- a/cmapisrv-mock/go.sum +++ b/cmapisrv-mock/go.sum @@ -31,8 +31,8 @@ github.com/cilium/cilium v1.16.3 h1:Pdm3FdcdrGZ0Zh2i1oADmM89WE9xbePhRiL/8UqxEWY= github.com/cilium/cilium v1.16.3/go.mod h1:w6huXlvvCbDrOdKW1P5FXjT3JIXzEREtXbvhhMZHxKM= github.com/cilium/ebpf v0.15.0 h1:7NxJhNiBT3NG8pZJ3c+yfrVdHY8ScgKD27sScgjLMMk= github.com/cilium/ebpf v0.15.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso= -github.com/cilium/hive v0.0.0-20241021113747-bb8f3c0bede4 h1:dTnQNUDijFP+hf7soSZtoBYZ1OTV7qATqE+qbb//zUQ= -github.com/cilium/hive v0.0.0-20241021113747-bb8f3c0bede4/go.mod h1:pI2GJ1n3SLKIQVFrKF7W6A6gb6BQkZ+3Hp4PAEo5SuI= +github.com/cilium/hive v0.0.0-20241025140746-d66ad09f4384 h1:MAkG2lk4v0Z8J2X4+fFnhuCEsIJGPdCCrWzL41S2Z/I= +github.com/cilium/hive v0.0.0-20241025140746-d66ad09f4384/go.mod h1:pI2GJ1n3SLKIQVFrKF7W6A6gb6BQkZ+3Hp4PAEo5SuI= github.com/cilium/proxy v0.0.0-20240418093727-2c7164c53e26 h1:wzm/nEkcMO6oGSySoqe3/bMcF1sxrxI2ByidN3gg30A= github.com/cilium/proxy v0.0.0-20240418093727-2c7164c53e26/go.mod h1:jzAmtWhlyR3kx+AwYdQvGM04lmHwsWhq1ySfAVpY/SA= github.com/cilium/statedb v0.2.4 h1:jCyXGcsiXgpJSfpfRRGKd+TD3U1teeDtOnqCyErsHsI= diff --git a/cmapisrv-mock/vendor/github.com/cilium/hive/script/cmds.go b/cmapisrv-mock/vendor/github.com/cilium/hive/script/cmds.go index acea412..7ae0a79 100644 --- a/cmapisrv-mock/vendor/github.com/cilium/hive/script/cmds.go +++ b/cmapisrv-mock/vendor/github.com/cilium/hive/script/cmds.go @@ -249,6 +249,14 @@ func doCompare(s *State, env bool, args ...string) error { } if text1 != text2 { + if s.DoUpdate { + // Updates requested, store the file contents and + // ignore mismatches. + s.FileUpdates[name1] = text2 + s.FileUpdates[name2] = text1 + return nil + } + if !quiet { diffText := diff.Diff(name1, []byte(text1), name2, []byte(text2)) s.Logf("%s\n", diffText) @@ -653,7 +661,7 @@ func match(s *State, args []string, text, name string) error { isGrep := name == "grep" wantArgs := 1 - if len(args) != wantArgs { + if !isGrep && len(args) != wantArgs { return ErrUsage } diff --git a/cmapisrv-mock/vendor/github.com/cilium/hive/script/engine.go b/cmapisrv-mock/vendor/github.com/cilium/hive/script/engine.go index 7b9b9bf..75293cb 100644 --- a/cmapisrv-mock/vendor/github.com/cilium/hive/script/engine.go +++ b/cmapisrv-mock/vendor/github.com/cilium/hive/script/engine.go @@ -73,16 +73,23 @@ type Engine struct { // If Quiet is true, Execute deletes log prints from the previous // section when starting a new section. Quiet bool + + // RetryInterval for retrying commands marked with '*'. If zero, then + // the default retry interval is used. + RetryInterval time.Duration } // NewEngine returns an Engine configured with a basic set of commands and conditions. func NewEngine() *Engine { return &Engine{ - Cmds: DefaultCmds(), - Conds: DefaultConds(), + Cmds: DefaultCmds(), + Conds: DefaultConds(), + RetryInterval: defaultRetryInterval, } } +const defaultRetryInterval = 100 * time.Millisecond + // A Cmd is a command that is available to a script. type Cmd interface { // Run begins running the command. @@ -167,7 +174,15 @@ func (e *Engine) Execute(s *State, file string, script *bufio.Reader, log io.Wri defer func(prev io.Writer) { s.logOut = prev }(s.logOut) s.logOut = log - var sectionStart time.Time + retryInterval := e.RetryInterval + if retryInterval == 0 { + retryInterval = defaultRetryInterval + } + + var ( + sectionStart time.Time + sectionCmds []*command + ) // endSection flushes the logs for the current section from s.log to log. // ok indicates whether all commands in the section succeeded. endSection := func(ok bool) error { @@ -193,6 +208,7 @@ func (e *Engine) Execute(s *State, file string, script *bufio.Reader, log io.Wri } sectionStart = time.Time{} + sectionCmds = nil return err } @@ -257,6 +273,8 @@ func (e *Engine) Execute(s *State, file string, script *bufio.Reader, log io.Wri if cmd == nil && err == nil { continue // Ignore blank lines. } + sectionCmds = append(sectionCmds, cmd) + s.Logf("> %s\n", line) if err != nil { return lineErr(err) @@ -296,16 +314,33 @@ func (e *Engine) Execute(s *State, file string, script *bufio.Reader, log io.Wri // Run the command. err = e.runCommand(s, cmd, impl) if err != nil { - if stop := (stopError{}); errors.As(err, &stop) { - // Since the 'stop' command halts execution of the entire script, - // log its message separately from the section in which it appears. - err = endSection(true) - s.Logf("%v\n", stop) - if err == nil { - return nil + if cmd.want == successRetryOnFailure || cmd.want == failureRetryOnSuccess { + // Command wants retries. Retry the whole section + for err != nil { + select { + case <-s.Context().Done(): + return lineErr(s.Context().Err()) + case <-time.After(retryInterval): + } + for _, cmd := range sectionCmds { + impl := e.Cmds[cmd.name] + if err = e.runCommand(s, cmd, impl); err != nil { + break + } + } } + } else { + if stop := (stopError{}); errors.As(err, &stop) { + // Since the 'stop' command halts execution of the entire script, + // log its message separately from the section in which it appears. + err = endSection(true) + s.Logf("%v\n", stop) + if err == nil { + return nil + } + } + return lineErr(err) } - return lineErr(err) } } @@ -394,9 +429,11 @@ type command struct { type expectedStatus string const ( - success expectedStatus = "" - failure expectedStatus = "!" - successOrFailure expectedStatus = "?" + success expectedStatus = "" + failure expectedStatus = "!" + successOrFailure expectedStatus = "?" + successRetryOnFailure expectedStatus = "*" + failureRetryOnSuccess expectedStatus = "!*" ) type argFragment struct { @@ -437,10 +474,12 @@ func parse(filename string, lineno int, line string) (cmd *command, err error) { // Command prefix ! means negate the expectations about this command: // go command should fail, match should not be found, etc. // Prefix ? means allow either success or failure. + // Prefix * means to retry the command until success (or context cancelled) + // Prefix !* means to retry the command until failure (or context cancelled) switch want := expectedStatus(arg); want { - case failure, successOrFailure: + case failure, successOrFailure, successRetryOnFailure, failureRetryOnSuccess: if cmd.want != "" { - return errors.New("duplicated '!' or '?' token") + return errors.New("duplicated '!', '?', '*' or '!*' token") } cmd.want = want return nil @@ -674,7 +713,7 @@ func (e *Engine) runCommand(s *State, cmd *command, impl Cmd) error { func checkStatus(cmd *command, err error) error { if err == nil { - if cmd.want == failure { + if cmd.want == failure || cmd.want == failureRetryOnSuccess { return cmdError(cmd, ErrUnexpectedSuccess) } return nil @@ -695,11 +734,11 @@ func checkStatus(cmd *command, err error) error { return cmdError(cmd, err) } - if cmd.want == success { + if cmd.want == success || cmd.want == successRetryOnFailure { return cmdError(cmd, err) } - if cmd.want == failure && (errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled)) { + if (cmd.want == failure || cmd.want == failureRetryOnSuccess) && (errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled)) { // The command was terminated because the script is no longer interested in // its output, so we don't know what it would have done had it run to // completion — for all we know, it could have exited without error if it diff --git a/cmapisrv-mock/vendor/github.com/cilium/hive/script/state.go b/cmapisrv-mock/vendor/github.com/cilium/hive/script/state.go index 1226dcf..9a3580b 100644 --- a/cmapisrv-mock/vendor/github.com/cilium/hive/script/state.go +++ b/cmapisrv-mock/vendor/github.com/cilium/hive/script/state.go @@ -26,7 +26,6 @@ type State struct { ctx context.Context cancel context.CancelFunc - file string log bytes.Buffer logOut io.Writer @@ -37,6 +36,9 @@ type State struct { stdout string // standard output from last 'go' command; for 'stdout' command stderr string // standard error from last 'go' command; for 'stderr' command + DoUpdate bool + FileUpdates map[string]string + background []backgroundCmd } @@ -79,12 +81,13 @@ func NewState(ctx context.Context, workdir string, initialEnv []string) (*State, } s := &State{ - ctx: ctx, - cancel: cancel, - workdir: absWork, - pwd: absWork, - env: env, - envMap: envMap, + ctx: ctx, + cancel: cancel, + workdir: absWork, + pwd: absWork, + env: env, + envMap: envMap, + FileUpdates: make(map[string]string), } s.Setenv("PWD", absWork) return s, nil diff --git a/cmapisrv-mock/vendor/modules.txt b/cmapisrv-mock/vendor/modules.txt index f5cd1e4..081b0f7 100644 --- a/cmapisrv-mock/vendor/modules.txt +++ b/cmapisrv-mock/vendor/modules.txt @@ -124,7 +124,7 @@ github.com/cilium/ebpf/internal/sysenc github.com/cilium/ebpf/internal/tracefs github.com/cilium/ebpf/internal/unix github.com/cilium/ebpf/link -# github.com/cilium/hive v0.0.0-20241021113747-bb8f3c0bede4 +# github.com/cilium/hive v0.0.0-20241025140746-d66ad09f4384 ## explicit; go 1.21.3 github.com/cilium/hive github.com/cilium/hive/cell