-
Notifications
You must be signed in to change notification settings - Fork 462
/
mutator.go
37 lines (29 loc) · 1.05 KB
/
mutator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package webhook
import (
"context"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// Mutator validates and if needed mutates objects.
type Mutator interface {
// Mutate validates and if needed mutates the given object.
// "old" is optional and it must always be checked for nil.
Mutate(ctx context.Context, new, old client.Object) error
}
// MutatorWithShootClient validates and if needed mutates objects. It needs the shoot client.
type MutatorWithShootClient interface {
// Mutate validates and if needed mutates the given object.
// "old" is optional and it must always be checked for nil.
Mutate(ctx context.Context, new, old client.Object, shootClient client.Client) error
}
type mutationWrapper struct {
Mutator
}
func (d *mutationWrapper) do(ctx context.Context, new, old client.Object) error {
return d.Mutate(ctx, new, old)
}
func mutatingActionHandler(val Mutator) handlerAction {
return &mutationWrapper{val}
}