MCPcopy
hub / github.com/vmware-tanzu/sonobuoy / Run

Function Run

pkg/discovery/discovery.go:71–233  ·  view source on GitHub ↗

Run is the main entrypoint for discovery.

(restConf *rest.Config, cfg *config.Config)

Source from the content-addressed store, hash-verified

69
70// Run is the main entrypoint for discovery.
71func Run(restConf *rest.Config, cfg *config.Config) (errCount int) {
72 kubeClient, err := kubernetes.NewForConfig(restConf)
73 if err != nil {
74 errlog.LogError(errors.Wrap(err, "could not create kubernetes client"))
75 return errCount + 1
76 }
77
78 t := time.Now()
79
80 // 1. Create the directory which will store the results, including the
81 // `meta` directory inside it (which we always need regardless of
82 // config)
83 outpath := filepath.Join(config.AggregatorResultsPath, cfg.UUID)
84 metapath := filepath.Join(outpath, MetaLocation)
85 err = os.MkdirAll(metapath, 0755)
86 if err != nil {
87 errlog.LogError(errors.Wrap(err, "could not create directory to store results"))
88 return errCount + 1
89 }
90
91 // Write logs to the configured results location. All log levels
92 // should write to the same log file
93 pathmap := make(lfshook.PathMap)
94 logfile := filepath.Join(metapath, "run.log")
95 for _, level := range logrus.AllLevels {
96 pathmap[level] = logfile
97 }
98
99 hook := lfshook.NewHook(pathmap, &logrus.JSONFormatter{})
100
101 logrus.AddHook(hook)
102
103 // Unset all hooks as we exit the Run function
104 defer func() {
105 logrus.StandardLogger().Hooks = make(logrus.LevelHooks)
106 }()
107 // closure used to collect and report errors.
108 trackErrorsFor := func(action string) func(error) {
109 return func(err error) {
110 if err != nil {
111 errCount++
112 errlog.LogError(errors.Wrapf(err, "error %v", action))
113 }
114 }
115 }
116
117 // Set initial annotation stating the pod is running. Ensures the annotation
118 // exists sooner for user/polling consumption and prevents issues were we try
119 // to patch a non-existant status later.
120 trackErrorsFor("setting initial pod status")(
121 setPodStatusAnnotation(kubeClient, cfg.Namespace,
122 &pluginaggregation.Status{
123 Status: pluginaggregation.RunningStatus,
124 }),
125 )
126
127 // 3. Dump the config.json we used to run our test
128 if blob, err := json.Marshal(cfg); err == nil {

Callers 1

runAggregatorFunction · 0.92

Calls 15

LogErrorFunction · 0.92
PostProcessPluginFunction · 0.92
SaveProcessedResultsFunction · 0.92
DirToTarballFunction · 0.92
setPodStatusAnnotationFunction · 0.85
avoidResultsDirIssueFunction · 0.85
QueryClusterFunction · 0.85
updatePluginStatusFunction · 0.85
dumpPluginFunction · 0.85
SaveHealthSummaryFunction · 0.85
getFileInfoFunction · 0.85
updateStatusFunction · 0.85

Tested by

no test coverage detected