Skip to content

Commit 817cf8c

Browse files
authored
K8SPG-876: Log commands before execing them in containers (#1341)
1 parent e0ac59d commit 817cf8c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/controller/runtime/pod_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"k8s.io/client-go/tools/remotecommand"
1616
"k8s.io/client-go/util/flowcontrol"
1717
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
18+
logf "sigs.k8s.io/controller-runtime/pkg/log"
1819
)
1920

2021
// podExecutor runs command on container in pod in namespace. Non-nil streams
@@ -62,6 +63,8 @@ func NewPodExecutor(config *rest.Config) (podExecutor, error) {
6263

6364
exec, err := remotecommand.NewSPDYExecutor(configCopy, "POST", request.URL())
6465

66+
log := logf.FromContext(ctx)
67+
log.V(1).Info("Running command in pod", "pod", pod, "container", container, "command", command)
6568
if err == nil {
6669
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
6770
Stdin: stdin,

percona/clientcmd/clientcmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/client-go/tools/remotecommand"
1414
"k8s.io/client-go/util/flowcontrol"
1515
"k8s.io/client-go/util/retry"
16+
logf "sigs.k8s.io/controller-runtime/pkg/log"
1617
)
1718

1819
type Client struct {
@@ -73,6 +74,9 @@ func (c *Client) Exec(ctx context.Context, pod *corev1.Pod, containerName string
7374
return errors.Wrap(err, "failed to create executor")
7475
}
7576

77+
log := logf.FromContext(ctx)
78+
log.V(1).Info("Running command in pod", "pod", pod.Name, "container", containerName, "command", command)
79+
7680
retryErr := retry.OnError(retry.DefaultRetry, func(err error) bool {
7781
return true // Retry on all errors
7882
}, func() error {

0 commit comments

Comments
 (0)