(ctx context.Context, conf *v1.ValidatingWebhookConfiguration)
| 120 | } |
| 121 | |
| 122 | func (w *ValidatingWebhookResource) submit(ctx context.Context, conf *v1.ValidatingWebhookConfiguration) error { |
| 123 | client := w.opts.KubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations() |
| 124 | listOpts := metav1.ListOptions{ |
| 125 | FieldSelector: "metadata.name=" + conf.Name, |
| 126 | } |
| 127 | |
| 128 | return retry.WithBackoff(ctx, submitRetryConfig, w.logger.With(slog.String(pkg.LogKeyName, conf.Name)), |
| 129 | "ValidatingWebhookConfiguration/submit", func() error { |
| 130 | list, err := client.List(ctx, listOpts) |
| 131 | if err != nil { |
| 132 | return fmt.Errorf("list ValidatingWebhookConfiguration: %w", err) |
| 133 | } |
| 134 | if len(list.Items) == 0 { |
| 135 | if _, err := client.Create(ctx, conf, pkg.DefaultCreateOptions()); err != nil { |
| 136 | return fmt.Errorf("create ValidatingWebhookConfiguration: %w", err) |
| 137 | } |
| 138 | } else { |
| 139 | newConf := list.Items[0] |
| 140 | newConf.Webhooks = conf.Webhooks |
| 141 | if _, err := client.Update(ctx, &newConf, pkg.DefaultUpdateOptions()); err != nil { |
| 142 | return fmt.Errorf("update ValidatingWebhookConfiguration: %w", err) |
| 143 | } |
| 144 | } |
| 145 | return nil |
| 146 | }) |
| 147 | } |
| 148 | |
| 149 | type MutatingWebhookResource struct { |
| 150 | hooks map[string]*MutatingWebhookConfig |
no test coverage detected