operator implements the "report operator" subcommand Produces a zip file containing - operator deployment - operator pod definition - operator configuration Configmap and Secret key (if any) - events in the operator namespace - operator's Validating/MutatingWebhookConfiguration and their associated
(ctx context.Context, format plugin.OutputFormat, file string, stopRedaction, includeLogs, logTimeStamp bool, now time.Time, )
| 136 | // - operator's Validating/MutatingWebhookConfiguration and their associated services (optional) |
| 137 | // - operator pod's logs (optional, if `includeLogs` is true) |
| 138 | func operator(ctx context.Context, format plugin.OutputFormat, |
| 139 | file string, stopRedaction, includeLogs, logTimeStamp bool, now time.Time, |
| 140 | ) error { |
| 141 | // Configure redactors |
| 142 | secretRedactor, configMapRedactor := configureRedactors(stopRedaction) |
| 143 | |
| 144 | // Collect deployment (the only truly required resource) |
| 145 | deployment, err := getOperatorDeployment(ctx) |
| 146 | if errors.Is(err, errNoOperatorDeployment) { |
| 147 | return fmt.Errorf("%w\n"+ |
| 148 | "HINT: Operator might be installed in another namespace."+ |
| 149 | "Specify a namespace using the '-n' option", err) |
| 150 | } |
| 151 | if err != nil { |
| 152 | return fmt.Errorf("could not get operator deployment: %w", err) |
| 153 | } |
| 154 | |
| 155 | // Collect all optional resources (all can fail gracefully) |
| 156 | pods := tryCollectPods(ctx) |
| 157 | secrets, configs := tryCollectConfigurations(ctx, deployment, secretRedactor, configMapRedactor) |
| 158 | events := tryCollectEvents(ctx, deployment.Namespace) |
| 159 | mutatingWebhook, validatingWebhook := tryCollectWebhooks(ctx, stopRedaction) |
| 160 | webhookService := tryCollectWebhookService(ctx, mutatingWebhook) |
| 161 | |
| 162 | // Build the report structure |
| 163 | rep := operatorReport{ |
| 164 | deployment: deployment, |
| 165 | operatorPods: pods, |
| 166 | secrets: secrets, |
| 167 | configs: configs, |
| 168 | events: events, |
| 169 | mutatingWebhookConfig: mutatingWebhook, |
| 170 | validatingWebhookConfig: validatingWebhook, |
| 171 | webhookService: webhookService, |
| 172 | } |
| 173 | |
| 174 | // Assemble all sections for the ZIP file |
| 175 | sections := assembleSections(ctx, rep, pods, format, includeLogs, logTimeStamp) |
| 176 | |
| 177 | // Write the final report |
| 178 | if err := writeZippedReport(sections, file, reportName("operator", now)); err != nil { |
| 179 | return fmt.Errorf("could not write report: %w", err) |
| 180 | } |
| 181 | |
| 182 | fmt.Printf("Successfully written report to \"%s\" (format: \"%s\")\n", file, format) |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | // configureRedactors sets up the appropriate redaction functions based on user preference |
| 187 | func configureRedactors(stopRedaction bool) ( |
no test coverage detected