(ctx context.Context, t task.Task, taskHook *hook.Hook, hookMeta task_metadata.HookMetadata, taskLogEntry *log.Logger, hookLogLabels map[string]string, metricLabels map[string]string)
| 731 | } |
| 732 | |
| 733 | func (op *ShellOperator) handleRunHook(ctx context.Context, t task.Task, taskHook *hook.Hook, hookMeta task_metadata.HookMetadata, taskLogEntry *log.Logger, hookLogLabels map[string]string, metricLabels map[string]string) error { |
| 734 | ctx, span := otel.Tracer(serviceName).Start(ctx, "handleRunHook") |
| 735 | defer span.End() |
| 736 | |
| 737 | for _, info := range taskHook.HookController.SnapshotsInfo() { |
| 738 | taskLogEntry.Debug("snapshot info", slog.String(pkg.LogKeyInfo, info)) |
| 739 | } |
| 740 | |
| 741 | result, err := taskHook.Run(ctx, hookMeta.BindingType, hookMeta.BindingContext, hookLogLabels) |
| 742 | if err != nil { |
| 743 | if result != nil && len(result.KubernetesPatchBytes) > 0 { |
| 744 | operations, patchStatusErr := objectpatch.ParseOperations(result.KubernetesPatchBytes) |
| 745 | if patchStatusErr != nil { |
| 746 | return fmt.Errorf("%s: couldn't patch status: %s", err, patchStatusErr) |
| 747 | } |
| 748 | |
| 749 | patchStatusErr = op.ObjectPatcher.ExecuteOperations(objectpatch.GetPatchStatusOperationsOnHookError(operations)) |
| 750 | if patchStatusErr != nil { |
| 751 | return fmt.Errorf("%s: couldn't patch status: %s", err, patchStatusErr) |
| 752 | } |
| 753 | } |
| 754 | return err |
| 755 | } |
| 756 | |
| 757 | if result.Usage != nil { |
| 758 | taskLogEntry.Debug("Usage", slog.String(pkg.LogKeyValue, fmt.Sprintf("%+v", result.Usage))) |
| 759 | op.MetricStorage.HistogramObserve(metrics.HookRunSysCPUSeconds, result.Usage.Sys.Seconds(), metricLabels, nil) |
| 760 | op.MetricStorage.HistogramObserve(metrics.HookRunUserCPUSeconds, result.Usage.User.Seconds(), metricLabels, nil) |
| 761 | op.MetricStorage.GaugeSet(metrics.HookRunMaxRSSBytes, float64(result.Usage.MaxRss)*1024, metricLabels) |
| 762 | } |
| 763 | |
| 764 | // Try to apply Kubernetes actions. |
| 765 | if len(result.KubernetesPatchBytes) > 0 { |
| 766 | operations, err := objectpatch.ParseOperations(result.KubernetesPatchBytes) |
| 767 | if err != nil { |
| 768 | return err |
| 769 | } |
| 770 | err = op.ObjectPatcher.ExecuteOperations(operations) |
| 771 | if err != nil { |
| 772 | return err |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | // Try to update custom metrics |
| 777 | err = op.HookMetricStorage.ApplyBatchOperations(result.Metrics, map[string]string{ |
| 778 | pkg.MetricKeyHook: hookMeta.HookName, |
| 779 | }) |
| 780 | if err != nil { |
| 781 | return err |
| 782 | } |
| 783 | |
| 784 | // Save validatingResponse in task props for future use. |
| 785 | if result.AdmissionResponse != nil { |
| 786 | t.SetProp("admissionResponse", result.AdmissionResponse) |
| 787 | taskLogEntry.Info("AdmissionResponse from hook", |
| 788 | slog.String(pkg.LogKeyValue, result.AdmissionResponse.Dump())) |
| 789 | } |
| 790 |
no test coverage detected