Skip to content

Commit eb8552e

Browse files
authored
Switch from mutating sts to pods (#583)
* Switch from mutating sts to pods * Logging * Logging
1 parent ffbc3ba commit eb8552e

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

controllers/postgres_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ func (r *PostgresReconciler) updatePatroniReplicationConfigOnAllPods(log logr.Lo
11531153
log.V(debugLogLevel).Info("no spilo pods found at all, requeueing")
11541154
return errors.New("no spilo pods found at all")
11551155
} else if len(pods.Items) < int(instance.Spec.NumberOfInstances) {
1156-
log.V(debugLogLevel).Info("expected %d pods, but only found %d (might be ok if it is still creating)", instance.Spec.NumberOfInstances, len(pods.Items))
1156+
log.V(debugLogLevel).Info("unexpected number of pods (might be ok if it is still creating)")
11571157
}
11581158

11591159
// iterate all spilo pods

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func main() {
499499

500500
if enableFsGroupChangePolicyWebhook {
501501
svcClusterMgr.GetWebhookServer().Register(
502-
"/mutate-apps-v1-statefulset",
502+
"/mutate-v1-pod",
503503
&webhook.Admission{
504504
Handler: &webhooks.FsGroupChangePolicySetter{
505505
SvcClient: svcClusterMgr.GetClient(),

pkg/webhooks/fsGroupChangePolicySetter.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77

88
"github.com/go-logr/logr"
9-
appsv1 "k8s.io/api/apps/v1"
109
v1 "k8s.io/api/core/v1"
1110
"sigs.k8s.io/controller-runtime/pkg/client"
1211

@@ -26,21 +25,21 @@ func (a *FsGroupChangePolicySetter) Handle(ctx context.Context, req admission.Re
2625
log := a.Log.WithValues("name", req.Name, "ns", req.Namespace)
2726
log.V(1).Info("handling admission request")
2827

29-
sts := &appsv1.StatefulSet{}
30-
err := a.Decoder.Decode(req, sts)
28+
pod := &v1.Pod{}
29+
err := a.Decoder.Decode(req, pod)
3130
if err != nil {
3231
log.Error(err, "failed to decode request")
3332
return admission.Errored(http.StatusBadRequest, err)
3433
}
3534

3635
// when the fsGroup field is set, also set the fsGroupChangePolicy to OnRootMismatch
37-
if sts.Spec.Template.Spec.SecurityContext != nil && sts.Spec.Template.Spec.SecurityContext.FSGroup != nil {
36+
if pod.Spec.SecurityContext != nil && pod.Spec.SecurityContext.FSGroup != nil {
3837
p := v1.FSGroupChangeOnRootMismatch
39-
sts.Spec.Template.Spec.SecurityContext.FSGroupChangePolicy = &p
40-
log.V(1).Info("Mutating StatefulSet", "sts", sts)
38+
pod.Spec.SecurityContext.FSGroupChangePolicy = &p
39+
log.V(1).Info("Mutating Pod", "pod", pod)
4140
}
4241

43-
marshaledSts, err := json.Marshal(sts)
42+
marshaledSts, err := json.Marshal(pod)
4443
if err != nil {
4544
log.Error(err, "failed to marshal response")
4645
return admission.Errored(http.StatusInternalServerError, err)

0 commit comments

Comments
 (0)