Skip to content

Commit c7a885d

Browse files
committed
Stop using deprecated Executor.Stream in k8s.io/client-go/tools/remotecommand package. Start using StreamWithContext.
1 parent 7b2408c commit c7a885d

18 files changed

+69
-68
lines changed

internal/controller/postgrescluster/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Reconciler struct {
6565
IsOpenShift bool
6666
Owner client.FieldOwner
6767
PodExec func(
68-
namespace, pod, container string,
68+
ctx context.Context, namespace, pod, container string,
6969
stdin io.Reader, stdout, stderr io.Writer, command ...string,
7070
) error
7171
Recorder record.EventRecorder

internal/controller/postgrescluster/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func (r *Reconciler) rolloutInstance(
792792

793793
pod := instance.Pods[0]
794794
exec := func(_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error {
795-
return r.PodExec(pod.Namespace, pod.Name, naming.ContainerDatabase, stdin, stdout, stderr, command...)
795+
return r.PodExec(ctx, pod.Namespace, pod.Name, naming.ContainerDatabase, stdin, stdout, stderr, command...)
796796
}
797797

798798
primary, known := instance.IsPrimary()

internal/controller/postgrescluster/instance_rollout_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
7575

7676
execCalls := 0
7777
reconciler.PodExec = func(
78-
namespace, pod, container string, stdin io.Reader, _, _ io.Writer, command ...string,
78+
ctx context.Context, namespace, pod, container string, stdin io.Reader, _, _ io.Writer, command ...string,
7979
) error {
8080
execCalls++
8181

@@ -134,7 +134,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
134134
reconciler := &Reconciler{}
135135
reconciler.Tracer = otel.Tracer(t.Name())
136136
reconciler.PodExec = func(
137-
namespace, pod, container string, _ io.Reader, stdout, _ io.Writer, command ...string,
137+
ctx context.Context, namespace, pod, container string, _ io.Reader, stdout, _ io.Writer, command ...string,
138138
) error {
139139
execCalls++
140140

@@ -162,7 +162,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
162162
reconciler := &Reconciler{}
163163
reconciler.Tracer = otel.Tracer(t.Name())
164164
reconciler.PodExec = func(
165-
_, _, _ string, _ io.Reader, _, _ io.Writer, _ ...string,
165+
ctx context.Context, _, _, _ string, _ io.Reader, _, _ io.Writer, _ ...string,
166166
) error {
167167
// Nothing useful in stdout.
168168
return nil

internal/controller/postgrescluster/patroni.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (r *Reconciler) handlePatroniRestarts(
103103
ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
104104
) error {
105105
pod := primaryNeedsRestart.Pods[0]
106-
return r.PodExec(pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
106+
return r.PodExec(ctx, pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
107107
})
108108

109109
return errors.WithStack(exec.RestartPendingMembers(ctx, "master", naming.PatroniScope(cluster)))
@@ -128,7 +128,7 @@ func (r *Reconciler) handlePatroniRestarts(
128128
ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
129129
) error {
130130
pod := replicaNeedsRestart.Pods[0]
131-
return r.PodExec(pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
131+
return r.PodExec(ctx, pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
132132
})
133133

134134
return errors.WithStack(exec.RestartPendingMembers(ctx, "replica", naming.PatroniScope(cluster)))
@@ -212,8 +212,8 @@ func (r *Reconciler) reconcilePatroniDynamicConfiguration(
212212
// NOTE(cbandy): Despite the guards above, calling PodExec may still fail
213213
// due to a missing or stopped container.
214214

215-
exec := func(_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error {
216-
return r.PodExec(pod.Namespace, pod.Name, naming.ContainerDatabase, stdin, stdout, stderr, command...)
215+
exec := func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error {
216+
return r.PodExec(ctx, pod.Namespace, pod.Name, naming.ContainerDatabase, stdin, stdout, stderr, command...)
217217
}
218218

219219
var configuration map[string]any
@@ -535,7 +535,7 @@ func (r *Reconciler) reconcilePatroniSwitchover(ctx context.Context,
535535
}
536536
exec := func(_ context.Context, stdin io.Reader, stdout, stderr io.Writer,
537537
command ...string) error {
538-
return r.PodExec(runningPod.Namespace, runningPod.Name, naming.ContainerDatabase, stdin,
538+
return r.PodExec(ctx, runningPod.Namespace, runningPod.Name, naming.ContainerDatabase, stdin,
539539
stdout, stderr, command...)
540540
}
541541

internal/controller/postgrescluster/patroni_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func TestReconcilePatroniSwitchover(t *testing.T) {
544544
var timelineCallNoLeader, timelineCall bool
545545
r := Reconciler{
546546
Client: client,
547-
PodExec: func(namespace, pod, container string,
547+
PodExec: func(ctx context.Context, namespace, pod, container string,
548548
stdin io.Reader, stdout, stderr io.Writer, command ...string) error {
549549
called = true
550550
switch {

internal/controller/postgrescluster/pgadmin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ func (r *Reconciler) reconcilePGAdminUsers(
454454
ctx = logging.NewContext(ctx, logging.FromContext(ctx).WithValues("pod", pod.Name))
455455

456456
podExecutor = func(
457-
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
457+
ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
458458
) error {
459-
return r.PodExec(pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
459+
return r.PodExec(ctx, pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
460460
}
461461
}
462462
if podExecutor == nil {

internal/controller/postgrescluster/pgadmin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ func TestReconcilePGAdminUsers(t *testing.T) {
785785

786786
calls := 0
787787
r.PodExec = func(
788-
namespace, pod, container string,
788+
ctx context.Context, namespace, pod, container string,
789789
stdin io.Reader, stdout, stderr io.Writer, command ...string,
790790
) error {
791791
calls++

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ func (r *Reconciler) reconcileStanzaCreate(ctx context.Context,
26342634
// create a pgBackRest executor and attempt stanza creation
26352635
exec := func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer,
26362636
command ...string) error {
2637-
return r.PodExec(postgresCluster.GetNamespace(), writableInstanceName,
2637+
return r.PodExec(ctx, postgresCluster.GetNamespace(), writableInstanceName,
26382638
naming.ContainerDatabase, stdin, stdout, stderr, command...)
26392639
}
26402640

internal/controller/postgrescluster/pgbackrest_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,13 @@ func TestReconcileStanzaCreate(t *testing.T) {
700700
},
701701
}})
702702

703-
stanzaCreateFail := func(namespace, pod, container string, stdin io.Reader, stdout,
704-
stderr io.Writer, command ...string) error {
703+
stanzaCreateFail := func(ctx context.Context, namespace, pod, container string, stdin io.Reader,
704+
stdout, stderr io.Writer, command ...string) error {
705705
return errors.New("fake stanza create failed")
706706
}
707707

708-
stanzaCreateSuccess := func(namespace, pod, container string, stdin io.Reader, stdout,
709-
stderr io.Writer, command ...string) error {
708+
stanzaCreateSuccess := func(ctx context.Context, namespace, pod, container string, stdin io.Reader,
709+
stdout, stderr io.Writer, command ...string) error {
710710
return nil
711711
}
712712

internal/controller/postgrescluster/pgbouncer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ func (r *Reconciler) reconcilePGBouncerInPostgreSQL(
181181

182182
if err == nil {
183183
ctx := logging.NewContext(ctx, logging.FromContext(ctx).WithValues("revision", revision))
184-
err = action(ctx, func(_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error {
185-
return r.PodExec(pod.Namespace, pod.Name, naming.ContainerDatabase, stdin, stdout, stderr, command...)
184+
err = action(ctx, func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error {
185+
return r.PodExec(ctx, pod.Namespace, pod.Name, naming.ContainerDatabase, stdin, stdout, stderr, command...)
186186
})
187187
}
188188
if err == nil {

0 commit comments

Comments
 (0)