MCPcopy
hub / github.com/cilium/cilium / newFlowsCmdHelper

Function newFlowsCmdHelper

hubble/cmd/observe/flows.go:291–670  ·  view source on GitHub ↗
(usage cmdUsage, vp *viper.Viper, ofilter *flowFilter)

Source from the content-addressed store, hash-verified

289}
290
291func newFlowsCmdHelper(usage cmdUsage, vp *viper.Viper, ofilter *flowFilter) *cobra.Command {
292
293 filterFlags := pflag.NewFlagSet("filters", pflag.ContinueOnError)
294 rawFilterFlags := pflag.NewFlagSet("raw-filters", pflag.ContinueOnError)
295 flowsFormattingFlags := pflag.NewFlagSet("Flow Format", pflag.ContinueOnError)
296 flagSets := []*pflag.FlagSet{selectorFlags, filterFlags, rawFilterFlags, formattingFlags, flowsFormattingFlags, config.ServerFlags, otherFlags}
297
298 flowsCmd := &cobra.Command{
299 Example: usage.example,
300 Use: usage.use,
301 Short: usage.short,
302 Long: usage.long,
303 PreRunE: func(cmd *cobra.Command, _ []string) error {
304 // bind these flags to viper so that they can be specified as environment variables.
305 // We bind these flags during PreRun so that only the running command binds them to the configuration.
306 return vp.BindPFlags(rawFilterFlags)
307 },
308 RunE: func(cmd *cobra.Command, args []string) error {
309 debug := vp.GetBool(config.KeyDebug)
310 if err := handleFlowArgs(cmd.OutOrStdout(), ofilter, debug); err != nil {
311 return err
312 }
313 req, err := getFlowsRequest(ofilter, vp.GetStringSlice(allowlistFlag), vp.GetStringSlice(denylistFlag))
314 if err != nil {
315 return err
316 }
317 if otherOpts.printRawFilters {
318 filterYAML, err := getFlowFiltersYAML(req)
319 if err != nil {
320 return err
321 }
322 fmt.Fprint(cmd.OutOrStdout(), filterYAML)
323 return nil
324 }
325
326 ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
327 defer cancel()
328
329 client, cleanup, err := GetHubbleClientFunc(ctx, vp)
330 if err != nil {
331 return err
332 }
333 defer cleanup()
334
335 logger.Logger.Debug("Sending GetFlows request", logfields.Request, req)
336 if err := getFlows(ctx, client, req); err != nil {
337 msg := err.Error()
338 // extract custom error message from failed grpc call
339 if s, ok := status.FromError(err); ok && s.Code() == codes.Unknown {
340 msg = s.Message()
341 }
342 return errors.New(msg)
343 }
344 return nil
345 },
346 }
347
348 // filter flags

Callers 2

newObserveCmdFunction · 0.85
newFlowsCmdWithFilterFunction · 0.85

Calls 15

RegisterFlagSetsFunction · 0.92
handleFlowArgsFunction · 0.85
getFlowsRequestFunction · 0.85
getFlowFiltersYAMLFunction · 0.85
getFlowsFunction · 0.85
filterVarFunction · 0.85
filterVarPFunction · 0.85
reservedIdentitiesNamesFunction · 0.85
MessageMethod · 0.80
NewWriterMethod · 0.80
DebugMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…