Skip to content

Commit

Permalink
pkg/gadget-context: remove lazy operator initialization
Browse files Browse the repository at this point in the history
Operator initialization should be handled by the caller that is also creating the
gadget context, not the gadget context itself. This removes the old code and relies
on initialization taking place somewhere else.

Signed-off-by: Michael Friese <mfriese@microsoft.com>
  • Loading branch information
flyth committed May 27, 2024
1 parent acccfef commit 256ca84
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions pkg/gadget-context/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,11 @@ func (c *GadgetContext) initAndPrepareOperators(paramValues api.ParamValues) ([]
log.Debugf("initializing data op %q", op.Name())
opParamPrefix := fmt.Sprintf("operator.%s", op.Name())

// Lazily initialize operator
// TODO: global params should be filled out from a config file or such; maybe it's a better idea not to
// lazily initialize operators at all, but just hand over the config. The "lazy" stuff could then be done
// if the operator is instantiated and needs to do work
err := op.Init(apihelpers.ToParamDescs(op.GlobalParams()).ToParams())
if err != nil {
return nil, fmt.Errorf("initializing operator %q: %w", op.Name(), err)
}

// Get and fill params
instanceParams := op.InstanceParams().AddPrefix(opParamPrefix)
opParamValues := paramValues.ExtractPrefixedValues(opParamPrefix)

err = apihelpers.Validate(instanceParams, opParamValues)
err := apihelpers.Validate(instanceParams, opParamValues)
if err != nil {
return nil, fmt.Errorf("validating params for operator %q: %w", op.Name(), err)
}
Expand Down

0 comments on commit 256ca84

Please sign in to comment.