@@ -17,18 +17,19 @@ import (
17
17
18
18
// +kubebuilder:webhook:path=/mutate-v1-pod,mutating=true,failurePolicy=ignore,groups=core,resources=pods,verbs=create;update,versions=v1,name=fsgroupchangepolicy.postgres.fits.cloud
19
19
20
- // FsGroupChangePolicySetter Adds securityContext.fsGroupChangePolicy=OnRootMismatch when the securityContext.fsGroup field is set
21
- type FsGroupChangePolicySetter struct {
20
+ // SpiloPodMutator Adds securityContext.fsGroupChangePolicy=OnRootMismatch when the securityContext.fsGroup field is set
21
+ type SpiloPodMutator struct {
22
22
SvcClient client.Client
23
23
Decoder admission.Decoder
24
24
Log logr.Logger
25
+ EnableFsGroupChangePolicyWebhook bool
25
26
EnablePodTopologySpreadConstraintWebhook bool
26
27
PodTopologySpreadConstraintTopologyKey string
27
28
PodTopologySpreadConstraintMaxSkew int32
28
29
PodTopologySpreadConstraintMinDomains int32
29
30
}
30
31
31
- func (a * FsGroupChangePolicySetter ) Handle (ctx context.Context , req admission.Request ) admission.Response {
32
+ func (a * SpiloPodMutator ) Handle (ctx context.Context , req admission.Request ) admission.Response {
32
33
log := a .Log .WithValues ("name" , req .Name , "ns" , req .Namespace )
33
34
log .V (1 ).Info ("handling admission request" )
34
35
@@ -39,11 +40,16 @@ func (a *FsGroupChangePolicySetter) Handle(ctx context.Context, req admission.Re
39
40
return admission .Errored (http .StatusBadRequest , err )
40
41
}
41
42
42
- // when the fsGroup field is set, also set the fsGroupChangePolicy to OnRootMismatch
43
- if pod .Spec .SecurityContext != nil && pod .Spec .SecurityContext .FSGroup != nil {
44
- p := v1 .FSGroupChangeOnRootMismatch
45
- pod .Spec .SecurityContext .FSGroupChangePolicy = & p
46
- log .V (1 ).Info ("Mutating Pod securityContext" , "pod" , pod )
43
+ //
44
+ // FSGroupChangePolicy
45
+ //
46
+ if a .EnableFsGroupChangePolicyWebhook {
47
+ // when the fsGroup field is set, also set the fsGroupChangePolicy to OnRootMismatch
48
+ if pod .Spec .SecurityContext != nil && pod .Spec .SecurityContext .FSGroup != nil {
49
+ p := v1 .FSGroupChangeOnRootMismatch
50
+ pod .Spec .SecurityContext .FSGroupChangePolicy = & p
51
+ log .V (1 ).Info ("Mutating Pod securityContext" , "pod" , pod )
52
+ }
47
53
}
48
54
49
55
//
0 commit comments